Created
January 3, 2014 19:11
-
-
Save jbrisbin/8244393 to your computer and use it in GitHub Desktop.
Example usage of a Reactor with JDK 8 Lambdas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Jon! I have some legacy code on my hand and it's using the same classes of Reactor (
reactor.event.Event
andreactor.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 :)