
Amazon Simple Queue Service (SQS) is a fully managed message queuing for microservices, distributed systems, and serverless applications. SQS allows you to send, store, and receive messages, making it easier to build reliable and decoupled systems. It supports both standard and FIFO queues.
SQS is offered “as a Service” (aaS) by the AWS cloud. Having OpenSIPS natively supporting SQS facilitates even more the creation and integration of OpenSIPS-based services in AWS.
The event_sqs module in OpenSIPS is designed to serve as a producer for Amazon SQS. It enables OpenSIPS to send messages to SQS queues either through manual scripting. It can also trigger events via the Event Interface (EVI).
Dependencies
The event_sqs module relies on the AWS SDK for C++. Make sure you have the AWS SDK for C++ installed and setup on your Linux system. You can use the AWS SDK for C++ Installation Guide. Further instructions can be found on the GitHub Repository.
Usage
This module can be used in two different ways:
- Manual Script: OpenSIPS users can publish messages to SQS queues directly from OpenSIPS script using the ‘sqs_publish_message()‘. function.
- Event-Driven: OpenSIPS publishes messages to SQS when a specific event is raised with OpenSIPS’ Event Interface.
Scripting
When using the manual script mode, you can configure SQS queues in the OpenSIPS configuration file. This is done via the ‘queue_url’ option, which specifies the URL to which messages should be send. Once configured, you can use the ‘sqs_publish_message()‘ function to send messages.
Example of Scripting Usage
modparam("event_sqs", "queue_url", "[q1]https://sqs.us-west-2.amazonaws.com/123456789012/Queue1")
$var(msg) = "Hello, this is a message to SQS!";
sqs_publish_message("q1", $var(msg));
Events
OpenSIPS can automatically send messages to SQS when certain events occur. This can be done through the use of OpenSIPS’s Event Interface, enabling you to subscribe for events and trigger them as necessary. When an event is triggered, the associated message is sent to the SQS queue that has been set up.
Example of Event-Driven Messaging
1. Event Subscription in OpenSIPS Script:
subscribe_event("E_OPENSIPS", "sqs:http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/Queue2");
2. Event Subscription via CLI:
opensips-cli -x mi event_subscribe E_OPENSIPS \
sqs:http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/Queue2
3. Raise the Event and Send Message:
opensips-cli -x mi raise_event E_OPENSIPS 'OpenSIPS Message'
Local Testing
If you want to run the SQS server locally for testing purposes, you can use the LocalStack project:
pip install localstack
localstack start
There are some environment variables that need to be set, for example:
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_DEFAULT_REGION=us-east-1
Examples of some cli commands that you can use for local testing can be found here.
Conclusion
The event_sqs module offers a smooth integration of Amazon SQS with the OpenSIPS system. Whether you want to manually send messages through scripts or utilizing event-driven messaging, this module provides the flexibility to interact with SQS queues in a scalable, asynchronous way.
This is the first version of the event_sqs module and we are open to feedback regarding other usage cases that you find useful to integrate into the module.
We encourage you to share your suggestions and needs for future extensions so that we can improve and expand the module.
