Skip to main content

KafkaExternalService

An ExternalService wrapping a Kafka cluster, exposing its topics as collections in the Skip runtime.

This adapter allows to easily create Kafka consumers, subscribing to external event/message streams and exposing their content as eager collections within the Skip runtime.

For a usage example, refer here.

Remarks

Subscription params may specify a fromBeginning boolean, which controls whether to consume all Kafka messages from the cluster, or only those sent since the creation of this external resource.

Implements

  • ExternalService

Constructors

new KafkaExternalService()

new KafkaExternalService(
kafka_config,
messageProcessor,
consumerOptions): KafkaExternalService

Parameters

ParameterType
kafka_config{ brokers: object[]; clientId: string; logLevel: logLevel; }
kafka_config.brokersobject[]
kafka_config.clientIdstring
kafka_config.logLevel?logLevel
messageProcessor(msg) => Iterable<[Json, Json]>
consumerOptionsOmit<ConsumerConfig, "groupId">

Returns

KafkaExternalService

Methods

shutdown()

shutdown(): Promise<void>

Shutdown the external service.

Returns

Promise<void>

Implementation of

ExternalService.shutdown

subscribe()

subscribe(
instance,
topic,
params,
callbacks): Promise<void>

Subscribe to a resource provided by the external service.

Parameters

ParameterTypeDescription
instancestringInstance identifier of the external resource.
topicstringName of the Kafka topic to expose as a resource.
params{ fromBeginning: boolean; }Parameters of the external resource.
params.fromBeginning?booleanControls whether to consume all Kafka messages from the cluster, or only from the creation of this external resource.
callbacks{ error: (error) => void; update: (updates, isInit) => Promise<void>; }Callbacks to react on error/update.
callbacks.error(error) => voidError callback.
callbacks.update(updates, isInit) => Promise<void>Update callback.

Returns

Promise<void>

Implementation of

ExternalService.subscribe

unsubscribe()

unsubscribe(instance): void

Unsubscribe from a resource provided by the external service.

Parameters

ParameterTypeDescription
instancestringInstance identifier of the external resource.

Returns

void

Implementation of

ExternalService.unsubscribe