Interface ClusterEventBus
- All Known Implementing Classes:
NoOpClusterEventBus,PostgresClusterEventBus
ClusterEvents across the nodes of a horizontally-scaled
deployment — the mechanism that keeps live-UI updates in sync when more than one instance runs
behind a load balancer.
It is swappable exactly like com.onec.ui.media.MediaStorage: the framework wires a
NoOpClusterEventBus when nothing better is available, onec-cluster-starter supplies
a Postgres LISTEN/NOTIFY default on a Postgres datasource, and a commercial build
can replace either by exposing its own ClusterEventBus bean (e.g. Kafka- or Redis-backed),
which the auto-configuration's @ConditionalOnMissingBean default then steps aside for.
This is a best-effort live-UI signal, not a guaranteed-delivery event log. An
event dropped during a reconnect is acceptable — the browser re-fetches the affected surface on its
next interaction. Durable, exactly-once domain-event distribution is the job of the outbox relay
(com.onec.messaging.OutboxWriter + onec-kafka-starter), not this bus.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanWhether this bus actually crosses node boundaries.voidpublish(ClusterEvent event) Publish a change to peer nodes.voidsubscribe(Consumer<ClusterEvent> sink) Register a sink invoked for events that originated on other nodes.
-
Method Details
-
publish
Publish a change to peer nodes. Fan-out to the publishing node's own SSE clients has already happened synchronously on the local event path, so an implementation that echoes the event back to its own subscribers must let them filter it byClusterEvent.originNodeId().The implementation stamps the event's
ClusterEvent.originNodeId()with its own node id before sending (seeClusterEvent.withOrigin(java.lang.String)); callers may leave that fieldnull(asClusterEvent.entityChanged(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)does). -
subscribe
Register a sink invoked for events that originated on other nodes. A bus must not invoke the sink for the local node's own events (seeClusterEvent.originNodeId()). May be called more than once to attach multiple sinks. -
isDistributed
default boolean isDistributed()Whether this bus actually crosses node boundaries.falseforNoOpClusterEventBus(single-node / non-Postgres dev),truefor a real distributed implementation. Useful for diagnostics and for callers that want to log the active topology at startup.
-