Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Created January 3, 2014 19:11
Show Gist options
  • Save jbrisbin/8244393 to your computer and use it in GitHub Desktop.
Save jbrisbin/8244393 to your computer and use it in GitHub Desktop.
Example usage of a Reactor with JDK 8 Lambdas.
import static reactor.event.selector.Selectors.*;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import reactor.event.Event;
import reactor.function.Function;
/**
* Example of Reactor usage with JDK 8 Lambdas.
**/
public class ReactorSample {
public static void main(String... args) {
Environment env = new Environment();
// RingBufferDispatcher is the default
Reactor r = Reactors.reactor(env);
// Subscribe to topic "test"
r.<Event<String>>on($("test"), ev -> System.out.println("hi " + ev.getData()));
// Notify topic "test"
r.notify("test", Event.wrap("Jon"));
// Subscribe to topic "test2" and reply with value
r.receive($("test2"), new Function<Event<?>, Object>() {
@Override public Object apply(Event<?> event) {
return "Jon";
}
});
// Notify topic "test2" and reply to topic "test"
r.send("test2", Event.wrap("test2").setReplyTo("test"));
env.shutdown();
}
}
@kimalavi
Copy link

Hello Jon! I have some legacy code on my hand and it's using the same classes of Reactor (reactor.event.Event and reactor.core.Reactor) but I can't seem to find the right maven dependency for them. Could you please tell me which version of reactore-core you have used in this snippet?
P.S: I know it's from 9 years ago but you are my only hope right now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment