Skip to main content
Version: 2.0.0

Sending Call Events to NATs

Routr ships with a NATs publisher that can be used to send call events to a NATs server. Call events are a function of the EdgePort. To enable the NATs publisher, you will need to update your EdgePort service to set the environment variable NATS_PUBLISHER_ENABLED to true as well as the environment variable NATS_PUBLISHER_URL to the URL of your NATs server. For example:

version: "3"
image: fonoster/routr-one:latest
- 51908:51908
- 5060:5060/udp

Once you have enabled the NATs publisher, you can subscribe to the or subjects to receive call events. As of the writing of this book, only the and subjects are supported. However, we plan to add more subjects in the future. Be sure to check in later to see if any more have been added.

To begin receiving call events, you can use the nats sub command line tool. To do this, first connect to your NATs server by running the following command:

nats context add nats \
--server \
--description "nats events" \

You should then see something like this:

NATs context add

In the previous command, we connected to the server, which is a public NATs server. You can use your own NATs server if you have one.

Then, you can subscribe to the subject by running the following command:

nats sub

After subscribing to the subject and making a call, you should see something like this:

NATs call started

Similarly, you can subscribe to the subject to receive call-ended events. This should produce an output like shown in the image below:

NATs call ended

You can use the NATS_PUBLISHER_SUBJECT environment variable to change the based subject name. For example, you can set it to myserver to receive call events in the myserver.calls.started subject.