Tutorial

Sending and receiving messages through RoboMQ is as easy as 1-2-3 …

1

Connect to RoboMQ

Client connects to RoboMQ with hostname and port, and authenticates using virtual host (vhost), username and password.

#Click here to view the full documentation

client = Stomp(StompConfig(“tcp://” + “hostname” + “:61613”, “username”, “password”))
client.connect(host = “yourvhost”)

//Click here to view the full documentation

var client = Stomp.overTCP(“hostname”, 61613);
client.connect(“username”, “password”, success_callback, fail_callback, “yourvhost”);

//Click here to view the full documentation

$client = new Stomp(“tcp://”.”hostname”.”:61613″, “username”, “password”, array(“host”=>”yourvhost”));

//Click here to view the full documentation

client = new Client(“hostname”, 61613, “username”, “password”, “yourvhost”);

//Click here to view the full documentation

struct ctx client;
stomp_session_t *session;
session = stomp_session_new(&client);
struct stomp_hdr conn_hdrs[] = {{“login”, “username”},
{“passcode”, “password”},
{“vhost”, “yourvhost”}};
stomp_connect(session, “hostname”, “61613”, sizeof(conn_hdrs)/sizeof(struct stomp_hdr), conn_hdrs);

2

Subscribe

Receiver subscribes to a message destination and processes received message. In this example, it prints the message body.

#Click here to view the full documentation

subscription = client.subscribe(“/queue/test”, {“ack”: “auto”})
while True:
frame = client.receiveFrame()
print frame.body

//Click here to view the full documentation

client.subscribe(“/queue/test”, function(message) {
console.log(message.body);
},
{ack: “auto”});

//Click here to view the full documentation

$client->subscribe(“/queue/test”, array(“ack”=>”auto”));
while (true) {
if ($frame = $client->readFrame()) {
echo $frame->body.PHP_EOL;
}
}

//Click here to view the full documentation

client.subscribe(“/queue/test”, new Listener()) {
public void message(Map headers, String body) {
System.out.println(body);
}
}

//Click here to view the full documentation

static void _message(stomp_session_t *s, void *ctx, void *session_ctx) {
struct stomp_ctx_message *e = ctx;
fprintf(stdout, “%s\n”, (const char *)e->body);
}
stomp_callback_set(session, SCB_MESSAGE, _message);
struct stomp_hdr sub_hdrs[] = {{“destination”, “/queue/test”},
{“ack”, “auto”},};
stomp_subscribe(session, sizeof(sub_hdrs)/sizeof(struct stomp_hdr), sub_hdrs);
stomp_run(session);

3

Send message

Sender sends the message with optional headers. Subscribed receivers will receive the message.

#Click here to view the full documentation client.send(“/queue/test”, message, {“content-type”: “text/plain”})

//Click here to view the full documentation

client.send(“/queue/test”, {“content-type”: “text/plain”}, message);

//Click here to view the full documentation

$client->send(“/queue/test”, $message, array(“content-type”=>”text/plain”));

//Click here to view the full documentation

HashMap headers = new HashMap();
headers.put(“content-type”, “text/plain”);
client.send(destination, message, headers);

//Click here to view the full documentation

struct stomp_hdr send_hdrs[] = {{“destination”, “/queue/test”},};
{“content-type”, “text/plain”},
stomp_send(session, sizeof(send_hdrs)/sizeof(struct stomp_hdr), send_hdrs, message, sizeof(message));

4

Try it yourself!

Connect the receiver, the sender and subscribe. Try typing a message of your own and voila, you got it!!

Sender

Message


Receiver


Received Messages:


5

Sign up for the free trial

This tutorial introduces a basic use case. RoboMQ covers a wide variety of messaging scenarios and is bundled with a number of components like messaging dashboard, real time analytics, data-driven alerts, and connectors to major enterprise systems and device platforms. Check out the full documentation for more details.

The form below gets you a free trial account to play with RoboMQ!

Start building your applications today !!!

  • Full feature cluster with shared tenancy
  • No Credit Card needed
  • Maximum 5 concurrent connections for free trial

Try it yourself !!! All you need to do is to provide some basic information and we will be in touch with you…