RabbitMQ Module

Răzvan Crainea

   OpenSIPS Project

Edited by

Răzvan Crainea

   Copyright © 2017 www.opensips-solutions.com
     __________________________________________________________

   Table of Contents

   1. Admin Guide

        1.1. Overview
        1.2. Dependencies

              1.2.1. OpenSIPS Modules
              1.2.2. External Libraries or Applications

        1.3. Exported Parameters

              1.3.1. server_id (string)

        1.4. Exported Functions

              1.4.1. rabbitmq_publish(server_id, routing_key,
                      message [, [content_type [, headers,
                      headers_vals]]])

   List of Examples

   1.1. Set server_id parameter
   1.2. rabbitmq_publish() function usage

Chapter 1. Admin Guide

1.1. Overview

   RabbitMQ (http://www.rabbitmq.com/) is an open source messaging
   server. It's purpose is to manage received messages in queues,
   taking advantage of the flexible AMQP protocol.

   Using this module you can send AMQP messages to a RabbitMQ
   server. Messages can be easily customized according to the AMQP
   specifications, as well the RabbitMQ extensions.

1.2. Dependencies

1.2.1. OpenSIPS Modules

   None.

1.2.2. External Libraries or Applications

   The following libraries or applications must be installed
   before running OpenSIPS with this module loaded:
     * librabbitmq-dev

1.3. Exported Parameters

1.3.1. server_id (string)

   Specify configuration for a RabbitMQ server. It contains a set
   of parameters used to customize the connection to the server,
   as well as to the messages sent. The format of the parameter is
   [id_name] param1=value1; param2=value2;. The uri parameter is
   mandatory.

   This parameter can be set multiple times, for each RabbitMQ
   server.

   The following parameters can be used:
     * uri - Mandatory parameter - a full amqp URI as described
       here. Missing fields in the URI will receive default
       values, such as: user: guest, password: guest, host:
       localhost, vhost: /, port: 5672. SSL connections are
       currently not available: amqps URIs will be declined.
     * frames - the maximum size of an AMQP frame. Optional
       parameter, default size is 131072.
     * retries - the number of retries in case a connection is
       down. Optional parameter, default is disabled (do not
       retry).
     * exchange - exchange used to send AMQP messages to. Optional
       parameter, default is "".
     * heartbeat - interval in seconds used to send heartbeat
       messages. Optional parameter, default is disabled.
     * immediate - indicate to the broker that the message MUST be
       delivered to a consumer immediately. Optional parameter,
       default is not immediate.
     * mandatory - indicate to the broker that the message MUST be
       routed to a queue. Optional parameter, default is not
       mandatory.
     * non-persistent - indicates that the message should not be
       persistent in case the RabbitMQ server restarts. Optional
       parameter, default is persistent.

   Example 1.1. Set server_id parameter
...
# connection to a RabbitMQ server on localhost, default port
modparam("rabbitmq", "server_id","[ID1] uri = amqp://127.0.0.1")
...
# connection with a 5 seconds interval for heartbeat messages
modparam("rabbitmq", "server_id","[ID2] uri = amqp://127.0.0.1;
heartbeat = 5")
...

1.4. Exported Functions

1.4.1.  rabbitmq_publish(server_id, routing_key, message [,
[content_type [, headers, headers_vals]]])

   Sends a publish message to a RabbitMQ server.

   This function also allows you to attach AMQP headers and values
   in the AMQP message. This is done by specifying a set of
   headers names (in the headers parameter) and the corresponding
   values (in the headers_vals parameter). The number of AVP
   values in the headers must be the same as the one in the
   headers_vals.

   This function can be used from any route.

   The function has the following parameters:
     * server_id - the id of the RabbitMQ server. Must be one of
       the parameters defined in the server_id modparam.
     * routing_key - routing key used to deliver the AMQP message.
     * message - the body of the message.
     * content_type (optional) - content type of the message sent.
       By default it is none.
     * headers (optional) - an AVP containing the names of the
       headers within the AMQP message. If set, headers_vals
       parameter must also be specified.
     * headers_vals (optional) - an AVP containing the
       corresponding values of the AMQP headers. If set, headers
       parameter must also be specified.

   Example 1.2. rabbitmq_publish() function usage
        ...
        rabbitmq_publish("ID1", "call", "$fU called $rU");
        ...
        rabbitmq_publish("ID1", "call", "{ \'caller\': \'$fU\',
                                        \'callee\; \'$rU\'", "applicatio
n/json");
        ...
        $avp(hdr_name) = "caller";
        $avp(hdr_value) = $fU;
        $avp(hdr_name) = "callee";
        $avp(hdr_value) = $rU;
        rabbitmq_publish("ID2", "call", "$rb", , "$avp(hdr_name)", "$avp
(hdr_value)");
        ...
