Package app.l2nx.gs.adapter.core.kafka
Interface KafkaFactory
- All Known Implementing Classes:
DefaultKafkaFactory
public interface KafkaFactory
Test seam over the
NxKafka.configure().build() singleton bootstrap.
The default impl (DefaultKafkaFactory) wires the actual call chain.
Tests substitute a captor that records the inputs without standing up a real
Kafka client — bypassing the singleton makes KafkaInitializer unit-testable
and decouples adapter wiring from nx-gs-kafka's build-time side effects
(AdminClient connect attempt + JVM shutdown hook registration).
-
Method Summary
-
Method Details
-
build
app.l2nx.gs.kafka.KafkaState build(String brokers, String clientId, Map<String, Object> properties, Map<String, byte[]> staticHeaders, Consumer<app.l2nx.gs.kafka.KafkaState> stateChangeListener) Create or replace theNxKafkasingleton with this configuration.Implementations MUST shut down any existing live
NxKafkainstance before re-init, so aDEGRADED → ACTIVEreconnect cycle that re-fetches Kafka credentials remains idempotent.Implementations MUST NOT block on broker reachability — return immediately with
KafkaState.DISCONNECTEDif the cluster is unreachable.nx-gs-kafkakeeps a background reconnect loop that will recover.- Parameters:
brokers- comma-separated bootstrap serversclientId- client identifier — typicallynx-gs-adapter-<tenant-slug>-<server-slug>properties- raw Kafka client properties (security.protocol, sasl.mechanism, sasl.jaas.config)staticHeaders- Kafka headers stamped on every produced record (e.g.Nx-Server-Idresolved from the connect response); may be emptystateChangeListener- invoked on everyKafkaStatetransition after build (CONNECTED ↔ DISCONNECTED, → CLOSED)- Returns:
- the post-build state —
KafkaState.CONNECTEDorKafkaState.DISCONNECTED
-