![](/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.