Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Guava EventBus ComponentAvailable since Camel 2.10.0 The Google Guava EventBus allows publish-subscribe-style communication between components without requiring the components to explicitly register with one another (and thus be aware of each other). The guava-eventbus: component provides integration bridge between Camel and Google Guava EventBus infrastructure. With the latter component, messages exchanged with the Guava Maven users will need to add the following dependency to their <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-guava-eventbus</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> URI formatguava-eventbus:busName[?options] Where busName represents the name of the Options
UsageUsing 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."); Using 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); } }); DeadEvent considerationsKeep in mind that due to the limitations caused by the design of the Guava EventBus, you cannot specify event class to be received by the listener without creating class annotated with @Subscribe public void eventReceived(Object event) { if (eventClass == null || eventClass.isAssignableFrom(event.getClass())) { doEventReceived(event); ... This drawback of this approach is that package com.example; public interface CustomListener { @Subscribe void eventReceived(SpecificEvent event); } The listener presented above could be used in the endpoint definition as follows. from("guava-eventbus:busName?listenerInterface=com.example.CustomListener").to("seda:queue"); Consuming multiple type of eventsIn order to define multiple type of events to be consumed by Guava EventBus consumer use package com.example; public interface MultipleEventsListener { @Subscribe void someEventReceived(SomeEvent event); @Subscribe void anotherEventReceived(AnotherEvent event); } The listener presented above could be used in the endpoint definition as follows. from("guava-eventbus:busName?listenerInterface=com.example.MultipleEventsListener").to("seda:queue"); |