Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Created September 6, 2013 01:20
Show Gist options
  • Save jbrisbin/6458352 to your computer and use it in GitHub Desktop.
Save jbrisbin/6458352 to your computer and use it in GitHub Desktop.
Reactor Test file
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import reactor.event.Event;
import reactor.spring.annotation.Selector;
import reactor.spring.context.config.EnableReactor;
public class ReactorTest {
public static void main(String... args) {
AnnotationConfigApplicationContext appCtx = new AnnotationConfigApplicationContext(ReactorConfig.class);
TestService testService = appCtx.getBean(TestService.class);
testService.fireEvent("World");
}
@Configuration
@EnableReactor
public static class ReactorConfig {
@Bean
public Reactor rootReactor(Environment env) {
// implicit Environment is injected into bean def method
return Reactors.reactor().env(env).get();
}
@Bean
public HandlerBean handlerBean() {
return new HandlerBean();
}
@Bean
public TestService testService() {
return new TestService();
}
}
@Component
public static class HandlerBean {
@Selector(value = "test.topic", reactor = "@rootReactor")
public void onTestTopic(Event<String> evt) {
System.out.println("Hello " + evt.getData());
}
}
@Service
public static class TestService {
@Autowired
private Reactor rootReactor;
public void fireEvent(String s) {
rootReactor.notify("test.topic", Event.wrap(s));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment