128.3. 使用
路由消费者端使用 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); } });