У меня есть простое учебное пособие по пружинному 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>