A queue middleware implementation for AsterNET.ARI allowing you to use AsterNET.ARI with Ari Proxies like go-ari-proxy.
Middleware.Queue allows one or many ARI proxies to communicate with your AsterNET.ARI application. This provides both High Availability and Load Balancing.
The Middleware Queue provides it's own client AriBrokerClient which allows you to connect to a queue implementation, currently RabbitMq is supported. The AriBrokerClient raises an event when a new Dialogue is created by the proxy and returns you a handler (BrokerSession, implements IAriClient) that allows you to talk back to the originating proxy and receive Stasis events.
Middleware.Queue has been tested with go-ari-proxy.
The AriClientBroker allows you to establish a connection with a queue provider (e.g. RabbitMq) and receive new dialogues. When a new dialogue is received, AriBrokerClient establishes the requires sub queues or topics to handle the new dialogue. It rases the OnNewDialogue event and passes an instance of BrokerSession (which implements IAriClient).
var ari = new AriBrokerClient("queue-name",
new RabbitMq("amqp://", new RabbitMqOptions()
{
AutoDelete = false,
Durable = true,
Exclusive = false
}));
// Hook into AriOnNewDialogue event
ari.OnNewDialogue += AriOnNewDialogue;
// Connect
ari.Connect();
A dialogue encapsulates all the communications required for an ARI Application and a proxy to communicate. Each dialogue includes an event queue and a request and response queue. These are exposed as an implementation of IAriClient.
private static void AriOnNewDialogue(object sender, BrokerSession e)
{
Console.WriteLine("New Dialogue Started: {0}", e.DialogueId);
// A new application dialogue has been raised!
// Events are now directly tied to a dialogue via the BrokerSession
e.OnStasisStartEvent += E_OnStasisStartEvent;
e.OnStasisEndEvent += E_OnStasisEndEvent;
}
private static void E_OnStasisStartEvent(IAriClient sender, StasisStartEvent e)
{
// sender if BrokerSession which implements IAriClient
sender.Channels.Answer(e.Channel.Id);
sender.Channels.Play(e.Channel.Id, "sound:demo-congrats");
}