I am successfully posting messages from a CRM plugin to an Azure Service Bus Queue. Ideally I need CRM to listen to a Topic (subscription) and perform an action on receive. I do not know if this is possible with CRM and cannot find a method of implementing it. I can read from a queue with the below;
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(QueueConnectionString);
//Receiving a message
MessageReceiver testQueueReceiver = factory.CreateMessageReceiver(QueueName);
while (true)
{
using (BrokeredMessage retrievedMessage = testQueueReceiver.Receive())
{
try
{
var message = new StreamReader(retrievedMessage.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();
retrievedMessage.Complete();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
retrievedMessage.Abandon();
}
}
}
However this gets called when a plugin is executed by a user action. I need to be always listening. Can this be achieved with CRM? I am using CRM 2016 on premise, with the message bus hosted in Azure.
Thanks for any pointers.