I'm not sure whether this behavior is correct or not, but when you try to create a message producer via EventBus.publisher method, it creates instance of MessageProducerImpl class with private send field equal to false -- which is designed to distinguish senders and publishers I guess; but actual implementation of methods send and write of the producer class differs:
Send method:
public MessageProducer<T> send(T message) {
doSend(message, null);
return this;
}
Write method:
public synchronized MessageProducer<T> write(T data) {
if (send) {
doSend(data, null);
} else {
bus.publish(address, data, options);
}
return this;
}
Which subsequently leads to strange behavior: send method actually sends messages, but write method publishes them, even if it was a publisher created.
In JavaDoc for the MessageProducer.send method denoted that it is
Synonym for write(Object).
So, if it is a synonym, why the behavior differs?
For me using MessageProducer.write method works fine now, but I had some time figuring out why publishing messages did not work (not all message handlers actually received data).
Please, consider adding analogous if (send) checks to the method send also, if this behavior is not correct. And should really write method be synchronized, while send is not?
I'm not sure whether this behavior is correct or not, but when you try to create a message producer via
EventBus.publishermethod, it creates instance ofMessageProducerImplclass with privatesendfield equal tofalse-- which is designed to distinguish senders and publishers I guess; but actual implementation of methodssendandwriteof the producer class differs:Send method:
Write method:
Which subsequently leads to strange behavior:
sendmethod actually sends messages, butwritemethod publishes them, even if it was a publisher created.In JavaDoc for the
MessageProducer.sendmethod denoted that it isSo, if it is a synonym, why the behavior differs?
For me using
MessageProducer.writemethod works fine now, but I had some time figuring out why publishing messages did not work (not all message handlers actually received data).Please, consider adding analogous
if (send)checks to the methodsendalso, if this behavior is not correct. And should reallywritemethod be synchronized, whilesendis not?