Node
The KubeMQ SDK for NodeJS enables Node JS/Typescript developers to seamlessly communicate with the KubeMQ server, implementing various communication patterns such as Events, EventStore, Commands, Queries, and Queues.
Sources
SDK
Examples
Prerequisites
Node.js (Ensure you have a recent version of Node.js installed)
TypeScript Compiler
KubeMQ server running locally or accessible over the network
Installation
The recommended way to use the SDK for Node in your project is to consume it from Node package manager.
Payload Details
Metadata: The metadata allows us to pass additional information with the event. Can be in any form that can be presented as a string, i.e., struct, JSON, XML and many more.
Body: The actual content of the event. Can be in any form that is serializable into a byte array, i.e., string, struct, JSON, XML, Collection, binary file and many more.
ClientID: Displayed in logs, tracing, and KubeMQ dashboard(When using Events Store, it must be unique).
Tags: Set of Key-value pair that help categorize the message
KubeMQ PubSub Client
For executing PubSub operation we have to create the instance of PubsubClient, its instance can be created with minimum two parameter address
(KubeMQ server address) & clientId
. With these two parameter plainText connections are established. The table below describes the Parameters available for establishing a connection.
PubSub Client Configuration
Pubsub Client connection establishment example code
The example below demonstrates to construct PubSubClient with ssl and other configurations:
Ping To KubeMQ server
You can ping the server to check connection is established or not.
Request: NONE
Response: ServerInfo
Interface Attributes
Create Channel
PubSub CreateEventsChannel Example:
Request:
Response:
PubSub Create Events Store Channel Example:
Request:
Response:
Delete Channel
PubSub DeleteEventsChannel Example:
Request:
Response:
PubSub Delete Events Store Channel Example:
Request:
Response:
List Channels
PubSub ListEventsChannel Example:
Request:
Response: PubSubChannel[]
PubSubChannel
interface Attributes
PubSubChannel[]
PubSubChannel
interface AttributesPubSub ListEventsStoreChannel Example:
Request:
Response: PubSubChannel[]
PubSubChannel
interface Attributes
PubSubChannel[]
PubSubChannel
interface AttributesPubSub Send & Receive
PubSub SendEventMessage Example:
Request: EventMessage
Interface Attributes
EventMessage
Interface AttributesNote:- metadata
or body
or tags
any one is required
Response: NONE
NONE
PubSub SendEventStoreMessage Example:
Request: EventStoreMessage
Class Attributes
EventStoreMessage
Class AttributesNote:- metadata
or body
or tags
any one is required
Response: NONE
NONE
PubSub SubscribeEvents Example:
Request: EventsSubscription
Class Attributes
EventsSubscription
Class AttributesResponse: NONE
NONE
Callback: EventMessageReceived
class details
EventMessageReceived
class detailsPubSub SubscribeEventsStore Example:
Request: EventsStoreSubscription
Interface Attributes
EventsStoreSubscription
Interface AttributesResponse: None
None
Callback: EventStoreMessageReceived
class details
EventStoreMessageReceived
class detailsKubeMQ Queues Operations
The examples below demonstrate the usage of KubeMQ Queues client. The examples include creating, deleting, listing channels, and sending/receiving queues messages.
Construct the Queues Client
For executing Queues operation we have to create the instance of QueuesClient, its instance can be created with minimum two parameter address
(KubeMQ server address) & clientId
. With these two parameter plainText connections are established. The table below describes the Parameters available for establishing a connection.
QueuesClient Configuration
Queues Client establishing a connection example code
The example below demonstrates to construct PubSubClient with ssl and other configurations:
Ping To KubeMQ server
You can ping the server to check connection is established or not.
Request: NONE
NONE
Response: ServerInfo
Class Attributes
ServerInfo
Class AttributesCreate Channel
Queues CreateQueueChannel Example:
Request:
Response:
Delete Channel
Queues DeleteQueueChannel Example:
Request:
Response:
List Channels
Queues listQueueChannels Example:
Request:
Response: QueuesChannel[]
QueuesChannel interface Attributes
QueuesChannel[]
QueuesChannel interface AttributesSend & Receive Queue Messages
Queues SendSingleMessage Example:
Request: QueueMessage
class attributes
QueueMessage
class attributesResponse: QueueSendResult
class attributes
QueueSendResult
class attributesQueues Pulls messages from a queue. Example:
Request: QueuesPullWaitingMessagesRequest
class attributes
QueuesPullWaitingMessagesRequest
class attributesResponse: QueuesPullWaitingMessagesResponse
class attributes
QueuesPullWaitingMessagesResponse
class attributesQueues Get waiting messages from a queue Example:
Request: QueuesPullWaitngMessagesRequest
class attributes
QueuesPullWaitngMessagesRequest
class attributesResponse: QueuesPullWaitingMessagesResponse
class attributes
QueuesPullWaitingMessagesResponse
class attributesPoll Queue Messages
Receives messages from a Queue channel.
Request: QueuesPollRequest
Class Attributes
QueuesPollRequest
Class AttributesResponse: QueuesMessagesPulledResponse
Class Attributes
QueuesMessagesPulledResponse
Class AttributesResponse: QueueMessageReceived
class attributes
Here's the requested Markdown table for the QueueMessageReceived
class:
Example
This method allows you to receive messages from a specified Queue channel. You can configure the polling behavior, including the maximum number of messages to receive and the wait timeout. The response provides detailed information about the received messages and the transaction.
Message Handling Options:
Acknowledge (ack): Mark the message as processed and remove it from the queue.
Reject: Reject the message. It won't be requeued.
Requeue: Send the message back to the queue for later processing.
Choose the appropriate handling option based on your application's logic and requirements.
KubeMQ Command & Query Operations
Construct the CQClient
For executing command & query operation we have to create the instance of CQClient, its instance can be created with minimum two parameter address
(KubeMQ server address) & clientId
. With these two parameter plainText connections are established. The table below describes the Parameters available for establishing a connection.
CQClient Configuration
CQClient establishing a connection example code
The example below demonstrates to construct CQClient with ssl and other configurations:
Ping To KubeMQ server
You can ping the server to check connection is established or not.
Request: NONE
Response: ServerInfo
interface Attributes
Create Channel
Command CreateCommandsChannel Example:
Request:
Response:
Queries CreateQueriesChannel Example:
Request:
Response:
async function createQueriesChannel(channel: string) { return cqClient.createQueriesChannel(channel); }
Queries DeleteQueriesChannel Example:
Request:
Response:
List Channels
Command ListCommandsChannel Example:
Request:
Response: CQChannel[]
CQChannel
interface attributes
Queries ListQueriesChannel Example:
Request:
Response: List<CQChannel>
CQChannel
class attributes
Send & Receive Command & Query Messages
Command SubscribeToCommandsChannel Example:
Request: CommandsSubscription
Class Attributes
Response: None
Callback: CommandsReceiveMessage
interface attributes
CommandsReceiveMessage
interface attributesQueries SubscribeToQueriesChannel Example:
Request: QueriesSubscriptionRequest
Class Attributes
Response: None
Callback: QueriesReceiveMessage
interface attributes
QueriesReceiveMessage
interface attributesLast updated