oalles / sip-platform

A Sip domain management application based on redis, redis gears v2 prerelease and kamailio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A SIP Domain Management Application with Java, Redis, Redis OM Spring, Redis Gears V2, and Kamailio

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.

Scenario

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.

Diagram

Description

Our business logic is composed of two main components:

  1. Java Service: It serves as the primary interface for data manipulation.
  2. 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.

Redis Gears V2 Functions

A more detailed description here.

SipPlatform Java Service

A more detailed description here.

SIP Domain Implementation with Kamailio and Redis

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.

Prerequisites

  • 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

Usage

  1. Start Redis Stack Server and Kamailio instances with docker-compose:
$ cd environment
$ docker-compose up
  1. 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
  1. 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! :)
  1. 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
  1. 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:

Try with Postman

  1. Try SIP registration to the created domain with the created credentials with a soft phone. Zoiper registered

About

A Sip domain management application based on redis, redis gears v2 prerelease and kamailio


Languages

Language:Java 77.5%Language:JavaScript 22.5%