C# (.NET)
The KubeMQ SDK for C# enables C# developers to seamlessly communicate with the KubeMQ server, implementing various communication patterns such as Events, EventStore, Commands, Queries, and Queues.
Sources
SDK
Examples
Prerequisites
.Net Core 5.0 or later
.Net Framework 4.6.1 or later
.Net Standard 2.0 or later
KubeMQ server running locally or accessible over the network
Installation
The KubeMQ SDK for C# is available as a NuGet package. You can install it using the following command:
Running Examples
The examples are standalone projects that showcase the usage of the SDK. To run the examples, ensure you have a running instance of KubeMQ.
SDK Overview
The SDK implements all communication patterns available through the KubeMQ server:
PubSub
Events
EventStore
Commands & Queries (CQ)
Commands
Queries
Queues
KubeMQ Client Configuration
All KubeMQ clients (PubSubClient, QueuesClient, and CQClient) share the same configuration parameters. To create any client instance, you need to use the respective builder with at least two mandatory parameters: address (KubeMQ server address) and clientId.
Configuration Parameters
The table below describes all available configuration parameters:
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
TlsConfig
Enable or disable TLS for secure communication.
false
No
MaxSendSize
int
The maximum size of the messages to send (in bytes).
104857600 (100MB)
No
MaxReceiveSize
int
The maximum size of the messages to receive (in bytes).
104857600 (100MB)
No
ReconnectIntervalSeconds
int
The interval in seconds between reconnection attempts.
5
No
TLS Configuration
Enabled
bool
Enable or disable TLS for secure communication.
false
No
CertFile
string
The path to the TLS certificate file.
None
No (Yes if tls is true)
KeyFile
string
The path to the TLS key file.
None
No (Yes if tls is true)
CaFile
string
The path to the TLS CA file.
None
No (Yes if tls is true)
Example Usage
Here's an example of how to create a client instance (using PubSubClient as an example):
Result Object
In many cases, the SDK methods return a Result object. The Result object is a simple class that contains two attributes: IsSuccess and ErrorMessage. It is used to indicate the success or failure of an operation and to provide an error message in case of failure.
PubSub Events Operations
Create Channel
Create a new Events channel.
Request Parameters
channelName
string
Name of the channel you want to create
None
Yes
Response
Return Result object
Example
Delete Channel
Delete an existing Events channel.
Request Parameters
channelName
string
Name of the channel you want to delete
None
Yes
Response
Return Result object
Example
List Channels
Retrieve a list of Events channels.
Request Parameters
searchQuery
string
Search query to filter channels (optional)
None
No
Response
Returns a ListPubSubAsyncResult where each PubSubChannel has the following attributes:
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
PubSubChannel
The statistics related to incoming messages for this channel.
Outgoing
PubSubChannel
The statistics related to outgoing messages for this channel.
Example
Send & Subscribe Event
Send and subscribe to event messages.
Send Request: Event
EventId
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
Response
Return Result object
Subscribe Request: EventsSubscription
EventsSubscriptionChannel
String
The channel to subscribe to.
None
Yes
Group
String
The group to subscribe with.
None
No
ReceiveEventHandler
delegate(EventMessageReceived)
Callback function to be called when an event message is received.
None
Yes
ErrorHandler
delegate(Exception)
Callback function to be called when an error occurs.
None
No
Callback: EventMessageReceived Class Detail
EventMessageReceived Class DetailId
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.
Tags
Map<string, string>
The tags associated with the message.
Example
PubSub EventsStore Operations
Create Channel
Create a new EventsStore channel.
Request Parameters
channelName
string
Name of the channel you want to create
None
Yes
Response
Return Result object
Example
Delete Channel
Delete an existing EventsStore channel.
Request Parameters
channelName
string
Name of the channel you want to delete
None
Yes
Response
Return Result object
Example
List Channels
Retrieve a list of EventsStore channels.
Request Parameters
searchQuery
string
Search query to filter channels (optional)
None
No
Response
Returns a ListPubSubAsyncResult where each PubSubChannel has the following attributes:
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
PubSubChannel
The statistics related to incoming messages for this channel.
Outgoing
PubSubChannel
The statistics related to outgoing messages for this channel.
Example
Send & Subscribe EventStore
Send and subscribe to event messages.
Request: EventStore Class Attributes
EventStore Class AttributesId
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
Subscribe To EventsStore Messages
Subscribes to receive messages from an EventsStore channel.
Request: EventsStoreSubscription Class Attributes
EventsStoreSubscription Class AttributesChannel
string
The channel to subscribe to.
None
Yes
Group
string
The group to subscribe with.
None
No
ReceiveEventHandler
delegate(EventStore)
Callback function to be called when an event message is received.
None
Yes
OnErrorCallback
delegate(Exception)
Callback function to be called when an error occurs.
None
No
StartAt
StartAtType
Type of EventsStore subscription (e.g., StartAtTime, StartAtSequence)
None
Yes
StartAtTimeValue
long
Start time for EventsStore subscription (if applicable)
None
Conditional
StartAtSequenceValue
long
Start sequence for EventsStore subscription (if applicable)
None
Conditional
StartAtType Options
Undefined
0
Default value, should be explicitly set to a valid type before use
StartNewOnly
1
Start storing events from the point when the subscription is made
StartFromFirst
2
Start storing events from the first event available
StartFromLast
3
Start storing events from the last event available
StartAtSequence
4
Start storing events from a specific sequence number
StartAtTime
5
Start storing events from a specific point in time
StartAtTimeDelta
6
Start storing events from a specific time delta in seconds
Example
Commands & Queries – Commands Operations
Create Channel
Create a new Command channel.
Request Parameters
channelName
string
Name of the channel you want to create
None
Yes
Response
Return Result object
Example
Delete Channel
Delete an existing Command channel.
Request Parameters
channelName
string
Name of the channel you want to delete
None
Yes
Response
Return Result object
Example
List Channels
Retrieve a list of Command channels.
Request Parameters
searchstring
string
Search query to filter channels (optional)
None
No
Response
Returns a ListCqAsyncResult where each CQChannel has the following attributes:
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
CQChannel
Statistics about incoming messages to the channel
Outgoing
CQChannel
Statistics about outgoing messages from the channel
Example
Send Receive Response Command
Send a command request to a Command channel.
Request: Command Class Attributes
Command Class AttributesId
string
The ID of the command message.
None
Yes
Channel
string
The channel through which the command message will be sent.
None
Yes
Metadata
string
Additional metadata associated with the command message.
None
No
Body
byte[]
The body of the command message as bytes.
Empty byte array
No
Tags
Map<string, string>
A dictionary of key-value pairs representing tags associated with the command message.
Empty Map
No
TimeoutInSeconds
int
The maximum time in seconds for waiting to response.
None
Yes
Response: CommandResponse Class Attributes
CommandResponse Class AttributesCommandReceived
CommandMessageReceived
The command message received in the response.
ClientId
string
The client ID associated with the command response.
RequestId
string
The unique request ID of the command response.
IsExecuted
boolean
Indicates if the command has been executed.
Timestamp
Timestamp
The timestamp when the command response was created.
Error
string
The error message if there was an error.
Subscribe To Commands
Subscribes to receive command messages from a Command channel.
Request: CommandsSubscription Class Attributes
CommandsSubscription Class AttributesChannel
string
The channel for the subscription.
None
Yes
Group
string
The group associated with the subscription.
None
No
ReceivedCommandHandler
delegate(CommandMessageReceived)
Callback function for receiving commands.
None
Yes
ErrorHandler
delegate(Exception)
Callback function for error handling.
None
No
Example
Commands & Queries – Queries Operations
Create Channel
Create a new Query channel.
Request Parameters
channelName
string
Name of the channel you want to create
None
Yes
Response
Return Result object
Example
Delete Channel
Delete an existing Query channel.
Request Parameters
channelName
string
Name of the channel you want to delete
None
Yes
Response
Return Result object
Example
List Channels
Retrieve a list of Query channels.
Request Parameters
searchstring
string
Search query to filter channels (optional)
None
No
Response
Returns a ListCqAsyncResult where each CQChannel has the following attributes:
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
CQChannel
Statistics about incoming messages to the channel
Outgoing
CQChannel
Statistics about outgoing messages from the channel
Example
Send Receive Response Query
Send a query request to a Query channel.
Request: Query Class Attributes
Query Class AttributesId
string
The ID of the command message.
None
Yes
Channel
string
The channel through which the command message will be sent.
None
Yes
Metadata
string
Additional metadata associated with the command message.
None
No
Body
byte[]
The body of the command message as bytes.
Empty byte array
No
Tags
Map<string, string>
A dictionary of key-value pairs representing tags associated with the command message.
Empty Map
No
TimeoutInSeconds
int
The maximum time in seconds for waiting to response.
None
Yes
Response: QueryResponse Class Attributes
QueryResponse Class AttributesCommandReceived
CommandMessageReceived
The command message received in the response.
ClientId
string
The client ID associated with the command response.
RequestId
string
The unique request ID of the command response.
IsExecuted
boolean
Indicates if the command has been executed.
Timestamp
Timestamp
The timestamp when the command response was created.
Error
string
The error message if there was an error.
Metadata
string
Additional metadata associated with the response.
Body
byte[]
The body of the query response as bytes.
Subscribe To Commands
Subscribes to receive query messages from a Query channel.
Request: QueriesSubscription Class Attributes
QueriesSubscription Class AttributesChannel
string
The channel for the subscription.
None
Yes
Group
string
The group associated with the subscription.
None
No
ReceivedQueryHandler
delegate(QueryMessageReceived)
Callback function for receiving queries.
None
Yes
ErrorHandler
delegate(Exception)
Callback function for error handling.
None
No
Example
Queues Operations
Create Channel
Create a new Queue channel.
Request Parameters
channelName
string
Name of the channel you want to create
None
Yes
Response
Return Result object
Example
Delete Channel
Delete an existing Queue channel.
Request Parameters
channelName
string
Name of the channel you want to delete
None
Yes
Response
Return Result object
Example
List Channels
Retrieve a list of Queue channels.
Request Parameters
searchstring
string
Search query to filter channels (optional)
None
No
Response
Returns a ListQueuesAsyncResult where each QueuesChannel has the following attributes:
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
PubSubChannel
The statistics related to incoming messages for this channel.
Outgoing
PubSubChannel
The statistics related to outgoing messages for this channel.
Example
Send / Receive Queue Messages
Send and receive messages from a Queue channel.
Send Request: QueueMessage
QueueMessageId
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
Policy
QueueMessagePolicy
The policy associated with the message.
None
No
Policy Options
DelaySeconds
int
The delay in seconds before the message becomes available in the queue.
None
No
ExpirationSeconds
int
The expiration time in seconds for the message.
None
No
MaxReceiveCount
int
The number of receive attempts allowed for the message before it is moved to the dead letter queue.
None
No
MaxReceiveQueue
String
The dead letter queue where the message will be moved after reaching the maximum receive attempts.
None
No
Send Queue Message
Send a message to a Queue channel.
Request: QueueMessage Class Attributes
QueueMessage Class Attributesid
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 for the message before it is moved to the dead letter queue.
None
No
deadLetterQueue
string
The dead letter queue where the message will be moved after reaching the maximum receive attempts.
None
No
Receive Request: PollRequest
PollRequestQueue
String
The channel to poll messages from.
None
Yes
MaxItems
int
The maximum number of messages to poll.
1
No
WaitTimeout
int
The wait timeout in seconds for polling messages.
60
No
AutoAck
boolean
Indicates if messages should be auto-acknowledged.
false
No
VisibilitySeconds
int
Add a visibility timeout feature for messages.
0
No
Response: PollResponse
PollResponseMessages
List
The list of received queue messages.
Example #1
Example #2
Example #3
Example #4
Example #5
Last updated
Was this helpful?