Java / Micronaut Interview questions
Explain the internal working of Micronaut's event publishing system?
Micronaut's event system is a lightweight, synchronous-by-default pub/sub mechanism wired through the same compile-time DI infrastructure as everything else; there's no separate runtime event bus with reflective listener discovery.
You define an event as a plain class, publish it by injecting ApplicationEventPublisher<MyEvent> and calling publish(event), and consume it by implementing ApplicationEventListener<MyEvent> as a bean. Because listener classes are annotated beans, the compile-time processor already knows which listeners exist and what event type each handles, so there's no runtime scanning to find subscribers.
By default, listeners run synchronously on the publishing thread in the order they're registered, which matters for framework internals like bean-created and service-ready events that other components depend on firing predictably. Annotating a listener method with @Async instead dispatches it to a configured executor, decoupling slow listener work, like sending a notification, from the thread that triggered the event.
More Related questions...