Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pause listener on MDB ?  RSS feed

 
Aalok Singh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 .
 
Ran Pleasant
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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.

 
Arunsanjay Jayarathanam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!