使用Spring Boot和Camel向两个ActiveMQ代理发送消息。

huangapple 未分类评论45阅读模式
英文:

Sending messages to two ActiveMQ brokers using springBoot & camel

问题

我在创建一个使用Apache Camel发送消息到两个独立的ActiveMQ代理的Spring Boot应用程序时遇到了困难。

我创建了两个ActiveMQComponent bean,每个都配置到不同的代理。然后,我定义了一个路由器,从第一个代理的队列中获取消息,处理它并将其传输到第二个代理的队列。

当我尝试运行应用程序时,我收到以下错误消息:

org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[{{primary.input.queue}}] -> [Log[New mess... because of No endpoint could be found for: primary://MyInputQueue 

我的配置代码如下:

@Bean("primary") 
public ActiveMQComponent primaryAMQComponent(final ConnectionFactory connectionFactory, final 
      JmsTransactionManager jmsTransactionManager ) {
	ActiveMQComponent component = new ActiveMQComponent();
	
	component.setBrokerURL("tcp://localhost:61616");
	component.setPreserveMessageQos(true);
	component.setConnectionFactory(connectionFactory);
	component.setTransactionManager(jmsTransactionManager);
	return component;
}

@Bean("secondary") 
public ActiveMQComponent primaryAMQComponent(final ConnectionFactory connectionFactory, final 
     JmsTransactionManager jmsTransactionManager ) {
    ActiveMQComponent component = new ActiveMQComponent();
	
	component.setBrokerURL("tcp://remotehost:61616");
	component.setPreserveMessageQos(true);
	component.setConnectionFactory(connectionFactory);
	component.setTransactionManager(jmsTransactionManager);
	return component;
}

我的路由器如下:

@Component
public class JmsTestRouter extends RouteBuilder {

	
    static final Logger log = LoggerFactory.getLogger(JmsTestRouter.class);

    @Override
    public void configure() throws Exception {
        from("{{primary.input.queue}}")
          .log("New message received")
          .process(exchange -> {
        	  System.out.println("New message received - message text :" + exchange.getMessage().getBody());
              String convertedMessage = exchange.getMessage().getBody() + " is processed ";
              exchange.getMessage().setBody(convertedMessage);
          })
          .to("{{secondary.output.queue}}")
          .log("Message is successfully sent to the output queue")
        .end();
    }
}

属性的定义如下:

primary.input.queue=primary:MyInputQueue
secondary.output.queue=secondary:MyOutputQueue

显然,我做错了一些事情。任何帮助将不胜感激。

英文:

I'm struggling in creating a Spring Boot application that uses Apache Camel and sends messages to two separate ActiveMQ brokers.

I've created two ActiveMQComponent beans, each is configured to a different broker. I then defined a router that gets a message from the queue in the first broker, processes it and transfers it to a queue in the second broker.

When I try to run the application I get the following error:

org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[{{primary.input.queue}}] -> [Log[New mess... because of No endpoint could be found for: primary://MyInputQueue 

My configuration code is:

@Bean("primary") 
public ActiveMQComponent primaryAMQComponent(final ConnectionFactory connectionFactory, final 
      JmsTransactionManager jmsTransactionManager ) {
	ActiveMQComponent component = new ActiveMQComponent();
	
	component.setBrokerURL("tcp://localhost:61616");
	component.setPreserveMessageQos(true);
	component.setConnectionFactory(connectionFactory);
	component.setTransactionManager(jmsTransactionManager);
	return component;
}

@Bean("secondary") 
public ActiveMQComponent primaryAMQComponent(final ConnectionFactory connectionFactory, final 
     JmsTransactionManager jmsTransactionManager ) {
    ActiveMQComponent component = new ActiveMQComponent();
	
	component.setBrokerURL("tcp://remotehost:61616");
	component.setPreserveMessageQos(true);
	component.setConnectionFactory(connectionFactory);
	component.setTransactionManager(jmsTransactionManager);
	return component;
}

My router is:

@Component
public class JmsTestRouter extends RouteBuilder {

	
    static final Logger log = LoggerFactory.getLogger(JmsTestRouter.class);

    @Override
    public void configure() throws Exception {
        from("{{primary.input.queue}}")
          .log("New message received")
          .process(exchange -> {
        	  System.out.println("New message received - message text :" + exchange.getMessage().getBody());
              String convertedMessage = exchange.getMessage().getBody() + " is processed ";
              exchange.getMessage().setBody(convertedMessage);
          })
          .to("{{secondary.output.queue}}")
          .log("Message is successfully sent to the output queue")
        .end();
    }
}

The properties' definition is:

primary.input.queue=primary:MyInputQueue
secondary.output.queue=secondary:MyOutputQueue

Apparently I'm doing something wrong. Any help will be appreciated.

huangapple
  • 本文由 发表于 2020年7月24日 00:51:57
  • 转载请务必保留本文链接:https://java.coder-hub.com/63059310.html
匿名

发表评论

匿名网友

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

确定