dots-stream-consume-messages

A library to help consume messages from the DOTS Stream regardless of what schema version is being used

Usage no npm install needed!

<script type="module">
  import dotsStreamConsumeMessages from 'https://cdn.skypack.dev/dots-stream-consume-messages';
</script>

README

DOTS Stream Consume Messages

This library is intended to sit just before your code that process DOTS Stream messages. It will serve as middleware that automatically converts messages from envelope schema version to another if they are compatible. The primary purpose is to assist envelope schema version migrations in the future.

Messages cannot be transformed to a later version. e.g. Messages using the Version 1 envelope schema cannot be transformed into Version 2 of the envelope schema.

If a message is received that is not a version that this library can handle, then the library will throw an error. It is indicative of an error occurring earlier in the process and should be regarded as an exceptional circumstance.

Supported Envelope Schema Versions

The only supported schema versions are v1 and v2

Example Usage

Consuming Version 1 Messages

const { consumeV1Messages } = require('@dazn/dots-stream-consume-messages')

const v1Handler = (messages) => {
    const v1messages = consumeV1Messages({ messages })
}

Consuming Version 2 Messages

const { consumeV2Messages } = require('@dazn/dots-stream-consume-messages')

const v2Handler = (messages) => {
    const v2messages = consumeV2Messages({ messages })
}

Using Configurable API

If you wish to use external config or environment variables to decide what version of messages you wish to consume, a version can be provided to consumeMessages.

const { consumeMessages } = require('@dazn/dots-stream-consume-messages')

const v1Handler = (messages) => {
    const v1messages = consumeMessages({ messages, version: 'v2' })
}