Skip to content

AMQP message queue protocol

WARNING

AMQP support in Syncplify Server! should be used with extreme caution. Unlike AFT!, scripts in Syncplify Server! are never meant to run forever or unattended—they always execute in response to events within a client session. If you use AMQP monitoring in a script, it will lock up the client session until the monitoring loop is broken. With very rare exceptions, AMQP is not practical or recommended in Syncplify Server! scripts.

CAUTION

There are two major, incompatible versions of the AMQP message queuing protocol:

  • AMQP v0.9.1 (used by RabbitMQ, StormMQ, Apache Qpid, JORAM, and others)
  • AMQP v1.0 (used by Apache ActiveMQ, Azure Event Hubs, Azure Service Bus, Solace, and others)

SyncJS provides dedicated client objects for each protocol version. Be sure to determine which protocol your provider uses and choose the correct object. If you select the wrong version, you will not be able to connect to your message queue service.

AMQP Client Object Constructors

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

Both client objects support both plain (amqp://) and secure (amqps://) protocols.

NOTE

The only difference between the two client objects is the constructor function name. All methods and usage are otherwise identical.

Below are two example scripts. The only difference is the client object constructor; all other code is the same.


Example: Connect to AMQP v0.9.1 (e.g., RabbitMQ) and monitor a 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;

Example: Connect to AMQP v1.0 (e.g., ActiveMQ) and monitor a 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;