Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMS Consumer and Listener  RSS feed

 
Ranch Hand
Posts: 221
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JMS, I understand that producer will produce the messages in a queue/topic.
And Consumer will consume the messages from queue/topic.
Then, what is the use of listener here? Why do we need  a listener when we already have a consumer?
 
Saloon Keeper
Posts: 1867
238
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The listener provides an asynchronous method for the consumer to receive messages instead of using the blocking MessageConsumer#receive method to receive a message.

After registering a MessageListener, the MessageListener#onMessage method will be called whenever a message is available from the queue.
 
Vaibhav Gargs
Ranch Hand
Posts: 221
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ron.

Can a MessageListener exist without a Consumer or vice-versa?
 
Ron McLeod
Saloon Keeper
Posts: 1867
238
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:Can a MessageListener exist without a Consumer or vice-versa?


Well .. you could create an instance of a class which implements the MessageListener interface, but if you don't bind it to a consumer it's no going to provide any value.
 
Vaibhav Gargs
Ranch Hand
Posts: 221
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ron for your inputs.

So, does it mean that a Listener can't exist without a consumer but a consumer can exist without a Listener?
 
Sheriff
Posts: 23503
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me Ron's answer means "Yes, you can create a Listener without a Consumer, but that would be pointless". Most of us here are not that interested in pointless code, but I know there are some who take an abstract view which doesn't concern itself with whether code is useful or not.
 
author
Sheriff
Posts: 23484
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hate to throw a monkey wrench into this discussion, but JMS has both topics and queues. Consumers are for queuing. Subscribers are for topics. And yes, it is possible to create a listener for a subscriber.  Hence, it is possible to create a listener without the need to have a consumer...

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!