1

我在 WebSphere 7.0.0.21 上部署了一个消息驱动 Bean (MDB),它在 SIB(服务集成总线)队列上发送 JMS 消息。

创建 JMS 资源:

@Resource(name = CONN_FACTORY, mappedName = CONN_FACTORY)
private QueueConnectionFactory connFactory;

@PostConstruct
public void postConstruct() {
  queueConnection = connFactory.createQueueConnection();
  queueSession = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
  responseQueueSender = queueSession.createSender(getResponseQueue());
}

并销毁:

@PreDestroy
public void preDestroy() {
  responseQueueSender.close();
  queueSession.close();
  queueConnection.close();
}

像这样发送:

TextMessage responseMessage = queueSession.createTextMessage("message");
responseQueueSender.send(responseMessage, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, expirationTime);
queueSession.commit();

我有大约 20 个 MDB 实例。当我向 MDB 生成大量传入消息时,就会出现问题。我收到以下错误:

CWSIA0053E: An exception was received during the call to the method JmsSessionImpl.getTransaction (#1): javax.resource.spi.IllegalStateException: CWSJR1121E: An internal error has occurred. During the call to the method getManagedConnection the exception javax.resource.spi.ResourceAllocationException: CWSJR1028E: An internal error has occurred. The exception com.ibm.ws.sib.processor.exceptions.SIMPConnectionUnavailableException: CWSIK0022E: The connection is closed to messaging engine seit3022Node01.server1-Payment and cannot be used. was received in method createManagedConnection. was thrown..

如果我将队列连接工厂的连接池大小增加很多,错误发生的几率会更低,但它仍然存在。如果我降低池大小,则会经常发生错误。

如何关闭连接?如果我的连接池大小大于并发 MDB:s 的数量,如何关闭连接?

连接池有各种属性,但我找不到任何关于关闭正在使用的连接...而且我的代码肯定不会关闭任何连接(除了@PreDestroy

4

1 回答 1

0

我不确定是什么导致了SIMPConnectionUnavailableException这里,但是您在 MDB 中管理连接的方式无论如何都不正确。您应该将postConstructandpreDestroy方法中的代码移动到onMessage方法中,而不是尝试重用相同的连接。如果您想确保 MDB 具有正确的事务行为,这一点尤其重要。请注意,由于连接工厂执行连接池,因此为每个接收到的消息请求连接不会导致开销。

于 2012-05-25T17:05:58.607 回答