Class EventsPublisher
NxEventsImpl.publishX(...)) call enqueue(EventEnvelope)
which is O(1) and never blocks on Kafka latency. The daemon
nx-events-publisher drains the queue, builds a
ProducerRecord, stamps the Nx-Message-Type header, and
hands off to the supplied EventsPublisher.Sender (production: NxKafka.sendBytesKeyRecord).
Drop policy on full queue:
EventsPublisher.DropPolicy.OLDEST(default) — evicts the head and admits the new envelope. Recent purchase events take priority over stale server-snapshot events.EventsPublisher.DropPolicy.NEWEST— drops the incoming envelope. Use only when oldest-events ordering is critical.
Counters expose the publisher's health via currentStatus()
for the heartbeat events module slot.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfaceBridge to the actual Kafka send. -
Constructor Summary
ConstructorsConstructorDescriptionEventsPublisher(@Nullable Map<String, String> familyTopics, EventsPublisher.Sender sender, EventsConfig config, app.l2nx.gs.adapter.core.events.EventTypeRegistry registry) -
Method Summary
Modifier and TypeMethodDescriptionapp.l2nx.gs.adapter.api.kafka.ops.ModuleStatusBuild a heartbeat slot snapshot.voidenqueue(@Nullable app.l2nx.gs.adapter.core.events.EventEnvelope envelope) Append an envelope to the publish queue.booleanisFamilyEnabled(String familyKey) True when the family key has a non-empty topic configured.voidstart()Spawn the publisher daemon.voidstop()Stop the publisher.
-
Constructor Details
-
EventsPublisher
public EventsPublisher(@Nullable Map<String, String> familyTopics, EventsPublisher.Sender sender, EventsConfig config, app.l2nx.gs.adapter.core.events.EventTypeRegistry registry)
-
-
Method Details
-
start
public void start()Spawn the publisher daemon. Idempotent. -
stop
public void stop()Stop the publisher. Signals the daemon, waits up toshutdownDrainMsfor in-flight envelopes to drain, then cancels. Idempotent. -
enqueue
public void enqueue(@Nullable app.l2nx.gs.adapter.core.events.EventEnvelope envelope) Append an envelope to the publish queue. On full queue, applies the configuredEventsPublisher.DropPolicy; never blocks longer than theArrayBlockingQueue.offer()fast path.Drop counter accounts for every lost envelope, including races. With
EventsPublisher.DropPolicy.OLDESTand concurrent callers, an enqueue may evict the head AND lose its own envelope to another caller filling the freed slot first — both losses are counted (droppedTotal += 2). -
currentStatus
public app.l2nx.gs.adapter.api.kafka.ops.ModuleStatus currentStatus()Build a heartbeat slot snapshot.State semantics:
ACTIVEwhen the daemon is running,DISABLEDwhen it has not been started or has been stopped. TODO(messaging-r14): emitDEGRADEDwhen thefailed-total / published-totalratio exceeds an internal threshold (spec suggests ~5% over the last minute). Operators can still derive degradation from the raw counters today; the rolling-window tracking is deferred until a real ops case demands it. -
isFamilyEnabled
True when the family key has a non-empty topic configured.
-