lk-dispatch
Canonical way to dispatch events to kinesis in the lk-architecture.
Usage
;; const kinesis = ; const dispatch = ; const eventType = "eventType";const eventData = key: "value";const eventOptions = sourceUserId: "userId" partitionKey: "partitionKey"; ;
Events in the lk-architecture
An event in the lk-architecture is a json object which conforms to the following json schema:
Example event:
const event = id: "f47ac10b-58cc-4372-a567-0e02b2c3d479" type: "eventType" data: /* whatever */ timestamp: "2016-01-01T00:00:00.000Z" source: userId: "userId" producerId: "producerId" kinesisPartitionKey: "kinesisPartitionKey" ;
Api
getDispatch(options)
Get the dispatch function.
Params
options
:kinesisClient
:AWS.Kinesis
instancekinesisStream
: name of the kinesis stream where events will be publishedproducerId
: a token to identify where events come from (will end up inevent.source.producerId
)
Return value
The dispatch function.
dispatch(type, data, options)
The dispatch function, publishes event to the configured kinesis stream.
Params
type
: the type of the eventdata
: the data of the eventoptions
(optional):sourceUserId (optional)
: the id of the user which triggered the operation that generated the eventpartitionKey
(optional): kinesis stream partition where to publish the event
Return value
A Promise that will be resolved with the published event when said event has been successfully published to kinesis.