![](/img/trans.png)
[英]How can we close and clean properly JMS Connection, Session, Consumer and Producer from system after Exception?
[英]JMS producer in Session bean on JBoss AS 6 throws exception
使用JBoss AS 6.1.0 Final和“默认”部署配置文件。
我喜欢从会话Bean发送JMS消息。 我设置如下:
/服务器/ default / deploy目录/我 - HornetQ的JMS的:
<configuration xmlns="urn:hornetq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
<queue name="queue/DummyMDBean">
<entry name="jms/DummyMDBean"/>
</queue>
</configuration>
在我有的豆:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class Demo implements DemoRemote, DemoLocal {
...
@Resource(mappedName = "java:/ConnectionFactory")
private static QueueConnectionFactory queueConnectionFactory;
@Resource(mappedName = "/jms/DummyMDBean")
private static Queue queue;
public void example() {
QueueConnection queueConnection = null;
try {
queueConnection = queueConnectionFactory.createQueueConnection();
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
e.printStackTrace();
}
try {
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(queue);
// Send a text message:
TextMessage textMessage = queueSession.createTextMessage();
textMessage.setText("Hello World");
queueSender.send(textMessage);
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
e.printStackTrace();
} finally {
closeConnection(queueConnection);
}
}
我收到以下错误:
15:46:05,011 INFO [STDOUT] Exception occurred: javax.jms.JMSException: Failed to create session factory
15:46:05,661 ERROR [STDERR] javax.jms.JMSException: Failed to create session factory
15:46:05,666 ERROR [STDERR] at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:605)
15:46:05,667 ERROR [STDERR] at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:131)
15:46:05,668 ERROR [STDERR] at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:126)
15:46:05,669 ERROR [STDERR] at com.demo.Demo.example(Demo.java:109)
...
15:46:05,782 ERROR [STDERR] at java.lang.Thread.run(Thread.java:722)
15:46:05,783 ERROR [STDERR] Caused by: java.lang.NullPointerException
15:46:05,784 ERROR [STDERR] at org.hornetq.core.client.impl.ServerLocatorImpl.removeFromConnecting(ServerLocatorImpl.java:682)
15:46:05,784 ERROR [STDERR] at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:751)
15:46:05,785 ERROR [STDERR] at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)
15:46:05,785 ERROR [STDERR] ... 180 more
第109行是“queueConnection = queueConnectionFactory.createQueueConnection();”。
除了上面的xml之外,我没有更改默认值。 关于这个问题的任何想法,以及如何解决它?
Demo.java中的第109行是否对应于以下行?
QueueSender queueSender = queueSession.createSender(queue);
我猜这个queue
可能是null。 您可以尝试按如下方式声明队列:
<queue name="queue/DummyMDBean">
<entry name="/jms/DummyMDBean"/>
</queue>
更新:
在EJB环境中使用的连接工厂也可能存在问题。 在AS 6.10 /ConnectionFactory
是一种非托管工厂,它在Servlet和JSF托管bean中工作,以创建直接目标侦听器(否则在容器中禁止)。
对于在EJB中的使用,你现在实际上应该使用java:/jmsXA
(这在6.0和5.x中是不同的)。 例如
@Resource(mappedName = "java:/JmsXA")
private ConnectionFactory queueConnectionFactory;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.