@lastshotlabs/slingshot-kafka
npm install @lastshotlabs/slingshot-kafka
Functions
Section titled “Functions”createInMemoryDedupStore
Section titled “createInMemoryDedupStore”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 } = {}): MessageDedupStoreSource: packages/slingshot-kafka/src/kafkaConnectors.ts
createKafkaAdapter
Section titled “createKafkaAdapter”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
createKafkaConnectors
Section titled “createKafkaConnectors”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; },): KafkaConnectorHandleSource: packages/slingshot-kafka/src/kafkaConnectors.ts
getKafkaAdapterIntrospectionOrNull
Section titled “getKafkaAdapterIntrospectionOrNull”Read Kafka adapter introspection metadata from a bus when available.
function getKafkaAdapterIntrospectionOrNull(bus: SlingshotEventBus,): KafkaAdapterIntrospection | nullSource: packages/slingshot-kafka/src/kafkaAdapter.ts
kafkaAdapterOptionsSchema
Section titled “kafkaAdapterOptionsSchema”Zod schema for the programmatic Kafka event-bus adapter configuration.
Config Fields
Section titled “Config Fields”| Field | Description |
|---|---|
autoCreateTopics | Whether to automatically create topics that do not yet exist on the broker |
brokers | List of Kafka broker addresses to connect to |
clientId | Kafka client identifier for this adapter instance |
compression | Compression codec applied to produced messages (e.g. gzip, snappy, lz4) |
connectionTimeout | Milliseconds to wait for the initial broker connection before timing out |
defaultPartitions | Default number of partitions when auto-creating topics |
groupPrefix | Prefix prepended to all consumer group IDs created by this adapter |
heartbeatInterval | Interval in milliseconds between consumer heartbeats to the group coordinator |
maxRetries | Maximum number of retries for failed produce or consume operations |
replicationFactor | Replication factor used when auto-creating topics |
requestTimeout | Milliseconds to wait for a broker request response before timing out |
sasl | SASL authentication configuration for the Kafka connection |
sessionTimeout | Consumer session timeout in milliseconds; triggers a rebalance if exceeded |
ssl | TLS/SSL configuration for the Kafka connection |
startFromBeginning | Whether new consumer groups start reading from the earliest available offset |
topicPrefix | Prefix prepended to all topic names produced or consumed by this adapter |
validation | Event payload validation mode: strict rejects, warn logs, off skips validation |
Source: packages/slingshot-kafka/src/kafkaAdapter.ts
kafkaConnectorsSchema
Section titled “kafkaConnectorsSchema”Zod schema for the programmatic Kafka connector bridge configuration.
Config Fields
Section titled “Config Fields”| Field | Description |
|---|---|
| `/** 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 |
brokers | List of Kafka broker addresses for the connector bridge |
clientId | Kafka client identifier for this connector bridge instance |
compression | Default compression codec applied to produced messages across all connectors |
drainIntervalMs | Interval in milliseconds between pending buffer drain attempts |
hooks | Observability hooks for monitoring inbound and outbound connector activity |
inbound | Array of inbound connector definitions consuming from Kafka topics |
maxProduceAttempts | Maximum number of produce attempts before a buffered outbound message is dropped |
sasl | SASL authentication configuration for the connector Kafka connection |
serializer | Default serializer used for all connectors unless overridden per connector |
ssl | TLS/SSL configuration for the connector Kafka connection |
validationMode | Default payload validation mode applied to all connectors unless overridden |
Source: packages/slingshot-kafka/src/kafkaConnectors.ts
toGroupId
Section titled “toGroupId”Build a consumer group ID scoped to the fully resolved topic name and subscription name.
function toGroupId(prefix: string, topic: string, name: string): stringSource: packages/slingshot-kafka/src/kafkaTopicNaming.ts
toTopicName
Section titled “toTopicName”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): stringSource: packages/slingshot-kafka/src/kafkaTopicNaming.ts
Classes
Section titled “Classes”KafkaAdapterConfigError
Section titled “KafkaAdapterConfigError”Raised when Kafka adapter configuration is invalid or incomplete.
Source: packages/slingshot-kafka/src/errors.ts
KafkaAdapterError
Section titled “KafkaAdapterError”Base error for Kafka event bus adapter failures.
Source: packages/slingshot-kafka/src/errors.ts
KafkaConnectorError
Section titled “KafkaConnectorError”Base error for Kafka connector bridge failures.
Source: packages/slingshot-kafka/src/errors.ts
KafkaConnectorMessageIdError
Section titled “KafkaConnectorMessageIdError”Raised when an outbound connector event cannot be assigned a Kafka message ID.
Source: packages/slingshot-kafka/src/errors.ts
KafkaConnectorStateError
Section titled “KafkaConnectorStateError”Raised when a Kafka connector lifecycle method is called from an invalid state.
Source: packages/slingshot-kafka/src/errors.ts
KafkaConnectorValidationError
Section titled “KafkaConnectorValidationError”Raised when a Kafka connector definition fails schema validation.
Source: packages/slingshot-kafka/src/errors.ts
KafkaDuplicateConnectorError
Section titled “KafkaDuplicateConnectorError”Raised when two Kafka connectors are registered with the same key.
Source: packages/slingshot-kafka/src/errors.ts
KafkaDuplicateDurableSubscriptionError
Section titled “KafkaDuplicateDurableSubscriptionError”Raised when a Kafka durable subscription name is reused for the same event.
Source: packages/slingshot-kafka/src/errors.ts
KafkaDurableSubscriptionNameRequiredError
Section titled “KafkaDurableSubscriptionNameRequiredError”Raised when a durable Kafka subscription is registered without a required name.
Source: packages/slingshot-kafka/src/errors.ts
KafkaDurableSubscriptionOffError
Section titled “KafkaDurableSubscriptionOffError”Raised when code tries to unregister a durable Kafka subscription with off().
Source: packages/slingshot-kafka/src/errors.ts
Interfaces
Section titled “Interfaces”ConnectorObservabilityHooks
Section titled “ConnectorObservabilityHooks”Optional observability hooks for the connector bridge.
Source: packages/slingshot-kafka/src/kafkaConnectors.ts
KafkaAdapterDropEvent
Section titled “KafkaAdapterDropEvent”Telemetry signal emitted when the adapter drops or skips a message.
Source: packages/slingshot-kafka/src/kafkaAdapter.ts
KafkaAdapterHealth
Section titled “KafkaAdapterHealth”Health snapshot for the Kafka event-bus adapter.
Source: packages/slingshot-kafka/src/kafkaAdapter.ts
KafkaAdapterHealthSnapshot
Section titled “KafkaAdapterHealthSnapshot”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
KafkaAdapterIntrospection
Section titled “KafkaAdapterIntrospection”Introspection handle attached to Kafka-backed event buses.
Source: packages/slingshot-kafka/src/kafkaAdapter.ts
MessageDedupStore
Section titled “MessageDedupStore”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
DuplicatePublishPolicy
Section titled “DuplicatePublishPolicy”Policy applied when an outbound connector duplicates the Kafka adapter topic mapping.
Source: packages/slingshot-kafka/src/kafkaConnectors.ts
InboundConnectorConfig
Section titled “InboundConnectorConfig”One inbound Kafka topic or topic-pattern consumer definition.
Source: packages/slingshot-kafka/src/kafkaConnectors.ts
KafkaAdapterDeserErrorPolicy
Section titled “KafkaAdapterDeserErrorPolicy”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
KafkaAdapterDropReason
Section titled “KafkaAdapterDropReason”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
KafkaAdapterOptions
Section titled “KafkaAdapterOptions”Runtime options accepted by createKafkaAdapter.
Source: packages/slingshot-kafka/src/kafkaAdapter.ts
KafkaConnectorsConfig
Section titled “KafkaConnectorsConfig”Top-level configuration accepted by createKafkaConnectors.
Source: packages/slingshot-kafka/src/kafkaConnectors.ts
OutboundConnectorConfig
Section titled “OutboundConnectorConfig”One outbound Slingshot-event to Kafka-topic publish definition.
Source: packages/slingshot-kafka/src/kafkaConnectors.ts