我尝试使用bean管理事务在weblogic 10.0.1中的EJB2(legacy sucks ;-)无状态会话bean中接收JMS消息。从JMS队列文件夹定义看起来像Weblogic10中的JMS队列能够发送但不能接收的EJB2会话Bean
<uniform-distributed-queue name="ReqQueue">
<default-targeting-enabled>true</default-targeting-enabled>
<delivery-params-overrides>
<delivery-mode>Non-Persistent</delivery-mode>
</delivery-params-overrides>
<quota>QuotaCrc</quota>
<jndi-name>xxx.ReqQueue</jndi-name>
<load-balancing-policy>Round-Robin</load-balancing-policy>
</uniform-distributed-queue>
<uniform-distributed-queue name="RespQueue">
<default-targeting-enabled>true</default-targeting-enabled>
<delivery-params-overrides>
<delivery-mode>Non-Persistent</delivery-mode>
</delivery-params-overrides>
<quota>QuotaCrc</quota>
<jndi-name>xxx.RespQueue</jndi-name>
<load-balancing-policy>Round-Robin</load-balancing-policy>
</uniform-distributed-queue>
在bean的业务方法不启动事务,所以JMS操作不是事务性的。所执行代码是
InitialContext ictx = new InitialContext();
QueueConnectionFactory cf = (QueueConnectionFactory)
ictx.lookup("weblogic.jms.ConnectionFactory");
Queue responseQueue = (Queue) ictx.lookup("RespQueue");
conn = cf.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer receiver = session.createConsumer(responseQueue);
ObjectMessage response = (ObjectMessage) receiver.receive(30000);
的问题是,receiver.receive
立即返回空而没有任何阻挡,而不管队列的内容。根据JMS API文档,带有超时的receiver.receive
在超时后返回null,如果目标关闭,则立即返回null。如果我使用bean管理的事务,容器管理的事务或根本没有事务,问题是一样的。将JMS消息发布到另一个队列。无论我是否使用同一方法发送,Receive都会立即返回null。
为什么队列关闭,或为什么看起来如此?
不幸的是MDB是不是一种选择,因为我们必须通过隧道JMS同步调用(我不想愚弄的泥;-)
我不明白为什么MDB不是一个选项。 – 2009-10-07 03:46:43
,因为我们想要摆脱EJB – 2009-10-07 08:11:01
在J2EE容器中使用JMS消息的标准方式是使用MDB,它被称为最简单的EJB 2.x.所以我仍然不明白为什么你更喜欢使用**更复杂的无状态会话Bean(SLSB)。我会摆脱SLSB,但MDB是好的国际海事组织。 – 2009-10-07 19:04:18