Search code examples
spring-pulsar

Creating listeners without springboot auto config


I have a usecase where I need to start listeners programmatically based on some configuration at runtime.

I was wondering how to register pulsar listeners at runtime without using the static @PulsarListener annotation.

thank you


Solution

  • The way it currently works is as follows:

    The PulsarListenerAnnotationBeanPostProcessor scans all @PulsarListener and for each one it...

    • asks the PulsarListenerEndpointRegistrar to register the endpoint to a container factory
    • registrar in turn asks the PulsarListenerEndpointRegistry to register the endpoint and container factory
    • registry in turn creates the container (using the factory)
    • registry handles the lifecycle (start/stop) of all registered containers (i.e. when registry bean is started it spins through and calls start on all registered containers)

    This is a more uncommon usecase and as such there is no built-in support for registering containers w/ the registry dynamically after app start.

    However, you can create your own container instances and handle the lifecycle methods yourself by manually starting/stopping them (e.g. here).

    I will provide a prototype that details several variants of the above in the next 24-48hrs but wanted to get you the above preliminary information quickly.