Active2 years, 9 months ago
REACTOR A reactor is the place where the desired reaction takes place that is, the removal of a selected contaminant. Containers, vessels or tanks in which chemical or biological reactions are carried out. 2 Source: Fundamentals of Water Treatment: Unit Processes.
I have a Spring Boot project that uses reactor for asynchronous tasks. I have began the task of upgrading the project to Spring Boot 1.3.1. As a side effect, it appears that it's using a new version of reactor. I am trying to figure out how to get it to work with the new reactor. I was using the @Consumer and @Selector annotations to tell it what classes and methods to use for an event like so:
I was previously notifying the receiver by doing this in a service class:
I have figured out that I need to change the rootReactor stuff to this:
But I'm not sure what I need to do on the consumer side. @Selector no longer supports the reactor attribute, so you can change it to eventBus, but what is the detault event bus named now? When I tried @Selector with ONLY the value attribute I started getting an NPE.
Twisty McGeeTwisty McGee
3 Answers
I just tried this with reactor-spring-messaging 2.0.7.RELEASE and it works even if the autowired field is private. The field does indeed have to be named exactly 'eventBus' or, if you name it something else, you have to specify its alternative name in the @Selector annotation.
If you prefer, you can @Autowire or @Inject the EventBus into your constructor and assign a property. This works just fine, and has the advantage that the IDE isn't angry at you about declaring an otherwise-unused field::
but the same rules about the field name apply. I tend to prefer constructor injection over injected fields.
wz2bwz2b
Your consumer must define an autowired, public (!) attribute of type eventBus. The consumer scans for it and register to the bus. Not a very nice solution, but it should work
Spring Reactor Pdf Template
}
Jan GalinskiJan Galinski8,10666 gold badges3838 silver badges6262 bronze badges
In moving from Reactor v1.x to Reactor v2.x,
Reactor
was renamed to EventBus
which is reflected in the @Selector
annotation.Your
@Selector
goes from..to..
Project Reactor
Reactor Tutorial
Sean ConnollySean Connolly3,53755 gold badges3030 silver badges6262 bronze badges