Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eventBus publisher should have a publish method #1468

Open
seanjburns opened this issue Jun 14, 2016 · 8 comments
Open

eventBus publisher should have a publish method #1468

seanjburns opened this issue Jun 14, 2016 · 8 comments

Comments

@seanjburns
Copy link

It was slightly confusing when i used the eventBus to create publisher.

I had code that looked like this
vertx.eventBus().publish("endpoint","Hello World");
and wanted to use a publisher instead
vertx.eventBus().publisher("endpoint")

but the publisher did not have the "publish" method (the write method does the correct function though).

@EmadAlblueshi
Copy link
Contributor

@seanjburns Hi, I hope I got what you need

DeliveryOptions options = new DeliveryOptions();
options.addHeader("action", "findAll");

MessageProducer<JsonObject> publisherMessage = eventBus.<JsonObject>publisher("io.vertx.news", options);
MessageProducer<JsonObject> senderMessage = eventBus.<JsonObject>sender("io.vertx.news", options);

JsonObject message = new JsonObject();

publisherMessage.<JsonObject>send(message, reply -> {
// publish
});

senderMessage.<JsonObject>send(message, reply -> {
// send
});

@seanjburns
Copy link
Author

^^ You see, I'm not the only one easily "fooled" @EmadAlblueshi just pasted a "solution" thats does not "publish" as expected.

@EmadAlblueshi this function
publisherMessage.<JsonObject>send(message, reply -> {
// publish <==== THIS DOES NOT PUBLISH
});`

Does not actually "publish" to all consumers, it "sends" to a single consumer. You actually have to use the write method like this

publisherMessage.<JsonObject>write(message, reply -> {
// publish
});`

FYI this is just a usability issue that is all.

@EmadAlblueshi
Copy link
Contributor

@seanjburns you are absolutely correct. I have just discovered that "write" method will do the publishing instead of sending. From usability perspective I think it should be "publish" to vanish such a confusion

+1

@seanjburns
Copy link
Author

@vietj
Copy link
Member

vietj commented Jun 30, 2016

I think having a send method was a design mistake, adding a publish method would be even more confusing and people can still do eventBus.publish and eventBus.send

@seanjburns
Copy link
Author

Maybe for vertx 4.0 (3.4?), We can have 2 interfaces that extend MessageProducer. Then the publisher and sender methods can return the respective interfaces.

@vietj
Copy link
Member

vietj commented Jun 30, 2016

@seanjburns I was rather thinking deprecating the send method and find a new name that works for both unless we want to keep only the write

@barbarosalp
Copy link

barbarosalp commented Feb 19, 2019

If you don't want to provide the address all the time, just create a publisher with an address:

  • to publish: use its write method if you want to publish a message to all consumers.
  • to send: use its send method. (If there are multiple consumers the message will be sent round-robin)

I think publish would be a better name rather than the write?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants