英文:
Setting camel ActiveMQ component options programmatically
问题
@Override
public void configure() throws Exception {
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61213");
broker.setPersistent(true);
broker.start();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(jmsProducerEndpointConfig.getBlindAddress());
// 将组件添加到 Camel 上下文
getContext().addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
from("test-jms:queue:MyQueue?autoStartup=true&allowNullBody=false")
.process(exchange -> {
System.out.println(exchange.getIn().getBody());
}).to("file://test");
}
英文:
I'm new to camel concepts and ActiveMQ concepts. Here I want using embedded broker and added it to camel context as component. Now I want to add some component options to ActiveMQ component (such as useSingleConnection=true
this is not a endpoint option it is component a option). I got that this could be achieve using spring XML. Is there way to do this programmatically?
@Override
public void configure() throws Exception {
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61213");
broker.setPersistent(true);
broker.start();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(jmsProducerEndpointConfig.getBlindAddress());
//added componet to camle context
getContext().addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
from("test-jms:queue:MyQueue?autoStartup=true&allowNullBody=false")
.process(exchange -> {
System.out.println(exchange.getIn().getBody());
}).to("file://test");
}
答案1
得分: 1
你离你发布的示例不远,像下面的代码这样应该足够了:
ActiveMQComponent amq = new ActiveMQComponent();
//
// 配置组件
//
getContext().addComponent("activemq", amq);
英文:
You are not far with the example you posted, something like the the code below should be enough:
ActiveMQComponent amq = new ActiveMQComponent();
//
// configure the component
//
getContext().addComponent("activemq", amq);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论