https://github.com/johnament/injectahvent
A lightweight CDI Integration for Apache Camel, forwarding Exchanges and Bodies as CDI events.
https://github.com/johnament/injectahvent
Last synced: over 1 year ago
JSON representation
A lightweight CDI Integration for Apache Camel, forwarding Exchanges and Bodies as CDI events.
- Host: GitHub
- URL: https://github.com/johnament/injectahvent
- Owner: johnament
- License: apache-2.0
- Created: 2013-10-13T23:36:55.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-21T01:21:18.000Z (over 12 years ago)
- Last Synced: 2025-01-07T13:14:26.449Z (over 1 year ago)
- Language: Java
- Size: 172 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
injectahvent
============
A lightweight CDI Integration for Apache Camel, forwarding Exchanges and Bodies as CDI events.
[](https://travis-ci.org/johnament/injectahvent)
## A word to the wise
The library is right now in early Alpha. As such, API is ugly and needs to be cleaned up. Please feel free to leave [an issue](https://github.com/johnament/injectahvent/issues) with feedback.
## Using the Library
There are two components that you can setup. The first is a `CDIExchangeProcessor` which allows you to register an event emitter that when messages are handed to a queue, a CDI event will be fired based on your configured qualifiers. Both the `body` and `Exchange` objects will get fired, but you can turn one or the other off as needed.
The usage of events requires setting up a `CDIExchangeProcessor` that uses a provided `Configuration` to determine what qualifiers should be observed for forwarding events to Camel.
To register it, simply add it to your `CamelContext`
RouteBuilder rb = new RouteBuilder() {
@Override
public void configure() throws Exception {
AnnotationLiteral sendable = new AnnotationLiteral(){};
Configuration config = ConfigurationBuilder.builder().addQualifiers(sendable).beanManager(beanManager).fireBody().fireExchange().build();
super.from("direct://foo").routeId("directFoo").process(new CDIExchangeProcessor(config));
}
};
This will register a new event emitter that fires messages for data that comes via the queue `direct://foo` to fire an event equivalent to `@Inject @Sendable Event objectEvent;`
The second is support for a drop in replacement of `ProducerTemplate` that is focused on CDI events. This allows you to fire a CDI event and translate it into a Camel route.
This requires some additional steps, namely you need to create a CDI Extension that extends `AbstractRoutingExtension` which will allow you to register the necessary Routes via CDI.
Internally this adds new CDI `ObserverMethod`s that will listen fot the configured types and send a message to a Camel route.
@Override
protected CamelContext getCamelContext(final BeanManager beanManager) throws Exception {
// add code that creates or retrieves your CamelContext.
return camelContext;
}
@Override
protected void createRoutes() {
super.addToAliased("direct://foo", "fooDirect");
}
This area still needs some work to allow delayed start up of routes, adding in callbacks for when to start the CamelContext and when to stop it.
## Gotchas
One criticism I have for this approach is that CDI events are essentially topics, not queues. Many receivers will get the event, if there are multiple registered.