0
我試圖在EBJ內部使用JMS(activemq v 5.10),由tomee +(v 1.7)容器管理。 我也想使用JMS事務,而這也正是我有麻煩...... 這是我的EJB:EJB 3 + JMS和事務
@Singleton
@Remote(value = JmsSender.class)
public class EJBJmsSender implements JmsSender, ExceptionListener {
@Resource
private ConnectionFactory connectionFactory;
private QueueConnection connection;
public void sendMessage(String Queue, String contenuMessage)
throws ExceptionTechniqueApiJms {
InitialContext ctx = null;
Queue queueduService = null;
Connection queueConn = null;
try {
// get the initial context
ctx = new InitialContext();
// lookup the queue object
queueduService = (Queue) ctx.lookup(Queue);
} catch (NamingException e) {
...
}
Session queueSession = null;
try {
// create a queue connections
queueConn = connectionFactory.createConnection();
queueConn.start();
queueConn.setExceptionListener(this);
// create a transacted queue session
queueSession = queueConn.createSession(true,0);
// create a queue sender
MessageProducer queueSender = queueSession
.createProducer(queueduService);
queueSender.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage message = queueSession
.createTextMessage(contenuMessage);
queueSender.send(message);
queueSession.commit();
} catch (Exception e) {
...
} finally {
try {
if (queueConn != null) {
queueConn.close();
}
} catch (JMSException e) {
...
}
}
這個EJB原因一個IllegalStateException當「提交」被稱爲:
javax.jms.IllegalStateException: Not a transacted session
at org.apache.activemq.ActiveMQSession.commit(ActiveMQSession.java:569)
at org.apache.activemq.ra.ManagedSessionProxy.commit(ManagedSessionProxy.java:108)
...
如何在我的EJB中使用JMS「事務會話」?
什麼奇怪的是,JMS消息被提前發和可以食用...
感謝
克萊門特
你可以在tomee論壇找到答案:http://tomee-openejb.979440.n4.nabble.com/Activemq-embedded-createSession-unable-to-make-it-work-td4672172.html – 2014-11-25 09:05:20