在我的Weblogic服务器上,我有MQ作为外部JMS服务器。问题是,我需要回滚消息并重试,直到达到回退阈值。然后,我需要将消息移动到backout队列。
MessageDrivenContext.setRollbackOnly()方法很好地解决了这一问题。然而,问题出在回退队列上的消息-它是未提交的。
此外,一旦新的消息出现在主队列上,这些消息就会从回退队列中取出并重新处理。
这表明我的方法有明显的错误。然而,我不能改变这样一个事实,即我必须使用相同的消息重试onMessage()几次,并在达到回退阈值时将其发送到回退队列。
@MessageDriven( name="MQListener", mappedName = "jms.mq.SOME.QUEUE.NAME",
activationConfig =
{
@ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms.mq.SOME.QUEUE.NAME"),
@ActivationConfigProperty(propertyName = "connectionFactoryJndiName", propertyValue = "jms.mq.MQ"),
@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true")
})
public class MQListener implements MessageListener {
@Resource
private MessageDrivenContext context;
@Override
public void onMessage(Message message) {
String messageContent="";
try {
messageId = message.getJMSMessageID();
if (message != null) {
messageContent = ((TextMessage)message).getText();
if(!doSomething(messageContent)){
// doSomething fails, I need to rollback the message and try again:
context.setRollbackOnly();
}
}
} catch (Exception e) {
throw new RuntimeException();
}
}
private boolean doSomething(String messageContent){
// ...
}
}发布于 2013-01-30 19:44:03
我是EJB的一名老手。但是从我在你的代码片段中看到的,我认为你错过了MessageDrivenContext的初始化。我想你将不得不这样做
context = getMessageDrivenContext();
context.setRollbackOnly();或
getMessageDrivenContext().setRollbackOnly();https://stackoverflow.com/questions/14582494
复制相似问题