我不能接受Apollo MQ的消息。

时间:2014-11-26 09:03:54

标签: java

当我连接Apollo MQ时,我的连接是真的。但如果我尝试从队列中获取消息,我将消息视为空。

我的连接代码是

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uName,pass,asBroker);

    connection = factory.createConnection();      
    connection.start();
    session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
    brokerConnected = true;

从队列接收消息的代码

public Syncable receive(String queue)抛出ActiveSyncMQException {

    ObjectMessage message = null;
    Syncable syncPojo = null;
    try{
        Destination destination = session.createQueue(queue);
        MessageConsumer consumer = session.createConsumer(destination);
        message = (ObjectMessage) consumer.receive(10000);
        syncPojo = (Syncable) message.getObject();
    }catch(JMSException jmsEx){
        throw new ActiveSyncMQException("JMS exception while receiving message from queue("+queue+")", jmsEx);
    }
    catch(Exception ex){
        throw new ActiveSyncMQException("Exception while receiving message from queue("+queue+")", ex);
    }
    return syncPojo;
}

0 个答案:

没有答案