Skip to content

Processing messages

ts
function GetMessages(): QueueMsg;

type QueueMsg = {
  receivedAt: Date; // JavaScript date object
  queue:      string;
  message:    string;
}

It is recommended, inside the loop in which GetMessages() is called iteratively, to also monitor whether a “halt” request has been issued and the script must terminate.

Example

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