由于您使用的是基于注释的配置,嵌入式 Active MQ 代理可能会意外停止,最好使用外部代理(例如:tcp://host:61616)。
JMS 端点上的 QoS 设置似乎不起作用。您可以从 ProducerTemplate 中获取 Header 值。
由于您使用的是 producerTemplate.requestBody,因此 activemq 端点假定它是请求和重播交换(InOut),并且由于路由超时没有响应。如果您想实施 (InOut),请按照 http://camel.apache.org/jms.html 的说明进行操作。由于您的 Routebuilder 是 InOnly,您需要从 ProducerTemplate 发送 disableReplyTo 标头。
将您的测试方法 testMessageSendToConsumerQueueRemoteId 替换为
@Transactional
@Test
public void testMessageSendToConsumerQueueRemoteId() throws Exception {
Status status = new Status();
status.setUserId(10);
statusDAO.save(status);
Endpoint mockEndpoint = this.context.getEndpoint(properties.getProperty("activemq.destination"));
PollingConsumer consumer = mockEndpoint.createPollingConsumer();
producerTemplate.sendBodyAndHeader(source, "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><example><remoteid>10</remoteid></example>","disableReplyTo","true");
Status savedStatus = consumer.receive(100).getIn().getBody(Status.class);
logger.info("savedStatus "+savedStatus.getID()+" "+savedStatus.getUserId());
assertNotNull(savedStatus);
}
将你的 ContentEnricherProcessor 的处理方法替换为
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
Entity entity = (Entity) message.getBody();
Status status = process(entity);
message.setBody(status);
exchange.getOut().setBody(status);
}
你的 camel.property 文件应该是
source=activemq:queue:deliverynotification
activemq.location=tcp://localhost:61616
activemq.destination=activemq:queue:responsenotification
如果您想收到生成的响应,您需要更改您的 RouteBuilder。
from(properties.getProperty("source"))
.process(new ResponseProcessor())
.inOnly("direct:z")
.end();
from("direct:z")
.unmarshal()
.jaxb("com.example.entities.xml").convertBodyTo(Entity.class)
.multicast()
.to("direct:x")
.end();
from("direct:x").transacted()
.process((ContentEnricherProcessor) applicationContext.getBean("contentEnricherProcessor"))
.to(properties.getProperty("activemq.destination"));
然后像这样改变生产者模式
Status response = producerTemplate.requestBody(source, "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><example><remoteid>11</remoteid></example>",Status.class);
这里是ResponseProcessor的处理方法
public void process(Exchange exchange) throws Exception {
Message outMsg = exchange.getIn().copy();
exchange.setOut(outMsg);
}
Camel ROCKS...您可以实现几乎任何企业集成用例或模式:)