【问题标题】:Camel replaceFromWith and Mock a JMS destination - Spring BootCamel replaceFromWith 和 Mock 一个 JMS 目的地 - Spring Boot
【发布时间】:2017-09-09 21:38:57
【问题描述】:

我查看了 Camel In Action 2 Chapter-9 示例,并查看了 previous questionthis user-group thread,但仍然卡住...

我正在使用 Spring-boot 和 Camel 2.18.x 我正在尝试将这两个 examples from Camel sample code 合二为一: to mockEndpoint 和 replaceFrom

工作场景:

  1. 我直接创建测试路由-->seda
  2. 我使用 Advicewith,并模拟所有端点
  3. 我的测试工作正常

工作场景:

  1. 我改变了目的地,直接-->jms
  2. 最后我得到一个异常,并看到 JMS 未能创建会话。

期望:我假设 JMS 将被 mock 取代,并且日志似乎表明了这一点。不确定为什么要调用 JMSProducer。这是预期的行为吗?

示例路线:

    from("direct:start")
            .id("testroute")
            .log("${body}")
            //.to("seda:finish")   //This works okay
            .to("jms:XYZ_Q")
     ;

单元测试类:

@RunWith(CamelSpringBootRunner.class)
@MockEndpoints
@UseAdviceWith
@SpringBootTest(classes = {UnitTestApplication.class, SampleTest.class})
public class SampleTest {

    @Autowired
    private CamelContext camelContext;

    @Autowired
    private ProducerTemplate producerTemplate;

    @Test
    public void test01() throws Exception {
        RouteDefinition route = camelContext.getRouteDefinition("testroute");
        AdviceWithRouteBuilder adviceWithRB = new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:renamed");
            }
        };

        route.adviceWith(camelContext, adviceWithRB);
        camelContext.start();

        producerTemplate.sendBody("direct:renamed", "  8888888820130601");
    }
}

我预计 JMS 组件不会尝试做任何事情,而是会被 mock 替换。这是不是一个错误的理解?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    我假设 JMS 会被 mock 取代

    1. 不,它不会被替换,因为replaceFromWith(..) 将路由的输入 (from(..)) 替换为新的端点 URI。它应该在以下情况下工作(使用你的例子):

      from("jms:XYZ_Q")
          .id("testroute")
          .log("${body}");
          //.to("seda:finish")   //This works okay
          //.to("jms:XYZ_Q")
      
    2. 如果您想模拟.to("jms:XYZ_Q") 部分(来自您的问题),那么您可以使用weaveByIdToString()weaveById() 等函数。更多信息:http://camel.apache.org/advicewith.html#AdviceWith-UsingAdviceWithRouteBuilder

    【讨论】:

      猜你喜欢
      • 2013-01-06
      • 2019-08-22
      • 2023-03-05
      • 2011-07-29
      • 2020-04-06
      • 2018-09-06
      • 2019-05-17
      • 2018-01-17
      • 2021-07-18
      相关资源
      最近更新 更多