This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JMS Consumer and Listener

 
Ranch Hand
Posts: 431
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?
 
Marshal
Posts: 3149
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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: 431
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
Marshal
Posts: 3149
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • 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: 431
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?
 
Marshal
Posts: 25674
69
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
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
    Bookmark Topic Watch Topic
  • New Topic