Skip to content

@lastshotlabs/slingshot-kafka

npm install @lastshotlabs/slingshot-kafka

Build a default in-memory LRU MessageDedupStore with TTL eviction.

Each set() records a timestamp and the access order is refreshed by has() lookups. Stale entries past their TTL are treated as misses; cold entries are evicted when the cache exceeds maxKeys.

function createInMemoryDedupStore(options: { maxKeys?: number } = {}): MessageDedupStore

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Create a Slingshot event bus backed by Kafka durable topics.

Non-durable listeners still execute in-process. Durable listeners are bridged through Kafka topics, consumer groups, and a reconnect buffer for transient producer failures.

function createKafkaAdapter(rawOpts: KafkaAdapterOptions & EventBusSerializationOptions & { /** * Optional metrics sink. When provided, the adapter records publish / * consume / dlq counters, publish/consume durations, and pending-buffer * + connection-state gauges so operators can wire ad-hoc dashboards * without log scraping. Defaults to a no-op emitter. */ metrics?: MetricsEmitter; /** * Optional structured logger. Defaults to a console-backed JSON * logger when omitted. All warn/error paths route through the logger * so no structured information is lost to console formatting. */ logger?: Logger; },): AcknowledgedEventBus &

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Create a programmatic bridge between the Slingshot event bus and Kafka topics.

Inbound connectors consume Kafka messages into handlers. Outbound connectors subscribe to Slingshot events and publish them to Kafka with buffering and duplicate-produce safeguards.

function createKafkaConnectors(rawOpts: KafkaConnectorsConfig & { /** * Optional metrics sink. When provided, the connector records publish / * consume / dlq counters and durations alongside the existing * observability hooks. Defaults to a no-op emitter. */ metrics?: MetricsEmitter; },): KafkaConnectorHandle

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Read Kafka adapter introspection metadata from a bus when available.

function getKafkaAdapterIntrospectionOrNull(bus: SlingshotEventBus,): KafkaAdapterIntrospection | null

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Zod schema for the programmatic Kafka event-bus adapter configuration.

FieldDescription
autoCreateTopicsWhether to automatically create topics that do not yet exist on the broker
brokersList of Kafka broker addresses to connect to
clientIdKafka client identifier for this adapter instance
compressionCompression codec applied to produced messages (e.g. gzip, snappy, lz4)
connectionTimeoutMilliseconds to wait for the initial broker connection before timing out
defaultPartitionsDefault number of partitions when auto-creating topics
groupPrefixPrefix prepended to all consumer group IDs created by this adapter
heartbeatIntervalInterval in milliseconds between consumer heartbeats to the group coordinator
maxRetriesMaximum number of retries for failed produce or consume operations
replicationFactorReplication factor used when auto-creating topics
requestTimeoutMilliseconds to wait for a broker request response before timing out
saslSASL authentication configuration for the Kafka connection
sessionTimeoutConsumer session timeout in milliseconds; triggers a rebalance if exceeded
sslTLS/SSL configuration for the Kafka connection
startFromBeginningWhether new consumer groups start reading from the earliest available offset
topicPrefixPrefix prepended to all topic names produced or consumed by this adapter
validationEvent payload validation mode: strict rejects, warn logs, off skips validation

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Zod schema for the programmatic Kafka connector bridge configuration.

FieldDescription
`/** Override the default inbound dedup TTL (1h). Set to 0 to disable dedup. */
dedupTtlMs`Override the default inbound dedup TTL (1h); set to 0 to disable dedup
brokersList of Kafka broker addresses for the connector bridge
clientIdKafka client identifier for this connector bridge instance
compressionDefault compression codec applied to produced messages across all connectors
drainIntervalMsInterval in milliseconds between pending buffer drain attempts
hooksObservability hooks for monitoring inbound and outbound connector activity
inboundArray of inbound connector definitions consuming from Kafka topics
maxProduceAttemptsMaximum number of produce attempts before a buffered outbound message is dropped
saslSASL authentication configuration for the connector Kafka connection
serializerDefault serializer used for all connectors unless overridden per connector
sslTLS/SSL configuration for the connector Kafka connection
validationModeDefault payload validation mode applied to all connectors unless overridden

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Build a consumer group ID scoped to the fully resolved topic name and subscription name.

function toGroupId(prefix: string, topic: string, name: string): string

Source: packages/slingshot-kafka/src/kafkaTopicNaming.ts

Convert a Slingshot event key to a Kafka topic name.

The event’s : separators are replaced with . (preserving the namespace convention) and the prefix is prepended verbatim. Inputs that contain Kafka-illegal characters or consecutive colons are passed through; callers are responsible for keeping event names well-formed (use defineEvent and the namespace:resource.action convention).

function toTopicName(prefix: string, event: string): string

Source: packages/slingshot-kafka/src/kafkaTopicNaming.ts

Raised when Kafka adapter configuration is invalid or incomplete.

Source: packages/slingshot-kafka/src/errors.ts

Base error for Kafka event bus adapter failures.

Source: packages/slingshot-kafka/src/errors.ts

Base error for Kafka connector bridge failures.

Source: packages/slingshot-kafka/src/errors.ts

Raised when an outbound connector event cannot be assigned a Kafka message ID.

Source: packages/slingshot-kafka/src/errors.ts

Raised when a Kafka connector lifecycle method is called from an invalid state.

Source: packages/slingshot-kafka/src/errors.ts

Raised when a Kafka connector definition fails schema validation.

Source: packages/slingshot-kafka/src/errors.ts

Raised when two Kafka connectors are registered with the same key.

Source: packages/slingshot-kafka/src/errors.ts

Raised when a Kafka durable subscription name is reused for the same event.

Source: packages/slingshot-kafka/src/errors.ts

Raised when a durable Kafka subscription is registered without a required name.

Source: packages/slingshot-kafka/src/errors.ts

Raised when code tries to unregister a durable Kafka subscription with off().

Source: packages/slingshot-kafka/src/errors.ts

Optional observability hooks for the connector bridge.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Telemetry signal emitted when the adapter drops or skips a message.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Health snapshot for the Kafka event-bus adapter.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Structured health snapshot for the Kafka adapter, designed for higher-level health-endpoint aggregation.

status is derived from the underlying signals:

  • 'unhealthy' when the adapter has been shut down or the producer is disconnected with pending events buffered.
  • 'degraded' when the producer is disconnected with no buffer pressure, the admin client is disconnected, or any registered consumer is disconnected.
  • 'healthy' otherwise.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Introspection handle attached to Kafka-backed event buses.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Pluggable consumer-side dedup store keyed by slingshot.message-id header.

Implementations may live in Redis, Memcached, or any TTL-aware store. The connector calls has() before invoking the inbound handler and set() after successful processing. A default in-memory LRU is used when none is provided.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Policy applied when an outbound connector duplicates the Kafka adapter topic mapping.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

One inbound Kafka topic or topic-pattern consumer definition.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

Behavior when the consumer encounters an undecodable message (deserialization failure or null value). dlq (default) routes raw bytes to ${topic}.deser-dlq so operators can replay after fixing the schema. skip commits the offset and continues, mirroring legacy behavior.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Reasons the adapter may drop or skip an event. Surfaced through onDrop so SREs can wire metrics and alerts without log scraping.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Runtime options accepted by createKafkaAdapter.

Source: packages/slingshot-kafka/src/kafkaAdapter.ts

Top-level configuration accepted by createKafkaConnectors.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts

One outbound Slingshot-event to Kafka-topic publish definition.

Source: packages/slingshot-kafka/src/kafkaConnectors.ts