dead letter queue on JBoss 6.0.0
soma13 Jan 30, 2011 12:26 PMDear All,
I am new in JBoss and I would like to get some help about queue handler onJBoss 6.
At my workplace I use weblogic app server, and it has a useful jms feature.Its name is redelivery. This function has three parameters:
- Redelivery Delay Override: The number of milliseconds (between 0 and a positive 64-bit integer) before rolled back and recovered messages are redelivered.
- Redelivery Limit: The number of redelivery tries (between 0 and a positive 32-bit integer) a message can have before it is placed in the error destination. If no JMS template is configured, then -1 means that there is no override.
- Error Destination: Destination for messages that have reached their redelivery limit, or for expired messages on the destination where the expiration policy is Redirect.
I use redelivery function on Weblogic for prevent data lost and the theme specified error queue is comfortable for IT operators. The redelivery on weblogic works when an error occurs in the MDB (message driven bean) during run business logic. If there is an error then onMessage method of MDB throw aRuntimeException and the app server containers roll back data to the original JMS queue. After a couple of time the queue consume data and the MDB try to run the business logic aging and again. The MDB makes some same cycle (itdepend on redelivery limit) and the message is going to delivery to the error destination jms queue.
So, I want to make this functionality on JBoss 6.0.0 application server. I have read documents and a see there is a dead letter on JBoss and it is same to redelivery function on weblogic server. I have written some example MDBs but the redelivery function is not working very well.
I show you my JBoss configuration files and my code of message driven bean. Please point at my mistake(s) in my code.
Thank you very much.
Here is my queue config in <jboss_6.0.0_home>/server/default/deploy/hornetq/hornetq-jms.xml file:
<configuration ...>
...
<!-- the queue used by the example -->
<queue name="exampleQueue">
<entryname="/queue/exampleQueue"/>
</queue>
<!-- the dead letter queue where dead messages will be sent-->
<queue name="deadLetterQueue">
<entryname="/queue/deadLetterQueue"/>
</queue>
</configuration>
Code of my message driven bean:
@MessageDriven(name = "DLQExample",
activationConfig = { @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName= "destination",propertyValue="/queue/exampleQueue") })
//@Pool(value=PoolDefaults.POOL_IMPLEMENTATION_STRICTMAX, maxSize=1)
@TransactionManagement(value= TransactionManagementType.CONTAINER)
@TransactionAttribute(value= TransactionAttributeType.REQUIRED)
@ResourceAdapter("jms-ra.rar")
//@ResourceAdapter("hornetq-ra.rar")
public class DLQExampleimplements MessageListener
{
public void onMessage(Message message)
{
try
{
// I know theclient is sending a text message
TextMessagetextMessage = (TextMessage)message;
String text =textMessage.getText();
System.out.println("received message:\n " + text);
if (text.contains("+") )
{
System.out.println("throw a forced exception to test my dead letterqueue");
throw new Exception("my forced exception");
}
}
catch (Exception e)
{
throw newRuntimeException(e);
}
}
}
After I dropped my first simple text message to "exampleQueue" with HermesJMS I see on the console that my MDB received the message and run it well.
My second message contains a "+" character so my code is going to throw a forced exception. My message rolled back to the"exampleQueue" jms and some time ago (value of Redelivery Delay) my MDB received the message. And the process continues indefinitely and my text message could not go to my "deadLetterQueue".
Could you tell me what is the wrong in my code?
regards, zappee