The goal is simply to experiment with the Redis Gears 2 (Triggers and Functions) prerelease, which includes V8 JavaScript Engine support, allowing us to subscribe JavaScript functions that automatically execute code on data changes directly in the Redis database.
Disclaimer: This project is all about the exploration rather than the end result.
We will be developing a SIP domain management application to facilitate user registration and connection to a SIP domain.
Having chosen Redis as our backend database and Kamailio to manage SIP communications, our primary goal is to develop a real-time synchronization system that ensures consistent and accurate data between our custom SipPlatform business model and the required Kamailio model.
Our business logic is composed of two main components:
- Java Service: It serves as the primary interface for data manipulation.
- Redis Gears V2 functions: to ensure that any changes in the business model are promptly reflected in Kamailio's configuration for SIP registration and management.
Our custom domain model is inspired by the Twilio SIP API, focusing primarily on two classes: SipDomain and Credential.
With support from Spring OM Redis, built on Spring Data Redis, we will effectively map our Java model to RedisJSON documents. RedisJSON module, will enable us to use Redis as a high-performance NoSQL document database. SipDomain and Credential models will be stored as JSON documents.
We plan to use Redis Gears v2 to subscribe JavaScript functions to keyspace notifications which will help us:
- include auditing metadata into our SIPPlatform domain entities.
- ensure Kamailio's configuration consistency, as any updates to our domain entities will be immediately delivered.
A more detailed description here.
A more detailed description here.
Kamailio is a powerful SIP (Session Initiation Protocol) server that can be customized to handle a wide range of SIP-related functionalities.
While Kamailio supports various databases, we're specifically choosing Redis for our example.
To enable Redis as the database backend for Kamailio, specific configurations need to be set. Here's an overview of what the Kamailio configuration file for Redis might look here.
- Node.js (v18.18.0) and npm(9.8.1) installed
- Redis Stack Server running with Key Space Notifications enabled:
CONFIG SET notify-keyspace-events KEA
- Maven (3.8.3) and Java (11) installed
- docker and docker-compose
- Start Redis Stack Server and Kamailio instances with docker-compose:
$ cd environment
$ docker-compose up
- Start the Redis Insights gui, start the profiler, open the CLI and run the following command in order check whether keyspace events notifications are enabled:
CONFIG GET notify-keyspace-events
# CONFIG SET notify-keyspace-events KEA
- Deploy javascript code to Redis Stack server:
$ cd redis-functions
$ npm install
$ npm run deploy
> redis-functions@1.0.0 deploy
> gears-api index.js
Deployed! :)
- Run the java backend application. This will create the necessary Redis indexes. (If you flush all redis data, be sure to rerun it in order to recreate the indexes
$ cd backend
$ mvn spring-boot:run
- Try creating a SipDomain, a Credential entities and request a DomainReload to Kamailio:
POST http://localhost:8080/domains
{
"name": "fictsip.com"
}
POST http://localhost:8080/credentials
{
"domain": "fictsip.com",
"username": "omar",
"password": "omar"
}
POST http://localhost:5060/RPC
{
"jsonrpc": "2.0",
"method": "domain.reload",
"id": 1 # increment this id for each request
}
A postman collection is provided: