簡體   English   中英

Spring JMS請求帶有隊列的響應

[英]spring jms request response with a queue

我有一個簡單的spring jms教程。貸款人充當接收者。 借款人是作為發送者的行動。 借款人發送工資和貸款金額,然后等待響應。 出借人做出決定並發回“接受”或“拒絕”。

在借款人方面,我正在做以下事情。

Message sentMessage = (Message)jmsTemplate.execute(new MyProducerCallBack(messageMap, "lenderResponseQueue"));

String filter = "JMSCorrelationID = '" + sentMessage.getJMSMessageID() + "'";
TextMessage tmsg = (TextMessage) jmsTemplate.receiveSelected("lenderResponseQueue", filter);

這是MyProducerCallBack中的代碼

public Object doInJms(Session session, MessageProducer producer) throws JMSException {
    System.out.println("inside doInJms");

    //create queue to receive accept or decline from lender
    Queue queue = session.createQueue(lenderResponseQueue);

    MapMessage jmsMapMsg = session.createMapMessage();
    populateJMSMapMsg(jmsMapMsg, mapMessage);
    jmsMapMsg.setJMSReplyTo(queue);

    //send salary and loan amount to lender
    producer.send(jmsMapMsg);

    //get the accept or decline from lender
    Message msg = session.createConsumer(queue).receive();

    if(msg instanceof TextMessage){
        System.out.println(((TextMessage)msg).getText());
    }

    return msg;
}

當消息msg = session.createConsumer(queue).receive(); 遇到日志拋出以下異常

2011-10-19 20:21:03,458 WARN [org.apache.activemq.ActiveMQSessionExecutor] - Received a message on a connection which is not yet started. 
Have you forgotten to call Connection.start()? Connection: ActiveMQConnection {id=ID:Reverb0253-PC-54217-1319070060323-0:1,clientId=ID:Reverb0253-PC-54217-1319070060323-1:1,started=false} 
Received: MessageDispatch {commandId = 0, responseRequired = false, consumerId = ID:Reverb0253-PC-54217-1319070060323-0:1:1:1, destination = queue://lenderResponseQueue, message = 
ActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:Reverb0253-PC-52978-1319058441747-0:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:Reverb0253-PC-52978-1319058441747-0:1:1:1, destination = queue://lenderResponseQueue, transactionId = null, expiration = 0, timestamp = 1319058485680, arrival = 0, brokerInTime = 1319058485706, brokerOutTime = 1319070063443, correlationId = ID:Reverb0253-PC-53001-1319058485443-0:1:1:1:1, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 5, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, text = Accepted!}, redeliveryCounter = 5}

接收隊列是lenderResponseQueue在Spring配置文件中不存在。 我需要在那里指定它嗎? 這是我來自配置文件的jmsTemplate

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="queueConnectionFactory"/>
    <property name="destinationResolver" ref="destinationResolver"/>
    <!-- name of destination -->
    <property name="defaultDestinationName" value="lenderRequestQueue"/>
    <!-- amount of time to wait before getting a message -->
    <property name="receiveTimeout" value="0"/>
    <!-- indicate weather queue or topic is used. false = queue or p2p -->
    <property name="pubSubDomain" value="false"/>
</bean>

您是否在執行回調中緊接着又有發送和接收的任何特定原因:

//send salary and loan amount to lender
producer.send(jmsMapMsg);

//get the accept or decline from lender
Message msg = session.createConsumer(queue).receive();

您通常會收到一個單獨的JmsTemplate。 receive ()調用(不在回調中)。 這將解耦/取消同步您的回調,最有可能解決您的問題:

Received a message on a connection which is not yet started.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM