129.4. 使用方法
在路由使用者端使用 guava-eventbus
组件将捕获发送到 Guava EventBus
的消息,并将它们转发到 Camel 路由。guava EventBus 消费者 异步 处理传入的消息。
SimpleRegistry registry = new SimpleRegistry(); EventBus eventBus = new EventBus(); registry.put("busName", eventBus); CamelContext camel = new DefaultCamelContext(registry); from("guava-eventbus:busName").to("seda:queue"); eventBus.post("Send me to the SEDA queue.");
在路由的制作者端使用 guava-eventbus
组件会将 Camel 交换的正文转发到 Guava EventBus
实例。
SimpleRegistry registry = new SimpleRegistry(); EventBus eventBus = new EventBus(); registry.put("busName", eventBus); CamelContext camel = new DefaultCamelContext(registry); from("direct:start").to("guava-eventbus:busName"); ProducerTemplate producerTemplate = camel.createProducerTemplate(); producer.sendBody("direct:start", "Send me to the Guava EventBus."); eventBus.register(new Object(){ @Subscribe public void messageHander(String message) { System.out.println("Message received from the Camel: " + message); } });