Queues
Get Started with Queues in KubeMQ
Connect Your KubeMQ Cluster
To be able to communicate with KubeMQ interface ports running in Kubernetes cluster, a Port Forward of KubeMQ's ports is needed.
kubemqctl has a handy command that will do it for you:
kubemqctl set cluster proxySend a Queue Message
The producer can send a message to the "hello-world-queue" channel with one of the following methods.
Run the following kubemqctl command:
kubemqctl queues send "hello-world-queue" "this is a queue message"A result message will be shown with an indication of the sending time of the message.
The following cURL command is using KubeMQ's REST interface:
curl -H 'Content-Type: application/json' \
--request POST "http://localhost:9090/queue/send" \
--data '{"Id":"","ClientId":"send-message-client-id","Channel":"hello-world-queue","Metadata":"","Body":"QmF0Y2ggTWVzc2FnZSAw","Tags":{"message":"0"}}'The following .NET code snippet is using KubeMQ's .NET SDK with gRPC interface:
using System;
namespace Queue_Send_a_Message
{
class Program
{
static void Main(string[] args)
{
var QueueName = "hello-world-queue";
var ClientID = "test-queue-client-id2";
var KubeMQServerAddress = "localhost:50000";
KubeMQ.SDK.csharp.Queue.Queue queue = null;
try
{
queue = new KubeMQ.SDK.csharp.Queue.Queue(QueueName, ClientID, KubeMQServerAddress);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
var res = queue.SendQueueMessage(new KubeMQ.SDK.csharp.Queue.Message
{
Body = KubeMQ.SDK.csharp.Tools.Converter.ToByteArray("some-simple_queue-queue-message"),
Metadata = "emptyMeta"
});
if (res.IsError)
{
Console.WriteLine($"message enqueue error, error:{res.Error}");
}
else
{
Console.WriteLine($"message sent at, {res.SentAt}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}When executed, a stream of events messages will be shown in the console.
The following Java code snippet is using KubeMQ's Java SDK with gRPC interface:
When executed, a stream of events messages will be shown in the console.
The following Go code snippet is using KubeMQ's Go SDK with gRPC interface:
When executed, a stream of events messages will be shown in the console.
The following Python code snippet is using KubeMQ's Python SDK with gRPC interface:
When executed, a stream of events messages will be shown in the console.
The following JS code snippet is using KubeMQ's NodeJS SDK with gRPC interface:
The following PHP code snippet is using KubeMQ's REST interface:
The following Ruby code snippet is using KubeMQ's REST interface:
The following jQuery code snippet is using KubeMQ's REST interface:
Receive a Queue Message
After you have sent a message to a queue, you can request the message from a queue.
Run the following kubemqctl command:
kubemqctl queues receive "hello-world-queue"The following cURL command is using KubeMQ's REST interface:
curl --location --request POST "http://localhost:9090/queue/receive" \
--header "Content-Type: application/json" \
--data '{"RequestID":"some-request-id","ClientID":"receive-message-client-id","Channel":"hello-world-queue","MaxNumberOfMessages":1,"WaitTimeSeconds":5}'The following c# code snippet is using KubeMQ's Java SDK with gRPC interface:
using System;
namespace Queue_Receive_a_Message
{
class Program
{
static void Main(string[] args)
{
var QueueName = "hello-world-queue";
var ClientID = "test-queue-client-id";
var KubeMQServerAddress = "localhost:50000";
KubeMQ.SDK.csharp.Queue.Queue queue = null;
try
{
queue = new KubeMQ.SDK.csharp.Queue.Queue(QueueName, ClientID, KubeMQServerAddress);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
var msg = queue.ReceiveQueueMessages();
if (msg.IsError)
{
Console.WriteLine($"message dequeue error, error:{msg.Error}");
return;
}
Console.WriteLine($"Received {msg.MessagesReceived} Messages:");
foreach (var item in msg.Messages)
{
Console.WriteLine($"MessageID: {item.MessageID}, Body:{KubeMQ.SDK.csharp.Tools.Converter.FromByteArray(item.Body)}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}The following Java code snippet is using KubeMQ's Java SDK with gRPC interface:
The following Go code snippet is using KubeMQ's Go SDK with gRPC interface:
The following Python code snippet is using KubeMQ's Python SDK with gRPC interface:
The following JS code snippet is using KubeMQ's NodeJS SDK with gRPC interface:
The following PHP code snippet is using KubeMQ's REST interface:
The following Ruby code snippet is using KubeMQ's REST interface:
The following jQuery code snippet is using KubeMQ's REST interface:
Last updated
Was this helpful?