How to manage Multi-tenant in Asterisk

We are trying to implement multi-tenant asterisk solution with as sip provider.
Every company(tenant) will have a account which has all the DID numbers corresponding to that company.

As per the discussion in the below links, there will be separate context in extensions.conf for each company :

Outgoing calls can be configured easily.
Problem is in directing incoming calls to its corresponding context based on DID.

As per this project: GitHub - irontec/ivozprovider: IVOZ Provider - Multitenant solution for VoIP telephony providers , we figured we can have a DB call from extensions.conf through AGI script to fetch context corresponding to DID.
But there is performance issue as we need to have DB call for each incoming call.

An alternative can be getting the value from cache. We already have sorcery cache for pjsip realtime.
But we don’t know how to retrieve data from this cache through AGI script.

Question: How to retrieve data from sorcery cache? Is the above method preferred? If not,what are the alternate solutions?

You could generate static dialplan that’s updated by an external script in a cron job

Hi @johnkiniston
Thanks for the response. But can you please elaborate on static dialplan and what the external script should be doing? As we are not aware how to implement.

So you can define a context and have it include an external file.

#include "customer.conf"

Then you create ‘customer.conf’ with your dialplan using your external script

exten => 5551234,1,Playback(tt-monkeys)
 same => n,Hangup()

exten => 5551235,1,Playback(you-sound-cute)
 same => n,Hangup()

Your script could be written in any language you like, just read your data from your database and write it out to your file.

1 Like