Vertx Unregister from consumer in the same consumer handler

34 views
Skip to first unread message

Jean Halbret

unread,
Sep 10, 2020, 1:08:58 PM9/10/20
to vert.x
Hello,
Please advice if it is okay to do the following, Where i am unregistering the consumer within it's handler.

public class Order{
     public void isCancel(){
         EventBus eb = Vertx.currentContext().owner().eventBus();
         MessageConsumer<String> consumer = eb.consumer("address");
         consumer.handler(message -> {
                   if(true){
                       doSomething();
                   }else {
                       consumer.unregister();
                   }
               });
           }  //End of method
}//End of class

Another instance of class  Order will be created again and the method isCancel will be called again for every instance of Order ...


Thanks in advance.


Julien Viet

unread,
Sep 10, 2020, 2:50:28 PM9/10/20
to vert.x
Hi,

unregistration works when receiving a message.

I'm not sure to understand why you are referring to instances of Order here.

Julien

--
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.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/4486268d-928f-4869-b119-082c8212726fn%40googlegroups.com.

Jean Halbret

unread,
Sep 10, 2020, 3:21:40 PM9/10/20
to ve...@googlegroups.com
Hi Julien, 

Yes, it's fine if unregistration happens on receiving the message.

I am talking about order instances since for every order instance a consumer is getting created. 

Assuming o1, o2, o3 are instances... 

Suppose, o1 instance is created first. Then I do a publish, then o1 consumer handler executes.

Now o2 instance is created. Then I do a publish. Then consumer handler of both o1 and o2 are getting  executed (if unregister is not called within the consumer handler).. which I want to avoid.


We are planning to redesign this but for now bcz of time constrain want to unregister in consumer handler. 

Thanks


You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/CegiBiT2qq4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CA%2BH-X4-UQsqZcQKdzjxVpaQdG8dRUGzOSdbXovaBKSUqBVZ%2BMA%40mail.gmail.com.

Jean Halbret

unread,
Sep 10, 2020, 9:41:44 PM9/10/20
to ve...@googlegroups.com
 Hi 

Once unregistration happens, another consumer can be created on the same address right? 

-J

Jean Halbret

unread,
Sep 12, 2020, 12:32:22 AM9/12/20
to ve...@googlegroups.com
Can someone plz help me on this...


Thanks in advance.
Reply all
Reply to author
Forward
0 new messages