Skip to content

AMQP message queue protocol

CAUTION

There are two milestone versions of the AMQP message queuing protocol, and they are totally incompatible with each other:

AMQP v0.9.1 used by RabbitMQ, StormMQ, Apache Qpid, JORAM, and others, and

AMQP v1.0 used by Apache ActiveMQ, Azure Event Hubs, Azure Service Bus, Solace, and others.

SyncJS features dedicated objects to handle each one of the above protocols, so - please - make sure you determine the exact protocol your provider uses, and choose the proper object, otherwise you won’t be able to connect to your message queue service.

Here’s the AMQP client object constructors:

ts
AmqpClient091() // for AMQP v0.9.1
AmqpClient10()  // for AMQP v1.0

Both client objects supports both the plain-unencrypted amqp:// and the secure amqps:// protocols.

Only the names of the object creator functions differ. All methods of both objects are absolutely identical. Here’s two examples, so you can see that the only line that differs is the line to create the correct client object, in every other way these 2 scripts are absolutely identical:

Script that connects to an AMQP v0.9.1 (ex: RabbitMQ) and monitors the “myqueue” queue:

ts
{
  ConsoleFeedback = true;
  var cli = new AmqpClient091();
  cli.URL = 'amqp://localhost:5672';
  cli.User = 'guest';
  cli.Pass = 'guest';
  if (cli.Connect()) {
    cli.MonitorQueue('myqueue');
    while (true) {
      Sleep(1000);
      if (HaltSignalReceived()) {
        break;
      }
      var msgs = cli.GetMessages();
      if (msgs.length > 0) {
        Log(JSON.stringify(msgs));
      }
    }
    cli.Close();
  }
  cli = null;
}

Script that connects to an AMQP v1.0 (ex: ActiveMQ) and monitors the “myqueue” queue:

ts
{
  ConsoleFeedback = true;
  var cli = new AmqpClient10();
  cli.URL = 'amqp://localhost:5672';
  cli.User = 'guest';
  cli.Pass = 'guest';
  if (cli.Connect()) {
    cli.MonitorQueue('myqueue');
    while (true) {
      Sleep(1000);
      if (HaltSignalReceived()) {
        break;
      }
      var msgs = cli.GetMessages();
      if (msgs.length > 0) {
        Log(JSON.stringify(msgs));
      }
    }
    cli.Close();
  }
  cli = null;
}