客户端请求:
public Message receive(String message, String queueName) {
String text = null;
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"tcp://10.0.0.0:61616");
String userName = "smx";
String password = "smx";
Connection connection;
Message response =null;
try {
connection = connectionFactory.createConnection(userName, password);
connection.start();
((ActiveMQConnectionFactory) connectionFactory)
.setDispatchAsync(false);
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue destination = session.createQueue(queueName);
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage textMessage = session.createTextMessage(message);
Queue tempQueue = session.createQueue(queueName);
textMessage.setJMSReplyTo(tempQueue);
producer.send(textMessage);
MessageConsumer consumer = session.createConsumer(tempQueue);
response = consumer.receive();
response.acknowledge();
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
return response;
}
服务器端:
public void configure() throws Exception {
from("activemq:queue:GET_QUEUE?disableReplyTo=true")
.setExchangePattern(ExchangePattern.InOut)
.to("freemarker:Response.ftl")
.inOnly("activemq:queue:GET_QUEUE");
}
我已经尝试过的以下事情没有得到结果 ?1)的ActiveMQ:队列:GET_QUEUE disableReplyTo =真安培; concurrentConsumers = 5
?2)的ActiveMQ:队列:GET_QUEUE disableReplyTo =真安培; concurrentConsumers = 1&安培; maxConcurrentConsumers = 5
3)的ActiveMQ:队列:GET_QUEUE disableReplyTo =真安培; useMessageIDAsCorrelationID =真安培; concurrentConsumers = 5
4)的ActiveMQ:队列:GET_QUEUE disableReplyTo =真安培; useMessageIDAsCorrelationID =真安培; concurrentConsumers = 5&安培; asyncConsumer =真
答案 0 :(得分:1)
你已经在Camel中禁用了replyTo,你不应该这样做,然后删除最后一个inOnly,因为当路由完成时,Camel会自动将消息发送回队列的回复。