Skip to content

PURISTA API / Modules / @purista/mqttbridge

Module: @purista/mqttbridge

Package for using a MQTT broker like rabbitMQ as event bridge.

Example usage:

Example

typescript
import { MqttBridge } from '@purista/mqttbridge'

// create and init our eventbridge
const eventBridge = new MqttBridge()
await eventBridge.start()

Table of contents

Classes

Type Aliases

Variables

Functions

Type Aliases

IncomingMessageFunction

Ƭ IncomingMessageFunction: (this: MqttBridge, payload: EBMessage, packet: IPublishPacket) => Promise<void>

Type declaration

▸ (this, payload, packet): Promise<void>

Parameters
NameType
thisMqttBridge
payloadEBMessage
packetIPublishPacket
Returns

Promise<void>

Defined in

mqttbridge/src/types/IncomingMessageFunction.ts:6


MqttBridgeConfig

Ƭ MqttBridgeConfig: Prettify<{ allowRetries?: boolean ; defaultMessageExpiryInterval: number ; defaultSessionExpiryInterval: number ; emptyTopicPartString: string ; qoSSubscription: QoS ; qosCommand: QoS ; shareTopicName: string ; shareTopicPrefix: string ; topicPrefix: string } & IClientOptions>

the configuration for the MQTT event bridge

Defined in

mqttbridge/src/types/MqttBridgeConfig.ts:8

Variables

puristaVersion

Const puristaVersion: "1.11.0"

Defined in

mqttbridge/src/version.ts:1

Functions

getCommandHandler

getCommandHandler(address, cb, _metadata, _eventBridgeConfig): IncomingMessageFunction

Parameters

NameType
addressEBMessageAddress
cb(message: { contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: unknown ; payload: unknown } ; principalId?: string ; receiver: EBMessageAddress ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }) => Promise<{ contentEncoding: "utf-8" ; contentType: "application/json" ; correlationId: string ; eventName?: string ; id: string ; isHandledError: boolean ; messageType: CommandErrorResponse ; otp?: string ; payload: { data?: unknown ; message: string ; status: StatusCode } ; principalId?: string ; receiver: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string } | { contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: unknown ; principalId?: string ; receiver: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }>
_metadataCommandDefinitionMetadataBase
_eventBridgeConfigDefinitionEventBridgeConfig

Returns

IncomingMessageFunction

Defined in

mqttbridge/src/handler/getCommandHandler.impl.ts:29


getCommandResponseSubscriptionTopic

getCommandResponseSubscriptionTopic(this): string

Parameters

NameType
thisMqttBridge

Returns

string

Defined in

mqttbridge/src/topic/getCommandResponseSubscriptionTopic.impl.ts:8


getCommandSubscriptionTopic

getCommandSubscriptionTopic(this, address): string

Parameters

NameType
thisMqttBridge
addressEBMessageAddress

Returns

string

Defined in

mqttbridge/src/topic/getCommandSubscriptionTopic.impl.ts:10


getDefaultMqttBridgeConfig

getDefaultMqttBridgeConfig(): Object

Returns

Object

NameTypeDescription
allowRetries?booleanallow retry of the initial connect
defaultMessageExpiryIntervalnumberthe message expiry interval in seconds Default ts
defaultSessionExpiryIntervalnumberDefault ts 0
emptyTopicPartStringstringThe string which should be used in topics for parts, which are undefined Default ts __none__
qoSSubscriptionQoSQOS for all subscriptions Default ts 1
qosCommandQoSQOS for command, command responses and command response subscriptions messages Default ts 1
shareTopicNamestringthe name of the shared topic (similar to pubsub name) Default ts sharedpurista
shareTopicPrefixstringthe prefix to be used to dynamically create topic names for shared subscriptions Default ts $share
topicPrefixstringthe prefix for topic to prevent name collisions Default ts purista

Defined in

mqttbridge/src/getDefaultMqttBridgeConfig.impl.ts:5


getSharedTopicName

getSharedTopicName(this, topic): string

Parameters

NameType
thisMqttBridge
topicstring

Returns

string

Defined in

mqttbridge/src/topic/getSharedTopicName.impl.ts:7


getSubscriptionHandler

getSubscriptionHandler(_subscription, cb): IncomingMessageFunction

Parameters

NameType
_subscriptionSubscription
cb(message: EBMessage) => Promise<undefined | Omit<{ contentEncoding: string ; contentType: string ; correlationId?: string ; eventName: string ; id: string ; messageType: CustomMessage ; otp?: string ; payload?: unknown ; principalId?: string ; receiver?: EBMessageAddress ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }, "id" | "timestamp">>

Returns

IncomingMessageFunction

Defined in

mqttbridge/src/handler/getSubscriptionHandler.impl.ts:18


getSubscriptionTopic

getSubscriptionTopic(this, subscription): string

Parameters

NameType
thisMqttBridge
subscriptionSubscription

Returns

string

Defined in

mqttbridge/src/topic/getSubscriptionTopic.impl.ts:10


getTopicName

getTopicName(this, message): string

Calculates the MQTT topic name for a message which should be sent. Something like: purista/ message_type/ principal_id/ sender_instance_id/ sender_name/ sender_version/ sender_target/ eventname/ sender_instance_id/ receiver_name/ receiver_version/ receiver_target

Parameters

NameTypeDescription
thisMqttBridge-
messageEBMessagethe message to send

Returns

string

the MQTT topic

Defined in

mqttbridge/src/topic/getTopicName.impl.ts:31


handleCommandResponse

handleCommandResponse(this, payload, packet): Promise<void>

Parameters

NameType
thisMqttBridge
payloadEBMessage
packetIPublishPacket

Returns

Promise<void>

Defined in

mqttbridge/src/handler/handleCommandResponse.impl.ts:16


isMatchingTopic

isMatchingTopic(input, pattern): boolean

Checks if a given topic is matching against a subscription pattern

Parameters

NameTypeDescription
inputstringthe real full topic
patternstringthe topic subscription pattern

Returns

boolean

Defined in

mqttbridge/src/topic/isMatchingTopic.impl.ts:8


msToSec

msToSec(ms): number

Convert milliseconds into seconds and round decimal to integer if needed.

Parameters

NameTypeDescription
msnumberValue in millisconads

Returns

number

rounded value in seconds

Defined in

mqttbridge/src/msToSec.impl.ts:7