I have two EventHandlers
registered via DS
(declarative services).
Now, there is another DS service calling EventAdmin.sendEvent()
.
It happens that only one of the EventHandlers
receives the event as one of them seems to not be ready when the event is fired.
As a consequence, when the second EventHandler
becomes available, it is too late as the event is already consumed.
Both EventHandlers
have immediate=true
set in the @Component
annotation.
Is there an "elegant" way to solve this scenario?
This is just a timing issue. Not all the consumers are ready when the producer produces. The point of Event Admin is to decouple event producers from consumers. But if you need to make sure all consumers see all events, then you will need to either ensure all consumers are ready to receive before any producer produces, or select another mechanism which can deliver events from the past to newly arriving consumers.