我正在玩 XA 交易。目前,我正在尝试将它们与 JMS 集成。但相反,我得到了一些关于信号量采集失败的神秘异常。
这是我的MDB:
@javax.ejb.MessageDriven(messageListenerInterface = MessageListener.class)
@org.jboss.ejb3.annotation.AspectDomain("Tibco/Simple.Request.Queue")
@org.jboss.ejb3.annotation.Pool(
value = PoolDefaults.POOL_IMPLEMENTATION_STRICTMAX,
maxSize = 1,
timeout = Long.MAX_VALUE
)
public class FeedReconciliationMessageBean implements MessageListener {
@EJB
private SimpleController simpleController;
@Override
public void onMessage(TrsFeedReconciliationRequestPayload message) {
simpleController.reconciliate(message.getReconId());
}
}
激活配置:
<domain name="Tibco/Simple.Request.Queue" extends="Message Driven Bean" inheritBindings="true">
<annotation expr="!class(@org.jboss.ejb3.annotation.DefaultActivationSpecs)">
@org.jboss.ejb3.annotation.DefaultActivationSpecs
(value={
@javax.ejb.ActivationConfigProperty(propertyName="destination",
propertyValue="/com/example/Simple.Request.Queue:queue"),
@javax.ejb.ActivationConfigProperty(propertyName="user",
propertyValue=""),
@javax.ejb.ActivationConfigProperty(propertyName="password",
propertyValue=""),
@javax.ejb.ActivationConfigProperty(propertyName="providerAdapterJNDI",
propertyValue="java:/TIBCOJMSProvider"),
@javax.ejb.ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue"),
@javax.ejb.ActivationConfigProperty(propertyName="useDLQ",
propertyValue="false"),
@javax.ejb.ActivationConfigProperty(propertyName="transactionTimeout",
propertyValue="43200000") })
</annotation>
</domain>
队列配置:
show queue Simple.Request.Queue
Queue: Simple.Request.Queue
Type: static
Properties: *prefetch=5,*store=$sys.nonfailsafe
JNDI Names: "/com/example/Simple.Request.Queue:queue"
Bridges: <none>
Receivers: 1
Pending Msgs: 0
Delivered Msgs: 0
Pending Msgs Size: 0.0 Kb
因此,每次我向队列发送消息时,都会收到如下异常:
2014-04-03 09:44:10,734 [WorkManager(2)-64] ERROR [org.jboss.resource.adapter.jms.inflow.JmsServerSession] Unexpected error delivering message MapMessage={ Header={ JMSMessageID={ID:EMS-SERVER.3585339006611AE:4} JMSDestination={Queue[Simple.Request.Queue]} JMSReplyTo={null} JMSDeliveryMode={PERSISTENT} JMSRedelivered={true} JMSCorrelationID={null} JMSType={null} JMSTimestamp={Thu Apr 03 09:44:10 MSD 2014} JMSExpiration={0} JMSPriority={4} } Properties={ JMSXDeliveryCount={Integer:7} } Fields={ userSessionId={null} payloadType={String:SimplePayload} processInstanceId={null} payloadFullType={String:com.example.SimplePayload} payload={String:<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SimplePayload>
<test>1</test>
</SimplePayload>
} } }
javax.ejb.EJBException: Failed to acquire the pool semaphore, strictTimeout=-1
at org.jboss.ejb3.pool.StrictMaxPool.get(StrictMaxPool.java:127)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
有趣的是,MDB 确实被调用了。我在onMessage
方法中设置了一个断点,当发送消息时,我确实在onMessage
方法中停止。但与此同时,我在 server.log 中得到了大约 7 个与上述类似的异常。
另一个有趣的事情是它onMessage
被调用了两次,尽管在它的执行过程中没有发生异常。
我试图用谷歌搜索这个问题。我发现的最常见的解决方案是增加 ejb 池大小。解释是,如果您的 JMS预取大小小于 EJB池大小,则可能会出现池中没有足够的 EJB 来处理所有消息。因此,超时后会引发异常。但正如你所看到的,这是完全不同的事情。为什么异常中的strictTimeout值为-1?我认为这与 XA 交易有关。