2
votes

I appear to be losing messages sent to a reactor in my Spring application. I suspect that this is due to the time in the lifecycle of the Spring container that I start to produce messages.

In my particular use case there is a Spring Bean which performs some initialisation on startup. Part of this initialisation involves producing a message that is sent to the Reactor.

I suspect that there is an issue with the order that Spring is registering consumers and that the initialisation code has run before the consumers have been registered. If I run the code manually after startup, e.g. make a request to a controller which calls the same code then the messages make it to the consumer.

I tried various ways of changing the time in the lifecycle that the initialisation code runs, e.g. ApplicationListener<ContextRefreshedEvent>, ApplicationListener<ContextStartedEvent>, @PostConstruct method, implementing InitializingBean and so on. None of these approaches appear to work.

My consumers are annotated with @reactor.spring.annotation.Consumer and the methods with @reactor.spring.annotation.Selector.Just in case it is relevant, I am using Spring Boot and the auto-configured Reactor (@EnableReactor).

1

1 Answers

2
votes

The ConsumerBeanAutoConfiguration doesn't run until the ApplicationContext is refreshed, which means it won't look for Consumer beans until everything's been initialized (including, it sounds like, the beans that emit initial events).

If you put your Reactor configuration on a separate @Configuration bean and @Import that into your main config, that should make sure the Reactor configuration is complete before your main configuration starts configuring beans and emitting events.