camel-SimpleRegistry

来源:互联网 发布:大数据平台建设方案 编辑:程序博客网 时间:2024/05/16 15:24

SimpleRegistry实际上是基于Map的注册,它主要被用于测试,或者单独的运行camel。

下面举一个例子,使用SimpleRegistry去单元测试Camel路由。

public class HelloBean {

public String hello(String name) {

return "Hello " + name;

}

}


public class SimpleRegistryTest extends TestCase {

private CamelContext context;

private ProducerTemplate template;

protected void setUp() throws Exception {

SimpleRegistry registry = new SimpleRegistry();

registry.put("helloBean", new HelloBean());

context = new DefaultCamelContext(registry);

template = context.createProducerTemplate();

context.addRoutes(new RouteBuilder() {

public void configure() throws Exception {

from("direct:hello").beanRef("helloBean");

}

});

context.start();

}

protected void tearDown() throws Exception {

template.stop();

context.stop();

}

public void testHello() throws Exception {

Object reply = template.requestBody("direct:hello", "World");

assertEquals("Hello World", reply);

}

}

为了测试你需要创建一个ProducerTemplate,使用它简单的发送一些消息给camel。当测试的方法做完后,需要使用template.stop()和context.stop()来释放资源。


0 0
原创粉丝点击