Hi everyone,
I’ve encountered an issue while setting up a multi-cluster messaging system. Here’s the scenario:
- I use EventPublisher to detect user login events. This part works perfectly, with events being registered during bean initialization and unregistered during bean destruction.
- When a login event occurs, I handle the logic in a method annotated with
@EventListener
.
However, I also need to propagate a message across all clusters so that each cluster can handle specific logic independently. To achieve this:
- I set up a ClusterMessagingService and a ClusterConsumer to send and listen for messages between clusters.
- When I test message propagation without the EventPublisher, everything works as expected—messages are sent and received across clusters.
The problem:
As soon as I integrate EventPublisher into the same bean (initializing it alongside ClusterMessagingService), the cluster messages stop propagating. Commenting out the EventPublisher-related code makes cluster messaging functional again, but this also means I can no longer catch login events.
Below is my simplified code for reference:
@Component
public class LoginEventListener implements InitializingBean, DisposableBean {
@JiraImport
private final ClusterMessagingService clusterMessagingService;
private static final String CLEAR_SESSION_CHANNEL = "clear-chn";
@Autowired
public LoginEventListener(ClusterMessagingService clusterMessagingService) {
this.clusterMessagingService = clusterMessagingService;
}
@Override
public void afterPropertiesSet() throws Exception {
clusterMessagingService.registerListener(CLEAR_SESSION_CHANNEL, new ClusterConsumer());
clusterMessagingService.sendRemote(CLEAR_SESSION_CHANNEL, "TestMessage");
}
@Override
public void destroy() throws Exception {
// Unregister listener
}
@EventListener
public void onUserEvent(LoginEvent loggedInUser) {
// Handle login logic
}
}
When I inject and use EventPublisher in this class, cluster messages stop being propagated. Removing the EventPublisher-related code resolves the issue but prevents login event handling.
Key Questions:
- Is there any known conflict between EventPublisher and ClusterMessagingService?
- What could be causing this interference, and how can I resolve it so both EventPublisher and ClusterMessagingService work together?
- Is there an alternative design or workaround for managing both user login events and cluster-wide messaging simultaneously?
Any insights or suggestions would be greatly appreciated!