设置C​amel ActiveMQ组件选项以编程方式

huangapple go评论70阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年8月20日 11:32:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63497896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定