PURISTA API / Modules / @purista/mqttbridge
Module: @purista/mqttbridge
Package for using a MQTT broker like rabbitMQ as event bridge.
Example usage:
Example
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
- getCommandHandler
- getCommandResponseSubscriptionTopic
- getCommandSubscriptionTopic
- getDefaultMqttBridgeConfig
- getSharedTopicName
- getSubscriptionHandler
- getSubscriptionTopic
- getTopicName
- handleCommandResponse
- isMatchingTopic
- msToSec
Type Aliases
IncomingMessageFunction
Ƭ IncomingMessageFunction: (this
: MqttBridge
, payload
: EBMessage
, packet
: IPublishPacket
) => Promise
<void
>
Type declaration
▸ (this
, payload
, packet
): Promise
<void
>
Parameters
Name | Type |
---|---|
this | MqttBridge |
payload | EBMessage |
packet | IPublishPacket |
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
Functions
getCommandHandler
▸ getCommandHandler(address
, cb
, _metadata
, _eventBridgeConfig
): IncomingMessageFunction
Parameters
Name | Type |
---|---|
address | EBMessageAddress |
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 }> |
_metadata | CommandDefinitionMetadataBase |
_eventBridgeConfig | DefinitionEventBridgeConfig |
Returns
Defined in
mqttbridge/src/handler/getCommandHandler.impl.ts:29
getCommandResponseSubscriptionTopic
▸ getCommandResponseSubscriptionTopic(this
): string
Parameters
Name | Type |
---|---|
this | MqttBridge |
Returns
string
Defined in
mqttbridge/src/topic/getCommandResponseSubscriptionTopic.impl.ts:8
getCommandSubscriptionTopic
▸ getCommandSubscriptionTopic(this
, address
): string
Parameters
Name | Type |
---|---|
this | MqttBridge |
address | EBMessageAddress |
Returns
string
Defined in
mqttbridge/src/topic/getCommandSubscriptionTopic.impl.ts:10
getDefaultMqttBridgeConfig
▸ getDefaultMqttBridgeConfig(): Object
Returns
Object
Name | Type | Description |
---|---|---|
allowRetries? | boolean | allow retry of the initial connect |
defaultMessageExpiryInterval | number | the message expiry interval in seconds Default ts |
defaultSessionExpiryInterval | number | Default ts 0 |
emptyTopicPartString | string | The string which should be used in topics for parts, which are undefined Default ts __none__ |
qoSSubscription | QoS | QOS for all subscriptions Default ts 1 |
qosCommand | QoS | QOS for command, command responses and command response subscriptions messages Default ts 1 |
shareTopicName | string | the name of the shared topic (similar to pubsub name) Default ts sharedpurista |
shareTopicPrefix | string | the prefix to be used to dynamically create topic names for shared subscriptions Default ts $share |
topicPrefix | string | the prefix for topic to prevent name collisions Default ts purista |
Defined in
mqttbridge/src/getDefaultMqttBridgeConfig.impl.ts:5
getSharedTopicName
▸ getSharedTopicName(this
, topic
): string
Parameters
Name | Type |
---|---|
this | MqttBridge |
topic | string |
Returns
string
Defined in
mqttbridge/src/topic/getSharedTopicName.impl.ts:7
getSubscriptionHandler
▸ getSubscriptionHandler(_subscription
, cb
): IncomingMessageFunction
Parameters
Name | Type |
---|---|
_subscription | Subscription |
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
Defined in
mqttbridge/src/handler/getSubscriptionHandler.impl.ts:18
getSubscriptionTopic
▸ getSubscriptionTopic(this
, subscription
): string
Parameters
Name | Type |
---|---|
this | MqttBridge |
subscription | Subscription |
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
Name | Type | Description |
---|---|---|
this | MqttBridge | - |
message | EBMessage | the 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
Name | Type |
---|---|
this | MqttBridge |
payload | EBMessage |
packet | IPublishPacket |
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
Name | Type | Description |
---|---|---|
input | string | the real full topic |
pattern | string | the 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
Name | Type | Description |
---|---|---|
ms | number | Value in millisconads |
Returns
number
rounded value in seconds