【发布时间】:2015-12-08 23:43:34
【问题描述】:
当发生错误时,我需要向队列返回消息。
我正在使用 Weblogic 11G (EJB3.0)、Java 1.6、javaee-api 6.0 上的消息驱动 Bean,队列位于 Oracle 数据库 (AQJMS) 上
我不想将消息发送到错误队列。
public void onMessage(Message message) {
try {
this.processMenssage(message);
} catch (ServiceInternalException e) {
// I need return the message to the queue because something wrong (anything) happend
}
}
我知道消息会一次又一次地恢复,直到我解决问题为止。
MDB 配置了注解
@MessageDriven(
name = "MyBeanMDB",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "connectionFactoryJndiName",
propertyValue = "AqJms3FSCF"), // External JNDI Name
@ActivationConfigProperty(propertyName = "destinationJndiName",
propertyValue = "myque/REQ_JMSQ") // Ext. JNDI Name
}
)
public class MyBeanMDB implements MessageListener{....
因为我的驱动程序数据源是 oracle.jdbc.xa.client.OracleXADataSource 我有一个文件 weblogic-ejb-jar.xml
<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar">
<weblogic-enterprise-bean>
<ejb-name>MyBeanMDB</ejb-name>
<message-driven-descriptor>
<pool>
<max-beans-in-free-pool>1</max-beans-in-free-pool>
<initial-beans-in-free-pool>1</initial-beans-in-free-pool>
</pool>
</message-driven-descriptor>
</weblogic-enterprise-bean>
我尝试使用 setRollbackOnly()
添加
@TransactionManagement(value=TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
和
@Override
public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
this.myctx = ctx;
}
内部异常
public void onMessage(Message message) {
try {
this.processMenssage(message);
} catch (ServiceInternalException e) {
this.myctx.setRollbackOnly(); // the message is not redelivered
}
}
RollbackOnly 被调用,日志显示:
####<Sep 13, 2015 11:40:33 AM ART> <Info> <EJB> <el01cl03> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <39d906d31eb822f1:-27a94574:14fc3fbcefe:-8000-0000000000000b8a> <1442155233307> <BEA-010213> <Message-Driven EJB: MyBeanMDB's transaction was rolled back. The transaction details are: Name=NewJMSMessagePoller.MyBeanMDB,Xid=BEA1-2BC2680CDDBA895EF953(294629023),Status=Rolled back. [Reason=weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction],numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=0,seconds left=60,XAServerResourceInfo[aqjmsuserDS_e2eSOADomain]=(ServerResourceInfo[aqjmsuserDS_e2eSOADomain]=(state=rolledback,assigned=AdminServer),xar=aqjmsuserDS,re-Registered = false),SCInfo[e2eSOADomain+AdminServer]=(state=rolledback),properties=({weblogic.transaction.name=NewJMSMessagePoller.MyBeanMDB}),local properties=({weblogic.jdbc.jta.aqjmsuserDS=[ No XAConnection is attached to this TxInfo ]}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=AdminServer+10.10.10.150:7001+e2eSOADomain+t3+, XAResources={eis/tibjms/Queue, NIICommonDS-rac0_e2eSOADomain, eis/activemq/Queue, 10gDataSource_e2eSOADomain, eis/fioranomq/Topic, eis/jbossmq/Queue, eis/Apps/Apps, eis/aqjms/Topic, eis/webspheremq/Queue, eis/AQ/aqSample, eis/tibjms/Topic, eis/aqjms/Queue, eis/aqjms/colasjmsuser3, ITM_e2eSOADomain, eis/sunmq/Queue, WSATGatewayRM_AdminServer_e2eSOADomain, NIICommonDS_e2eSOADomain, eis/jms/ReprocessJMSQueue, eis/tibjmsDirect/Queue, eis/wls/Queue, aqjmsuserDS_e2eSOADomain, eis/tibjmsDirect/Topic, eis/wls/Topic, eis/pramati/Queue, NIICommonDS-rac1_e2eSOADomain, eis/jms/ReprocessJMS11gQueueCF},NonXAResources={})],CoordinatorURL=AdminServer+10.10.10.150:7001+e2eSOADomain+t3+).>
但之后队列中的状态(AQJMS)是3(已处理)
也许问题是:
aqjmsuserDS=[ No XAConnection is attached to this TxInfo ]
【问题讨论】:
-
如果您在 catch 块中抛出 RuntimeException,则应该重新传递消息。
-
我尝试了 RuntimeException,但消息没有再次恢复。
-
你能提供 processMenssage(message) 代码吗?我很想知道该方法可能会抛出哪些异常?
-
weblogic 日志中的任何内容?事务可能有问题,所以回滚永远不会发生。
-
在 weblogic 日志中我可以看到回滚发生了,但是 MDB 没有再次收到消息:(
标签: java jms message-queue message-driven-bean