从CRM插件订阅Azure Service Bus主题 [英] Azure Service Bus Topic subscribe from CRM plugin

查看:68
本文介绍了从CRM插件订阅Azure Service Bus主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功将消息从CRM插件发布到Azure服务总线队列.理想情况下,我需要CRM来收听主题(订阅)并在接收时执行操作.我不知道CRM是否可以做到这一点,并且找不到实现它的方法.我可以从下面的队列中读取内容;

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();
            }
        }
    }

但是,当通过用户操作执行插件时,将调用此方法.我需要一直在听. CRM可以实现吗?我在内部使用CRM 2016,消息总线托管在Azure中.

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.

感谢任何指针.

推荐答案

CRM不是始终监听的应用程序.它是由HTTP请求触发的Web应用程序.为了弥合这一差距,您可以使用Azure Functions.由于服务总线可以触发Azure功能,因此 可以调用Dynamics CRM.

CRM is not an always-listening application. It is a web application triggered by an HTTP request. To bridge this gap you can use Azure Functions. Since an Azure Function can be triggered by the Service Bus and can call Dynamics CRM.

您将需要创建由Service Bus队列触发的Azure功能的部署.在以下位置对此进行了详细记录: https://docs.microsoft.com/zh-CN/azure/azure-functions/functions-bindings-service-bus

You will need to create an deploy an Azure Function that is triggered by a Service Bus queue. This is well documented at: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus

为您的Azure函数创建package.json:

Create a package.json for your Azure Function:

{
"bindings": [
    {
    "queueName": "testqueue",
    "connection": "MyServiceBusConnection",
    "name": "myQueueItem",
    "type": "serviceBusTrigger",
    "direction": "in"
    }
],
"disabled": false
}

基本功能代码:

public static void Run(string myQueueItem, TraceWriter log)
{
    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}

一旦完成此工作,就可以构建Azure Function代码以连接到Dynamics CRM,就像其他任何代码一样.

Once you have this working you can build out your Azure Function code to connect to Dynamics CRM - same as you would any other code.

将依赖项添加到project.json(必须完全正确,如此处所述:

Add dependencies to project.json (must get this exactly correct as discussed here: http://crmtipoftheday.com/2016/12/12/connect-to-dynamics-365-in-azure-functions/):

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.CrmSdk.CoreAssemblies": "8.2.0",
        "Microsoft.CrmSdk.XrmTooling.CoreAssembly": "8.2.0"
      }
    }
  }
}

这篇关于从CRM插件订阅Azure Service Bus主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆