Node
Last updated
Last updated
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.
Node.js (Ensure you have a recent version of Node.js installed)
TypeScript Compiler
KubeMQ server running locally or accessible over the network
The recommended way to use the SDK for Node in your project is to consume it from Node package manager.
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
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.
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
address | String | The address of the KubeMQ server. | None | Yes |
clientId | String | The client ID used for authentication. | None | Yes |
authToken | String | The authorization token for secure communication. | None | No |
tls | boolean | Indicates if TLS (Transport Layer Security) is enabled. | None | No |
tlsCertFile | String | The path to the TLS certificate file. | None | No (Yes if |
tlsKeyFile | String | The path to the TLS key file. | None | No (Yes if |
tlsCaCertFile | String | The path to the TLS CA cert file. | None | No (Yes if |
maxReceiveSize | int | The maximum size of the messages to receive (in bytes). | 104857600 (100MB) | No |
reconnectIntervalSeconds | int | The interval in seconds between reconnection attempts. | 1 | No |
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
Name | Type | Description |
---|---|---|
host | String | The host of the server. |
version | String | The version of the server. |
serverStartTime | long | The start time of the server (in seconds). |
serverUpTimeSeconds | long | The uptime of the server (in seconds). |
PubSub CreateEventsChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | Channel name which you want to create | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
PubSub Create Events Store Channel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | Channel name to which you want to create | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
PubSub DeleteEventsChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | Channel name which you want to delete | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
PubSub Delete Events Store Channel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | Channel name to which you want to delete | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
PubSub ListEventsChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
search | String | Search query to filter channels (optional) | None | No |
PubSubChannel[]
PubSubChannel
interface AttributesName | Type | Description |
---|---|---|
name | String | The name of the Pub/Sub channel. |
type | String | The type of the Pub/Sub channel. |
lastActivity | long | The timestamp of the last activity on the channel, represented in milliseconds since epoch. |
isActive | boolean | Indicates whether the channel is active or not. |
incoming | PubSubStats | The statistics related to incoming messages for this channel. |
outgoing | PubSubStats | The statistics related to outgoing messages for this channel. |
PubSub ListEventsStoreChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
search | String | Search query to filter channels (optional) | None | No |
PubSubChannel[]
PubSubChannel
interface AttributesName | Type | Description |
---|---|---|
name | String | The name of the Pub/Sub channel. |
type | String | The type of the Pub/Sub channel. |
lastActivity | long | The timestamp of the last activity on the channel, represented in milliseconds since epoch. |
isActive | boolean | Indicates whether the channel is active or not. |
incoming | PubSubStats | The statistics related to incoming messages for this channel. |
outgoing | PubSubStats | The statistics related to outgoing messages for this channel. |
PubSub SendEventMessage Example:
EventMessage
Interface AttributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
id | String | Unique identifier for the event message. | None | No |
channel | String | The channel to which the event message is sent. | None | Yes |
metadata | String | Metadata associated with the event message. | None | No |
body | byte[] | Body of the event message in bytes. | Empty byte array | No |
tags | Map<String, String> | Tags associated with the event message as key-value pairs. | Empty Map | No |
Note:- metadata
or body
or tags
any one is required
NONE
PubSub SendEventStoreMessage Example:
EventStoreMessage
Class AttributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
id | String | Unique identifier for the event message. | None | No |
channel | String | The channel to which the event message is sent. | None | Yes |
metadata | String | Metadata associated with the event message. | None | No |
body | byte[] | Body of the event message in bytes. | Empty byte array | No |
tags | Map<String, String> | Tags associated with the event message as key-value pairs. | Empty Map | No |
Note:- metadata
or body
or tags
any one is required
NONE
PubSub SubscribeEvents Example:
EventsSubscription
Class AttributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel to subscribe to. | None | Yes |
group | String | The group to subscribe with. | None | No |
onReceiveEventCallback | Consumer | Callback function to be called when an event message is received. | None | Yes |
onErrorCallback | Consumer | Callback function to be called when an error occurs. | None | No |
NONE
EventMessageReceived
class detailsName | Type | Description |
---|---|---|
id | String | The unique identifier of the message. |
fromClientId | String | The ID of the client that sent the message. |
timestamp | long | The timestamp when the message was received, in seconds. |
channel | String | The channel to which the message belongs. |
metadata | String | The metadata associated with the message. |
body | byte[] | The body of the message. |
sequence | long | The sequence number of the message. |
tags | Map<String, String> | The tags associated with the message. |
PubSub SubscribeEventsStore Example:
EventsStoreSubscription
Interface AttributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel to subscribe to. | None | Yes |
group | String | The group to subscribe with. | None | No |
onReceiveEventCallback | Consumer | Callback function to be called when an event message is received. | None | Yes |
onErrorCallback | Consumer | Callback function to be called when an error occurs. | None | No |
None
EventStoreMessageReceived
class detailsName | Type | Description |
---|---|---|
id | String | The unique identifier of the message. |
fromClientId | String | The ID of the client that sent the message. |
timestamp | long | The timestamp when the message was received, in seconds. |
channel | String | The channel to which the message belongs. |
metadata | String | The metadata associated with the message. |
body | byte[] | The body of the message. |
sequence | long | The sequence number of the message. |
tags | Map<String, String> | The tags associated with the message. |
The examples below demonstrate the usage of KubeMQ Queues client. The examples include creating, deleting, listing channels, and sending/receiving queues messages.
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.
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
address | String | The address of the KubeMQ server. | None | Yes |
clientId | String | The client ID used for authentication. | None | Yes |
authToken | String | The authorization token for secure communication. | None | No |
tls | boolean | Indicates if TLS (Transport Layer Security) is enabled. | None | No |
tlsCertFile | String | The path to the TLS certificate file. | None | No (Yes if |
tlsKeyFile | String | The path to the TLS key file. | None | No (Yes if |
tlsCaCertFile | String | The path to the TLS CA cert file. | None | No (Yes if |
maxReceiveSize | int | The maximum size of the messages to receive (in bytes). | 104857600 (100MB) | No |
reconnectIntervalSeconds | int | The interval in seconds between reconnection attempts. | 1 | No |
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.
NONE
ServerInfo
Class AttributesName | Type | Description |
---|---|---|
host | String | The host of the server. |
version | String | The version of the server. |
serverStartTime | long | The start time of the server (in seconds). |
serverUpTimeSeconds | long | The uptime of the server (in seconds). |
Queues CreateQueueChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | The name of the channel you want to create | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
Queues DeleteQueueChannel Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | The name of the channel you want to delete | None | Yes |
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
Queues listQueueChannels Example:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
searchString | String | The channel name you want to search for | None | No |
QueuesChannel[]
QueuesChannel interface AttributesName | Type | Description |
---|---|---|
name | String | The name of the queue channel. |
type | String | The type of the queue channel. |
lastActivity | long | The timestamp of the last activity in the queue channel. |
isActive | boolean | Indicates whether the queue channel is currently active. |
incoming | QueuesStats | The statistics for incoming messages in the queue channel. |
outgoing | QueuesStats | The statistics for outgoing messages in the queue channel. |
Queues SendSingleMessage Example:
QueueMessage
class attributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
id | String | The unique identifier for the message. | None | No |
channel | String | The channel of the message. | None | Yes |
metadata | String | The metadata associated with the message. | None | No |
body | byte[] | The body of the message. | new byte[0] | No |
tags | Map<String, String> | The tags associated with the message. | new HashMap<>() | No |
delayInSeconds | int | The delay in seconds before the message becomes available in the queue. | None | No |
expirationInSeconds | int | The expiration time in seconds for the message. | None | No |
attemptsBeforeDeadLetterQueue | int | The number of receive attempts allowed before the message is moved to the dead letter queue. | None | No |
deadLetterQueue | String | The dead letter queue where the message will be moved after reaching max receive attempts. | None | No |
QueueSendResult
class attributesName | Type | Description |
---|---|---|
id | String | The unique identifier of the message. |
sentAt | LocalDateTime | The timestamp when the message was sent. |
expiredAt | LocalDateTime | The timestamp when the message will expire. |
delayedTo | LocalDateTime | The timestamp when the message will be delivered. |
isError | boolean | Indicates if there was an error while sending the message. |
error | String | The error message if |
Queues Pulls messages from a queue. Example:
QueuesPullWaitingMessagesRequest
class attributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel to poll messages from. | None | Yes |
maxNumberOfMessages | int | The maximum number of messages to poll. | 1 | No |
waitTimeoutSeconds | int | The wait timeout in seconds for polling messages. | 60 | No |
QueuesPullWaitingMessagesResponse
class attributesName | Type | Description |
---|---|---|
id | String | The reference ID of the request. |
messagesReceived | number | Number of valid messages received. |
messages |
| The list of received queue messages. |
error | String | The error message, if any error occurred. |
isError | boolean | Indicates if there was an error. |
isPeek | boolean | Indicates if it is a peek or pull operation. |
messagesExpired | number | Number of expired messages from the queue. |
Queues Get waiting messages from a queue Example:
QueuesPullWaitngMessagesRequest
class attributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel to poll messages from. | None | Yes |
maxNumberOfMessages | int | The maximum number of messages to poll. | 1 | No |
waitTimeoutSeconds | int | The wait timeout in seconds for polling messages. | 60 | No |
QueuesPullWaitingMessagesResponse
class attributesName | Type | Description |
---|---|---|
id | String | The reference ID of the request. |
messagesReceived | number | Number of valid messages received. |
messages |
| The list of received queue messages. |
error | String | The error message, if any error occurred. |
isError | boolean | Indicates if there was an error. |
isPeek | boolean | Indicates if the operation is a peek or pull. |
messagesExpired | number | Number of expired messages from the queue. |
Receives messages from a Queue channel.
QueuesPollRequest
Class AttributesName | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel to poll messages from. | None | Yes |
pollMaxMessages | int | The maximum number of messages to poll. | 1 | No |
pollWaitTimeoutInSeconds | int | The wait timeout in seconds for polling messages. | 60 | No |
autoAckMessages | boolean | Indicates if messages should be auto-acknowledged. | false | No |
visibilitySeconds | int | Add a visibility timeout feature for messages. | 0 | No |
QueuesMessagesPulledResponse
Class AttributesName | Type | Description |
---|---|---|
id | String | The reference ID of the request. |
messages | QueueMessageReceived[] | The list of received queue messages. |
messagesReceived | number | Number of valid messages received. |
messagesExpired | number | Number of messages expired. |
isPeek | boolean | Indicates if the operation is a peek or pull. |
error | String | The error message, if any error occurred. |
isError | boolean | Indicates if there was an error. |
visibilitySeconds | int | The visibility timeout for the message in seconds. |
isAutoAcked | boolean | Indicates whether the message was auto-acknowledged. |
Response: QueueMessageReceived
class attributes
Here's the requested Markdown table for the QueueMessageReceived
class:
Name | Type | Description |
---|---|---|
id | String | The unique identifier for the message. |
channel | String | The channel from which the message was received. |
metadata | String | Metadata associated with the message. |
body | byte[] | The body of the message in byte array format. |
fromClientId | String | The ID of the client that sent the message. |
tags | Map | Key-value pairs representing tags for the message. |
timestamp | Instant | The timestamp when the message was created. |
sequence | long | The sequence number of the message. |
receiveCount | int | The number of times the message has been received. |
isReRouted | boolean | Indicates whether the message was rerouted. |
reRouteFromQueue | String | The name of the queue from which the message was rerouted. |
expiredAt | Instant | The expiration time of the message, if applicable. |
delayedTo | Instant | The time the message is delayed until, if applicable. |
transactionId | String | The transaction ID associated with the message. |
isTransactionCompleted | boolean | Indicates whether the transaction for the message is completed. |
responseHandler | StreamObserver | The response handler for processing downstream requests. |
receiverClientId | String | The ID of the client receiving the message. |
visibilitySeconds | int | The visibility timeout for the message in seconds. |
isAutoAcked | boolean | Indicates whether the message was auto-acknowledged. |
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.
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.
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.
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
address | String | The address of the KubeMQ server. | None | Yes |
clientId | String | The client ID used for authentication. | None | Yes |
authToken | String | The authorization token for secure communication. | None | No |
tls | boolean | Indicates if TLS (Transport Layer Security) is enabled. | None | No |
tlsCertFile | String | The path to the TLS certificate file. | None | No (Yes if |
tlsKeyFile | String | The path to the TLS key file. | None | No (Yes if |
tlsCaCertFile | String | The path to the TLS CA cert file. | None | No (Yes if |
maxReceiveSize | int | The maximum size of the messages to receive (in bytes). | 104857600 (100MB) | No |
reconnectIntervalSeconds | int | The interval in seconds between reconnection attempts. | 1 | No |
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
Name | Type | Description |
---|---|---|
host | String | The host of the server. |
version | String | The version of the server. |
serverStartTime | long | The start time of the server (in seconds). |
serverUpTimeSeconds | long | The uptime of the server (in seconds). |
Command CreateCommandsChannel Example:
Request:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | Channel name which you want to create | None | Yes |
Response:
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
Queries CreateQueriesChannel Example:
Request:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | The name of the channel to create. | None | Yes |
Response:
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
```typescript |
async function createQueriesChannel(channel: string) { return cqClient.createQueriesChannel(channel); }
Queries DeleteQueriesChannel Example:
Request:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channelName | String | The name of the channel to delete | None | Yes |
Response:
Name | Type | Description |
---|---|---|
void | Promise | Doesn't return a value upon completion |
Command ListCommandsChannel Example:
Request:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
searchString | String | The name of the channel to search for. | None | No |
Response: CQChannel[]
CQChannel
interface attributes
Name | Type | Description |
---|---|---|
name | String | The name of the channel. |
type | String | The type of the channel. |
lastActivity | long | The timestamp of the last activity on the channel. |
isActive | boolean | Indicates whether the channel is currently active. |
incoming | CQStats | Statistics about incoming messages to the channel. |
outgoing | CQStats | Statistics about outgoing messages from the channel. |
Queries ListQueriesChannel Example:
Request:
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
searchString | String | Channel name which you want to search | None | No |
Response: List<CQChannel>
CQChannel
class attributes
Name | Type | Description |
---|---|---|
name | String | The name of the channel. |
type | String | The type of the channel. |
lastActivity | long | The timestamp of the last activity on the channel. |
isActive | boolean | Indicates whether the channel is currently active. |
incoming | CQStats | Statistics about incoming messages to the channel. |
outgoing | CQStats | Statistics about outgoing messages from the channel. |
Command SubscribeToCommandsChannel Example:
Request: CommandsSubscription
Class Attributes
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel for the subscription. | None | Yes |
group | String | The group associated with the subscription. | None | No |
onReceiveCommandCallback |
| Callback function for receiving commands. | None | Yes |
Response: None
CommandsReceiveMessage
interface attributesName | Type | Description |
---|---|---|
commandReceived |
| The command message that was received. |
clientId | String | The ID of the client that sent the command. |
requestId | String | The ID of the request. |
isExecuted | boolean | Indicates whether the command was executed. |
timestamp | LocalDateTime | The timestamp of the response. |
error | String | The error message if an error occurred. |
Queries SubscribeToQueriesChannel Example:
Request: QueriesSubscriptionRequest
Class Attributes
Name | Type | Description | Default Value | Mandatory |
---|---|---|---|---|
channel | String | The channel for the subscription. | None | Yes |
group | String | The group associated with the subscription. | None | No |
onReceiveQueriesCallback |
| Callback function for receiving queries. | None | Yes |
Response: None
QueriesReceiveMessage
interface attributesName | Type | Description |
---|---|---|
id | String | The ID of the request. |
channel | String | Channel name from which the message was received. |
metadata | String | Metadata of the message. |
body | Uint8Array | The body of the response. |
tags | Map<String, String> | Tags associated with the query message. |
replyChannel | String | The reply channel for this message. |