0

我尝试在 weblogic 10.0.1 中的 EJB2(旧版糟透了 ;-) 无状态会话 bean 中接收 JMS 消息,并使用 bean 管理事务。jms 文件夹中的队列定义如下所示

<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,无论队列的内容如何,​​都会立即返回 null 而没有任何阻塞。根据 JMS API 文档,receiver.receive超时后返回 null,如果目标关闭,则立即返回。如果我使用 bean 管理的事务、容器管理的事务或根本没有事务,问题是一样的。将 JMS 消息发布到另一个队列有效。无论我之前是否以相同的方法发送过,Receive 都会立即返回 null。

为什么队列关闭了,或者为什么看起来如此?

不幸的是,MDB 不是一个选项,因为我们必须通过 JMS 隧道同步调用(而且我不想在泥球中胡闹太多;-)

4

2 回答 2

0

创建连接后,需要启动它以进入接收器模式。尝试这个

 ......
 conn = cf.createConnection(); 
 conn.start();
 session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
 ......
于 2010-12-10T15:02:23.780 回答
0

之前 MessageConsumer 接收者 = session.createConsumer(responseQueue); conn.start();

于 2009-12-15T12:18:16.650 回答