Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JMS Consumer and Listener  RSS feed

 
Ranch Hand
Posts: 315
2
Java
  • 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: 2020
273
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: 315
2
Java
  • 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: 2020
273
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: 315
2
Java
  • 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: 23640
48
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: 23568
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!