is it possible to publish only to a single verticle instance in a clustered eventbus?

443 views
Skip to first unread message

Steffen Stundzig

unread,
Nov 10, 2017, 8:39:00 AM11/10/17
to vert.x

Hi folks,

vertx.io is really a great piece of software. I love it.

I'm using vertx in a clustered environment on different machines, currently only as cluster without HA. 
On each machine, here Node1 and Node2, the same set of verticles is deployed.

Now i would like to publish a message on the eventbus, that should be consumed only by one instance of a verticle type across the whole cluster.

Node1         Node2
--------          --------
|   V1 |         | V1   |
|   V2 |         | V2   |
--------          --------

E.g. i publish a message, that should only be consumed by one instance of Verticle V1 and one instance of Verticle V2 and not both instances of V1 and V2. Is this possible? 

Or should i use another setup with high availability here and deployment of only one instance of V1 and V2 in the cluster?

Thanks for any answer.

Regards
   Steffen...

Paulo Henrique Ferreira de Lima

unread,
Nov 10, 2017, 11:44:01 AM11/10/17
to vert.x
Hi Steffen,

You mean send one unique message to one specific event bus address, right?

The vert.x support point to point message, so you can use the send method instead publish.

Basically when you say to event bus publish one message, you means delivering the message to all handlers for this address. Using the send method you will sent one message for one of these handlers of your cluster, following one round-robin algorithm. 

So try use:

vertx.eventBus().send("address", payload)

Steffen Stundzig

unread,
Nov 10, 2017, 12:05:41 PM11/10/17
to vert.x
Hi,

thanks for your answer. I know the difference between send and publish.

I would like to send one message, which should be received by an instance of verticle V1 and also V2, but only on one Node. So e.g. Message1 should be received by (Node1.V1 and Node2.V2) or (Node2.V1 and Node2.V2) but never on Node.V1 and Node2.V1.  

My first question was not clear enough.

Regards
   Steffen...

Phil Lehmann

unread,
Nov 10, 2017, 6:41:14 PM11/10/17
to vert.x
You probably need a central node / verticle register, e.g. another verticle which offers two EventBus services: one, where verticles can register themselves (they need to provide the node they are running on as well, so <nodeId> and <verticleId>). The second one can then be used to dispatch a message to those registered verticles. For that to work, the registered verticles need to consume a distinct EventBus address, e.g. "/verticle/<nodeId>/<verticleId>".

With the registry data, you can then dispatch incoming messages from your register verticle to specific verticles.

Steffen Stundzig

unread,
Nov 10, 2017, 11:26:36 PM11/10/17
to vert.x
Hi Phil,

thanks for this approach. 

I like the idea with the dispatcher. I've many verticles, which could be run parallel. But for my special case from my initial question, i'll replace the publish()  with a send() to a special consumer for this special message, which itself calls then send(V1.adress) and send(V2.adress).  

If i found more then 3 of this *special* cases, i'll start with the central node/registry approach for all verticles.

Regards
   Steffen...

Julien Viet

unread,
Nov 13, 2017, 1:35:58 PM11/13/17
to vert.x
if you register V1 and V2 on different addresses and "send" the message to these address, don't you get the behavior your describe ?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/95ba4271-dad7-4b42-8dc1-ea6c1d305315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Phil Lehmann

unread,
Nov 14, 2017, 12:32:55 AM11/14/17
to vert.x
If you know can know the addresses of V1 and V2 (e.g. a contained node id), that's certainly easier to do.

Steffen Stundzig

unread,
Nov 14, 2017, 2:58:51 AM11/14/17
to vert.x
Hi Phil,

thanks for your answer.

I've created a 'MessagePublisherVerticle' which receives the initial message and sends special message to each V1 and V2.

Regards
   Steffen...
Reply all
Reply to author
Forward
0 new messages