我正在嘗試編寫一個 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@SpringBootTestpublic class SimpleCamelRouteTest extends CamelTestSupport {@EndpointInject(uri = "mock:rest")private MockEndpoint mockEndpoint;@AutowiredCamelContext context;@AutowiredProducerTemplate template;@Beforepublic 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();}@Testpublic 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 5000msjava.net.ConnectException: 連接被拒絕 (Connection refused)任何人都可以給我一些建議,告訴我如何告訴我的 SpringBootTest 不要尋找正在運行的代理并尊重我設(shè)置的模擬(假設(shè)模擬設(shè)置正確。)
1 回答

白衣非少年
TA貢獻1155條經(jīng)驗 獲得超0個贊
您正在嘗試使用攔截消費者 (?from
)?interceptSendToEndpoint
。這不可能。為此你需要replaceFromWith
。
context.getRouteDefinitions().get(0).adviceWith(context,?new?AdviceWithRouteBuilder()?{ ???@Override ????public?void?configure()?throws?Exception?{ ???????replaceFromWith("direct:triggerFoo");? ?????????????//... ????} });
然后像這樣觸發(fā)路由:
template.sendBody("direct:triggerFoo",?body);
你也在攔截http4
生產(chǎn)者,但從你的路線看來你可能想要攔截rest*
。
添加回答
舉報
0/150
提交
取消