Getting Started Guide

Follow these 3 simple steps to send your first Queue message using KubeMQ!

1

Deploy KubeMQ

To start using KubeMQ message queue, we first need to run a KubeMQ docker container either locally or on remote node.

Every deployment method requires an KubeMQ token. Please register to obtain your KubeMQ token.

docker run -d -p 8080:8080 -p 50000:50000 -p 9090:9090 -v kubemq-vol:/store -e KUBEMQ_TOKEN= "Your KubeMQ Token Here" kubemq/kubemq

kubectl apply -f https://get.kubemq.io/deploy?token="YOUR_KUBEMQ_TOKEN"

$ helm repo add kubemq-charts https://kubemq-io.github.io/charts
$ helm install --name kubemq-cluster --set token="Your KubeMQ Token Here" kubemq-charts/kubemq

version: '3.7'
services:
  kubemq:
    image: kubemq/kubemq:latest
    container_name: kubemq
    ports:
      - "8080:8080"
      - "9090:9090"
      - "50000:50000"
    environment:
      - KUBEMQ_HOST=kubemq
      - KUBEMQ_TOKEN="Your KubeMQ Token Here"
    networks:
      - backend
    volumes:
      - kubemq_vol:/store
networks:
  backend:
volumes:
  kubemq_vol:

2

Send a Message

The producer can send a message to the “hello-world-queue" channel with one of the following methods.

kubetools queue send "hello-world-queue" "this is a queue message"

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);
            }
           
        }
    }
}

Code snippet will available soon

The following Go code snippet is using KubeMQ’s Go SDK with gRPC interface:

package main

import (
  "context"
  "github.com/kubemq-io/kubemq-go"
  "log"
  "time"
)

func main() {
  ctx, cancel := context.WithCancel(context.Background())
  defer cancel()
  client, err := kubemq.NewClient(ctx,
    kubemq.WithAddress("localhost", 50000),
    kubemq.WithClientId("test-command-client-id"),
    kubemq.WithTransportType(kubemq.TransportTypeGRPC))
  if err != nil {
    log.Fatal(err)
  }
  defer client.Close()
  channel := "hello-world-queue"

  sendResult, err := client.NewQueueMessage().
    SetChannel(channel).
    SetBody([]byte("some-simple_queue-queue-message")).
    Send(ctx)
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("Send to Queue Result: MessageID:%s,Sent At: %sn", sendResult.MessageID, time.Unix(0, sendResult.SentAt).String())
}

Code snippet will available soon

For all other languages, check out the SDKs that KubeMQ supports on our documentation page

3

Receive a Message

After you have send a message to a queue, you can request the message from a queue.

kubetools queue receive "hello-world-queue"

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);
            }
        }
    }
}

Code snippet will available soon

The following Go code snippet is using KubeMQ’s Go SDK with gRPC interface:

package main

import (
  "context"
  "github.com/kubemq-io/kubemq-go"
  "log"
  "time"
)

func main() {
  ctx, cancel := context.WithCancel(context.Background())
  defer cancel()
  client, err := kubemq.NewClient(ctx,
    kubemq.WithAddress("localhost", 50000),
    kubemq.WithClientId("test-command-client-id"),
    kubemq.WithTransportType(kubemq.TransportTypeGRPC))
  if err != nil {
    log.Fatal(err)
  }
  defer client.Close()
  channel := "hello-world-queue"

  receiveResult, err := client.NewReceiveQueueMessagesRequest().
    SetChannel(channel).
    SetMaxNumberOfMessages(1).
    SetWaitTimeSeconds(5).
    Send(ctx)
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("Received %d Messages:n", receiveResult.MessagesReceived)
  for _, msg := range receiveResult.Messages {
    log.Printf("MessageID: %s, Body: %s", msg.Id, string(msg.Body))
  }
}

Code snippet will available soon

For all other languages, check out the SDKs that KubeMQ supports on our documentation page

4

Congratulations!

You’ve sent your first Event message using KubeMQ!

Next steps:

Check out our SDK reference and code examples .NET, GO, Java, Python and REST.

Read our documatation

Send a Message