Weblogic10 EJB2 会话 bean 中的 JMS 队列能够发送但不能接收

发布于 2024-08-06 15:32:27 字数 1897 浏览 4 评论 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,或者如果目标关闭则立即返回 null。如果我使用 bean 管理的事务、容器管理的事务或根本不使用事务,问题是相同的。将 JMS 消息发布到另一个队列是可行的。无论我之前是否以相同的方法发送,接收都会立即返回 null。

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

不幸的是,MDB 不是一个选项,因为我们必须通过 JMS 传输同步调用(而且我不想在泥球中浪费太多时间;-)

I try to receive a JMS message in an EJB2 (legacy sucks ;-) stateless session bean, in weblogic 10.0.1, with bean managed transactions. Queue definition from jms folder looks like

<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>

The business method in the bean does not start a transaction, so the JMS operations are not transactional. The executed code is

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);

The problem is that receiver.receive returns null immediately without any blocking, regardless of the contents of the queue. According to the JMS API doc., receiver.receive with a timeout returns null after the timeout or immediately if the destination is closed. The problem is the same if I use bean managed transactions, container managed transactions or no transactions at all. Posting a JMS message to another queue works. Receive returns null immediately regardless if I do a send before in the same method or not.

Why is the queue closed, or why does it seem so?

Unfortunately MDB is not an option because we have to tunnel a synchronous call through JMS (and I don't want to fool around too much in the Ball of Mud ;-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2024-08-13 15:32:27


MessageConsumer 接收者 = session.createConsumer(responseQueue);

conn.start();

Before
MessageConsumer receiver = session.createConsumer(responseQueue);
put
conn.start();

温柔嚣张 2024-08-13 15:32:27

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

 ......
 conn = cf.createConnection(); 
 conn.start();
 session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
 ......

After you create the connection, it needs to be started to get into the receiver mode.
Try this

 ......
 conn = cf.createConnection(); 
 conn.start();
 session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 
 ......
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文