-
Notifications
You must be signed in to change notification settings - Fork 49
Additional modules
You're using Spring Reactor? Good for you! Are you using ringBuffer as your default dispatcher? Great! Did you remember to pass correlationId to your new thread? Most likely not. With our approach you will never have to worry about it.
NOTE!!
This approach works only for Spring Reactor Java based approach!!!
Example of usage for the following scenario:
- We have a Config class for SpringBoot autoconfiguration
- We have a MySender class that sends an com.ofg.infrastructure.reactor.event.ReactorEvent using Reactor
- We have a MySubscriber class that subscribes to 'key' channel and executes logic from the annotated method
@Configuration
@EnableReactor
@ComponentScan
@EnableAutoConfiguration
class Config {
}
@Component
class MySender {
@Autowired public Reactor reactor
void sendsEvent() {
reactor.notify('key', ReactorEvent.wrap('data'))
}
}
@Component
class MySubscriber {
@Autowired public Reactor reactor
@Selector('key')
void receive(Event<String> event) {
// do some logic upon receiving messages
}
Reactor getReactor() {
return reactor
}
}
If you want to use only this module just add a dependency:
repositories {
jcenter()
}
dependencies {
compile 'com.ofg:micro-infra-spring-reactor:0.4.1'
}
and either
component scan over com.ofg.infrastructure.reactor:
@Configuration
@ComponentScan("com.ofg.infrastructure.reactor")
class MyWebAppConfiguration {
}
or add the configuration explicitly
@Configuration
@Import(com.ofg.infrastructure.reactor.aspect.ReactorAspectConfiguration)
class MyModuleConfiguration {
}
If you are using Apache Camel routes in your service there is now possibility to handle correlationId in received/sent message header.
For all incoming messages correlationId value will be taken from corresponding header and set in current thread. In case there is no such header field, a new one will be created with correlationId generated. On the other hand when a message with no correlationId header set is going to be sent the proper header field will be provided for it automatically.
NOTE!!
Current solution does not support routes defined in XML files.
There are two things required to have this working: configuration enabled (see Module configuration below) and Camel route should be defined in org.apache.camel.builder.RouteBuilder
implementation.
The implementation of the builder is straightforward:
class MyRouteBuilder extends RouteBuilder {
@Override
void configure() throws Exception {
from('direct:start').to('my:cool:endpoint').routeId('route-1')
}
}
Now you just need to expose the builder as a Spring bean in configuration of your service and that's it.
If you want to use only this module just add a dependency:
repositories {
jcenter()
}
dependencies {
compile 'com.ofg:micro-infra-spring-camel:0.4.4'
}
and either
component scan over com.ofg.infrastructure.camel:
@Configuration
@ComponentScan("com.ofg.infrastructure.camel")
class MyWebAppConfiguration {
}
or add the configuration explicitly
@Configuration
@Import(com.ofg.infrastructure.camel.CorrelationIdOnCamelRouteConfiguration.class)
class MyModuleConfiguration {
}