|
07.03.2013, 12:11 | #1 |
Участник
|
dynamics-coe: Simple “Publish-Subscribe” integration with Dynamics CRM using Azure Service Bus Topics/Subscriptions
Источник: http://blogs.msdn.com/b/dynamics-coe...criptions.aspx
============== Implementation of “publish-subscribe” based integration where Dynamics CRM acts as publisher is very common. In this article, I will talk about how “Azure Service Bus Topics/Subscriptions” can be used with Dynamics CRM to create a “publish-subscribe” based integration. I will not talk about “Azure Service Bus Topics/Subscriptions” in detail but focus more on usage scenario and integration. What is “Publish-Subscribe” Integration? First step is to know what is “publish-subscribe” (commonly known as pub-sub) based integration. It is an integration pattern. In simple language, in pub-sub integration, the subscribers are interested in certain messages and they keep looking for the messages at certain place called “bus”. When the publisher publishes or creates the message in the “bus”, each subscriber interested in this message gets a copy of it. There could be multiple subscribers for the same message. Subscribers could be interested either in a type of message or a message with certain content. When they are interested in message with certain content, content based routing is used to make that message available to the subscriber. I recommend you read the following links to learn more about publish-subscribe and content based routing – Publish Subscribe - http://www.eaipatterns.com/PublishSubscribeChannel.html Content Based Routing - http://www.eaipatterns.com/ContentBasedRouter.html Business Scenario for “Publish-Subscribe” Let me share couple of real scenario examples. There is a utility company which provides water and waste management service to citizens. It has a CRM system, billing system, messaging system and mapping (GIS) system. When a customer (message) is created in the CRM system (publisher), the billing, messages, GIS systems (Subscribers) need a copy of customer data to perform follow-up tasks and automation. For instance – billing system will create a billing account for the customer, the messaging system will send welcome message with customer account details on preferred communication channel and GIS system will update customer address in the database for mapping purpose. This is an example where subscribers are interested a message type. Another example is for content based subscription. There is a Telco company which provided services to a massive geography. It has logically divided the geography into four regions. It has a centralized CRM system but the billing system has been partitioned into four physical instances – one for each region. When the customer (message) is created or updated in the CRM system (published), it has to be updated into respective billing system (subscriber) based on the region (content) of the customer. The following are critical components of the publish-subscribe pattern –
The Windows Azure Service Bus Topics/Subscriptions provides a light-weight but reliable and scalable platform for “public-subscribe” based integration. It has the entire ingredient for such implementation –
We need to do the following for integration –
How to use Topics/Subscriptions with Dynamics CRM? Finally, let’s see how we make Topics/Subscriptions work with Dynamics CRM in simplest form. Let’s take a scenario where when contact is created or updated in Dynamics CRM – the subscribers (billing, messaging, GIS systems etc.) are interested in it.
string _ConnectionString = "Endpoint=sb://demosb-ns.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=u5TOVcfSgWC1lKX8+KiHH/7znVP3p3pX23ddwed342edd="; string topicName = "demotopic"; public void Execute(IServiceProvider serviceProvider) { try { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName.Equals("contact")) { TopicClient Client = TopicClient.CreateFromConnectionString(_ConnectionString, topicName); BrokeredMessage message = new BrokeredMessage(entity); Client.Send(message); } } catch (Exception) { throw; } }
string _ConnectionString = "Endpoint=sb://demosb-ns.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=u5TOVcfSgWC1lKX8+KiHH/7znVP3p3pX23ddwed342edd="; string topicName = "demotopic"; string subName = "demosubscriptio"; SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString (_ConnectionString, topicName, subName); Client.Receive(); // Continuously process messages received from the subscription while (true) { BrokeredMessage message = Client.Receive(); if (message != null) { try { Entity entity = message.GetBody(); //TODO: WRITE CODE TO CONSUME THIS ENTITY INSTANCE message.Complete(); } catch (Exception) { message.Abandon(); } } }
You can see it is a simple, elegant but very reliable and powerful way of implementing publish-subscribe pattern with Dynamics CRM. The implementation can have many faces and variant – I leave that to your design and scenario. Hope you find this article useful. Источник: http://blogs.msdn.com/b/dynamics-coe...criptions.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|