为什么不能在jboss中的servlet中接收jms消息

时间:2011-05-29 17:03:52

标签: jboss jms

如果我将我的jms代码放在UserTransaction中,如:

-----------发送----------------------

UserTransaction.begin();
cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");

connection = cf.createConnection();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(queueName);
MessageProducer publisher = session.createProducer(queue);

connection.start();

TextMessage jmsMessage = session.createTextMessage(message);
publisher.send(jmsMessage);
publisher.close();
connection.stop();
connection.close();

UserTransaction.commit();

-----------接收----------------------

UserTransaction.begin();
ic = getInitialContext();
cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
connection = cf.createConnection();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(queueName);
MessageConsumer subscriber = session.createConsumer(queue);
connection.start();
while(true)
{
    TextMessage jmsMessage = (TextMessage)subscriber.receiveNoWait();
    if(jmsMessage == null)
    {
        break;
    }
}                
connection.close();
UserTransaction.commit();

我无法发送\接收消息(我不确定它是发送失败还是接收失败)。

为什么?

0 个答案:

没有答案