PacktPublishing/Hands-On-Reactive-Programming-in-Spring-5

Question on code in the book.

devinwhalen opened this issue · 3 comments

Hello,
I am confused on some code in the book.
What does this mean in the below code: $("channel")

I have not seen that notation in Java before.

Environment env = new Environment(); // (1)
Reactor reactor = Reactors.reactor() // (2)
 .env(env) //
 .dispatcher(Environment.RING_BUFFER) // (2.1)
 .get(); //

reactor.on($("channel"), // (3)

event -> System.out.println(event.getData())); //

Executors.newSingleThreadScheduledExecutor() // (4)
 .scheduleAtFixedRate( //
 () -> reactor.notify("channel", Event.wrap("test")), // 
 0, 100, TimeUnit.MILLISECONDS //
 );

@devinwhalen

Apologies for the delayed reply. Can you let us know in which chapter did you encounter this issue so that we can help you resolve it?

Hey, it is more of a question regarding the code samples in Chapter 4 page 132.

`Environment env = new Environment(); // (1)
Reactor reactor = Reactors.reactor() // (2)
.env(env) //
.dispatcher(Environment.RING_BUFFER) // (2.1)
.get(); //

reactor.on($("channel"), // (3)

event -> System.out.println(event.getData())); //

Executors.newSingleThreadScheduledExecutor() // (4)
.scheduleAtFixedRate( //
() -> reactor.notify("channel", Event.wrap("test")), //
0, 100, TimeUnit.MILLISECONDS //
);
`

I don’t understand this line: reactor.on($(“channel”). I have never seen this $ symbol before.

Hey, @devinwhalen!

I have not seen that notation in Java before.

it is specific Reactor 1 feature. It is not related to java ecosystem anyhow.

In the Reactor 1 context, $ works as a Selector which allows filtering events which come through a Dispatcher