Skip to content

Latest commit

 

History

History
111 lines (83 loc) · 3.68 KB

mod_amqp_9635078.mdx

File metadata and controls

111 lines (83 loc) · 3.68 KB

mod_amqp

About

mod_amqp gives FreeSWITCH™ ability to send events through an amqp server like RabbitMQ and listen for api commands. You can configure one or more connections and filter for which events to send.

Click here to expand Table of Contents

Loading

Once you have installed FreeSWITCH from packages, configure FreeSWITCH to load mod_amqp in autoload_configs/modules.conf.xml by uncommenting the line:

<load module="mod_amqp"/>

Configuring

If need be, edit the amqp connection configuration in autoload_configs/amqp.conf.xml and set the hostname, username, password, and port as applicable.

Example for default installation where rabbitmq server is the same as the FreeSWITCH server:

<producers>
 <profile name="default">
  <connections>
    <connection name="primary">
     <param name="hostname" value="localhost"/>
     <param name="virtualhost" value="/"/>
     <param name="username" value="guest"/>
     <param name="password" value="guest"/>
     <param name="port" value="5672"/>
     <param name="heartbeat" value="0"/>
   </connection>
...

Various parameters can be set depending on the services required. For example, to send FreeSWITCH events to rabbitmq, the following parameters could be added to the profile:

 <params>
  	<param name="exchange-name" value="TAP.Events"/>
  	<param name="exchange-type" value="topic"/>
	  <param name="circuit_breaker_ms" value="10000"/>
	  <param name="reconnect_interval_ms" value="1000"/>
	  <param name="send_queue_size" value="5000"/>
	  <param name="enable_fallback_format_fields" value="1"/>
  	<param name="format_fields" value="#FreeSWITCH,FreeSWITCH-Hostname,Event-Name,Event-Subclass,Unique-ID"/>
...

The routing key is made from the format string, using the header values in the event specified in the format_fields. Fields that are prefixed with a # are treated as literals rather than doing a header lookup.

Customize the Event Filter by editing the following lines. The default captures channel create and destroy, fs heartbeat, and dtmf.

 <!--    <param name="eventFilter" value="SWITCH_EVENT_ALL"/> -->
 <param name="event_filter" value="SWITCH_EVENT_CHANNEL_CREATE,SWITCH_EVENT_CHANNEL_DESTROY,SWITCH_EVENT_HEARTBEAT,SWITCH_EVENT_DTMF"/>

It is also possible to send commands to FreeSWITCH via a rabbitmq connection by adding a commangs section to the configuration:

<commands>
    <profile name="default">
      <connections>
       	<connection name="primary">
	         <param name="hostname" value="localhost"/>
	         <param name="virtualhost" value="/"/>
	         <param name="username" value="guest"/>
	         <param name="password" value="guest"/>
	         <param name="port" value="5672"/>
	         <param name="heartbeat" value="0"/>
	       </connection>
      </connections>
      <params>
	       <param name="exchange-name" value="TAP.Commands"/>
	       <param name="binding_key" value="$${hostname}_command"/>
	       <param name="reconnect_interval_ms" value="1000"/>
	       <param name="queue-passive" value="false"/>
	       <param name="queue-durable" value="false"/>
	       <param name="queue-exclusive" value="false"/>
	       <param name="queue-auto-delete" value="true"/>
	       <param name="queue-name" value="$${hostname}_command"/>
      </params>
    </profile>
</commands>

When publishing a command via rabbitmq, it is necessary to set two header values:

x-fs-api-resp-exchange and x-fs-api-resp-key

These will contain the exchange and the route key to which you require the command output sending to.

From fs_cli, apply the changes:

 reloadxml
 reload mod_amqp