在JMS简单接收器程序中未收到消息

时间:2015-10-25 15:32:42

标签: jms

我创建了简单的JMS客户端和接收器程序。我使用过JDk1.7和activeMQ 5.10.0。我的发件人代码正在使用特殊消息执行

ifelse()

1 个答案:

答案 0 :(得分:1)

您需要开始连接。

这个groovy代码适合我:

factory = new ActiveMQConnectionFactory("tcp://tpmint:61616");
dest = new ActiveMQQueue("foo.bar");

conn = null;
session = null;
consumer = null;

try {
    conn = factory.createConnection();
    println "Connected: $conn";
    session  = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
    println "Session: $session";
    consumer = session.createConsumer(dest);
    println "Consumer: $consumer";
    conn.start();
    msg = consumer.receive(1000);
    if(msg==null) println "Timeout";
    else println "Msg:$msg";
} finally {
    if(consumer!=null) try { consumer.close(); println "Consumer Closed";} catch (e) {}
    if(session!=null) try { session.close(); println "Session Closed";} catch (e) {}
    if(conn!=null) try { conn.close(); println "Connection Closed"; } catch (e) {e.printStackTrace(System.err);}
}

输出:

Connected: ActiveMQConnection {id=ID:tpmint-51137-1445798087365-0:8,clientId=null,started=false}
Session: ActiveMQSession {id=ID:tpmint-51137-1445798087365-0:8:1,started=false}
Consumer: ActiveMQMessageConsumer { value=ID:tpmint-51137-1445798087365-0:8:1:1, started=false }
Msg:ActiveMQTextMessage {commandId = 7, responseRequired = false, messageId = ID:tpmint-58446-1445793097761-4:2:1:1:3, originalDestination = null, originalTransactionId = null, producerId = ID:tpmint-58446-1445793097761-4:2:1:1, destination = queue://foo.bar, transactionId = null, expiration = 0, timestamp = 1445798905534, arrival = 0, brokerInTime = 1445798905534, brokerOutTime = 1445802982704, correlationId = , replyTo = null, persistent = false, type = , priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = org.apache.activemq.util.ByteSequence@5346e84e, dataStructure = null, redeliveryCounter = 2, size = 0, properties = {JMSXMessageCounter=1}, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = hey hey}
Consumer Closed
Session Closed
Connection Closed