gpt4 book ai didi

java - 如何设置bean的Exchange到ProducerTemplate

转载 作者:行者123 更新时间:2023-12-02 04:43:00 25 4
gpt4 key购买 nike

我正在使用 CamelTestSupport 运行测试,

public class TestIntegrationBeanCtrlContrat extends CamelTestSupport {

@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;

@Produce(uri = "direct:start")
protected ProducerTemplate template;

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
this.from("direct:start")
.bean(MyClassA.class, "methodOfMyClassA").to("mock:result");
}
};
}
@Test
public void test_ControleBean_Integration() {
this.template.sendBody(....);

}

我正在尝试将另一个 bean 的主体放入生产者模板中,例如:

template.sendBody( bean(MyClassB.class, "methodOfMyClassB") )

可以这样做吗?

一般来说,我该如何设置 ProduceTempplace 中的输入。

最佳答案

我不确定我是否理解您的需求,但如果您想在路由过程中注入(inject)某些bean的结果,您应该使用Camel Mock来注入(inject)bean过程(在您的示例中为MyClassB.methodOfMyClassB()):

@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;

@Produce(uri = "direct:start")
protected ProducerTemplate template;

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").bean("BeanA", "methodA").to("mock:beanB").to("mock:result");
}
};
}

@Test
public void test() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:beanB");
mock.whenAnyExchangeReceived(new Processor() {
public void process(Exchange exchange) throws Exception {
// call the method of your class here
exchange.getIn().setBody(MyClassB.methodOfMyClassB());
}
});
template.sendBody("Your message body...");

// check some results
mock.assertIsSatisfied();
}

关于java - 如何设置bean的Exchange到ProducerTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29946905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com