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

    Modifier and Type
    Method
    Description
    app.l2nx.gs.kafka.KafkaState
    build(String brokers, String clientId, Map<String,Object> properties, Consumer<app.l2nx.gs.kafka.KafkaState> stateChangeListener)
    Create or replace the NxKafka singleton with this configuration.
  • Method Details

    • build

      app.l2nx.gs.kafka.KafkaState build(String brokers, String clientId, Map<String,Object> properties, Consumer<app.l2nx.gs.kafka.KafkaState> stateChangeListener)
      Create or replace the NxKafka singleton with this configuration.

      Implementations MUST shut down any existing live NxKafka instance before re-init, so a DEGRADED → ACTIVE reconnect cycle that re-fetches Kafka credentials remains idempotent.

      Implementations MUST NOT block on broker reachability — return immediately with KafkaState.DISCONNECTED if the cluster is unreachable. nx-gs-kafka keeps a background reconnect loop that will recover.

      Parameters:
      brokers - comma-separated bootstrap servers
      clientId - client identifier — typically nx-gs-adapter-<tenant-slug>-<server-slug>
      properties - raw Kafka client properties (security.protocol, sasl.mechanism, sasl.jaas.config)
      stateChangeListener - invoked on every KafkaState transition after build (CONNECTED ↔ DISCONNECTED, → CLOSED)
      Returns:
      the post-build state — KafkaState.CONNECTED or KafkaState.DISCONNECTED