• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

How to pause listener on MDB ?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Techies,

I am using MDB for message processing, inside which i have some condition, if condition is false then i don't want to read the message, i.e. i don't want to lose the message.

Can any one tell me how to prevent MDB to read the message.

Regards,

Aalok
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is pretty straight forward , inside the onMessage Method , check for the condition whatever you want to perform first

 
Aalok Singh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ravi Kiran,

I per my knowledge and J2EE Specs., onMessage(Message msg) is only for processing the message, not reading the message.

message is read by Container and then given to onMessage() method for processing.

and my problem is that... i don't want to read the message if condition is false i.e. that message must not be removed (read out) from JMS Queue.


Regards,
Aalok
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I currently dont remember exactly how to do this , but as per my knowledge you need to google on
"Configuring MDB Message Selectors"

and for this to work you need to set Header properties to your Message also .

Google it you will find it .
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aalok Singh wrote:Can any one tell me how to prevent MDB to read the message.



Aalok

My understanding is that you cannot stop an instance of a MDB from receiving a message once a queue/topic selects that instance to receive the message.

If you don't want to process the message at the time it is received by an instance of the MDB then you can set a property within the message header that indicates the message processing should be delayed and place the message back into the queue/topic or into another queue/topic so that it can be processed later. Below is an example of setting this message property on JBoss. Note that the property name "JMS_JBOSS_SCHEDULED_DELIVERY" is specific to JBoss, thus it will be different on another server.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran Va wrote:I currently dont remember exactly how to do this , but as per my knowledge you need to google on
"Configuring MDB Message Selectors"

and for this to work you need to set Header properties to your Message also .

Google it you will find it .



before sending a message to a queue or topic add a property to it which would uniquely identify it like

.
.
ObjectMessage obj = session.createObjectMessage();
obj.setStringProperty("type","XYZ");
.
.

and when configuring the listener or the mdb to listen to a queue and pickup only messages which have type "XYZ"

String messageSelector = "type = 'XYZ'"
TopicSubscriber sub = session.createSubscriber(topicName,messageSelector,true);

there are numerous operators other than '=', you can even do a wildcard match for the messageSelector like "'type LIKE 'XYZ%'"
this is with reference to ActiveMQ. the creation of subscriber might vary depending upon the third party provider.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic