Skip to content

Incorrect javadoc for MessageProducer#send #2618

@remagister

Description

@remagister

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions