【问题标题】:Camel RabbitMQ to REST Endpoint SpringBootTest failingCamel RabbitMQ 到 REST 端点 SpringBootTest 失败
【发布时间】:2019-12-23 23:01:22
【问题描述】:

我正在尝试编写 SpringBootTest 来测试 Camel 路线。我的路线如下所示:

 restConfiguration().producerComponent("http4")
            .host("http://127.0.0.1);

    from("rabbitmq:foo")
            .to(rest:post")
            .log("Hello!: ${body}");

这是我的测试:

@RunWith(CamelSpringRunner.class)
@MockEndpoints
@UseAdviceWith
@SpringBootTest
public class SimpleCamelRouteTest extends CamelTestSupport {

@EndpointInject(uri = "mock:rest")
private MockEndpoint mockEndpoint;

@Autowired
CamelContext context;

@Autowired
ProducerTemplate template;

@Before
public void setUp() throws Exception {

    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
       @Override
        public void configure() throws Exception {
           interceptSendToEndpoint("rabbitmq:foo")
                   .skipSendToOriginalEndpoint()
                   .to("mock:foo");
           interceptSendToEndpoint("http://*")
                   .skipSendToOriginalEndpoint()
                   .to("mock:rest");
        }
    });
    context.start();

}


@Test
public void test() throws InterruptedException {
    String body = "Camel";
    mockEndpoint.expectedMessageCount(1);

    template.sendBody("mock:foo", body);

    mockEndpoint.assertIsSatisfied();
}

}

看起来它正在尝试在启动时连接到一个真实运行的 RabbitMq 实例:(

18-08-2019 13:20:07.729 [Camel (camel-1) thread #3 - RabbitMQConsumer] INFO  o.a.c.c.rabbitmq.RabbitMQConsumer.call - Connection failed, will retry in 5000ms

java.net.ConnectException:连接被拒绝(连接被拒绝)

谁能给我一些建议,告诉我如何告诉我的 SpringBootTest 不要寻找正在运行的代理并尊重我设置的模拟(假设模拟设置正确。)

谢谢

【问题讨论】:

    标签: java rabbitmq apache-camel integration spring-boot-test


    【解决方案1】:

    您正在尝试使用 interceptSendToEndpoint 拦截消费者 (from)。这不可能。为此,您需要replaceFromWith

    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
       @Override
        public void configure() throws Exception {
           replaceFromWith("direct:triggerFoo");
           //...
        }
    });
    

    然后像这样触发路由:

    template.sendBody("direct:triggerFoo", body);
    

    此外,您正在拦截 http4 生产者,但从您的路线看来,您可能想要拦截 rest*

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 2019-10-19
      • 2022-10-08
      • 1970-01-01
      相关资源
      最近更新 更多