我使用 Apache Camel 向 ActiveMQ 发送消息。我正在使用recipientList方法,因为我需要一个动态URI。
在运行时,我必须更改代理URL。我有以下问题:当我更改connectionFactory(新代理URL)时,生产者不会考虑它。但是,当我使用.to方法而不是recipientList方法时,它工作正常。我也有一个jms消费者,它很好地考虑了修改。
我的路线建设者:
from(JMS_OUTBOUND)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(JMS_FROM_HEADER, idOrganisation);
long fileSize = (long) exchange.getIn().getHeader("CamelFileLength");
if(fileSize > 50000000) {
exchange.getIn().setHeader("tooHeavyFile", true);
String parentPath = (String) exchange.getIn().getHeader("CamelFileParent");
String tooHeavyFileDirectory = parentPath + "/too_heavy_file/";
exchange.getIn().setHeader("tooHeavyFilePath", tooHeavyFileDirectory);
} else {
exchange.getIn().setHeader("tooHeavyFile", false);
}
}
})
.choice()
.when(header("tooHeavyFile").isEqualTo(false))
.recipientList(simple("mybrokerjms:queue:${header.jms-to}?mapJmsMessage=false"))
.end()
.otherwise()
.recipientList(simple("file://${header.tooHeavyFilePath}"))
.routeId(JMS_OUTBOUND_ID);
我如何更新代理网址:
context.removeComponent("mybrokerjms");
context.stopRoute(JmsRouteBuilder.JMS_INBOUND_ID);
context.stopRoute(JmsRouteBuilder.JMS_OUTBOUND_ID);
context.removeRoute(JmsRouteBuilder.JMS_INBOUND_ID);
context.removeRoute(JmsRouteBuilder.JMS_OUTBOUND_ID);
List<Hub> hubList = hubBoundary.findAll();
if(hubList != null && hubList.size() > 0) {
Hub hub = hubList.get(0);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://" + hub.getAddress() + ":" + hub.getPort());
context.addComponent("mybrokerjms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
Configuration configuration = configurationBoundary.find("ID_ORGANIZATION");
if(configuration != null) {
String idClient = configurationBoundary.find("ID_ORGANIZATION").getProperty();
context.addRoutes(new JmsRouteBuilder(idClient));
}
}
骆驼版:2.15.1。