Multiple asterisk servers, PJSIP, shared realtime database

I’m looking to add some fail over support to our Asterisk system and I’m wondering if this is possible:

In our DNS server, I have A records set to two Asterisk servers. Lets call them sip1 and sip2.
And an SRV record for sip with 50/50 weight pointing to sip1 and sip2.

These Asterisk systems are both using a shared realtime MySQL database. So any user can register on sip1 or sip2.
The SRV record works; if you register to sip, you sometimes register to sip1 and sometimes you register to sip2.

The issue I’m having is calling across servers. Say 101 calls 102 - where 101 is registered to sip1 and 102 is on sip2.

We are using an ARI dial type app handling routing. If 101 calls 102, we call all contacts of 102 and stop ringing once one picks up.

It would be really simple if 101 can call every contact of 102 across all servers. I tried this and got inconsistent results. Using X-Lite and Zoiper registered to separate servers, Zoiper will ring but X-Lite will not when calling each other.

I can get this to work over an IAX connection between the servers though it can get complicated since an endpoint could have a contact on either/both servers at once. This might be the way I do this in the end though.

Does anyone have experience doing this?


It really depends on the network and endpoint itself. If NAT is involved then you may or may not be able to send a message to the device from another server, as it is dependent on the properties of the NAT itself. The endpoint itself can also choose to ignore your message as it did not originate from the server it registered to.

Thanks for your reply.

Yes, endpoints will almost always be behind a NAT. So this will not work I guess.

Would using a proxy server instead of SRV records solve this? I have looked into Kamailio but honestly found it pretty difficult to wrap my head around.

And, if an endpoint is allowed multiple contacts, the endpoint can register to two servers at once.

Is there a way to make sure all of an endpoint’s contacts register to the same server? I’m guessing there is not with SRV records…

Kamailio dispatcher probably can if dispatching based on username.

If devices register to the SIP proxy instead then it would work, as calls would flow through there.

As for registering to the same place - no, there is no way with SRV records.

Is there a way to find the contacts for a given endpoint and tell which server it is registered on?

Using ARI,




give contacts across both servers.

Is there something like this?


I have tried using the id column from ps_contacts and have tried url encoding first. But I always get a 404.

And what is the REST data model called “ContactInfo”?

I’m wondering if this will help me but I can’t find how to access it.


No, there is no way as things are right now. That information is not present. It was not designed for that deployment model and has not been changed to work as such either. ContactInfo is for a PJSIP contact, but I have not used it through the dynamic mechanism so I can’t comment on it. It also would not tell you what server the contact is on.

I think I found a way to do this.

If I remove the realtime contacts configuration from extconfig.conf and sorcery.conf so that contacts are not stored in the database, then each server only knows about contacts stored on themselves. Then I can use ARI to check other servers to see if the contact is registered there too.

This kind of seems like a hacky approach to this… I think I’m not sure exactly what is the purpose of the ps_contacts table when using ARI. Is there some other function that I’m missing?

I really appreciate your answers. Thanks


It does give useful info like via_addr and user_agent. Is there a way to get this from ARI?

I don’t know in regards to ps_contacts and ARI. As for retrieving via_addr and user_agent, not that I’m aware of.

If anyone else is wondering, I was able to get this info from the ARI:

For example, the contact:


you would use:


That is, MD5 sum of





1 Like