Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

CorrelationId for Spring Reactor

Marcin Grzejszczak edited this page Nov 15, 2015 · 7 revisions

WORKS UNTIL VERSION 2.0.1

Description

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

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
     }
}

Module configuration

If you want to use only this module just add a dependency:

repositories {
    jcenter()
}

dependencies {
    compile 'com.ofg:micro-infra-spring-reactor:0.6.0'
}

and enable this via annotation:

@Configuration
@EnableCorrelationIdForReactor
class MyModuleConfiguration {
}