Azure Service Bus Consumer Without Changing Messaging Connection - Sitecore 9.3
With the advent of SaaS or DXP services like Sitecore Connect, messaging gains more importance than ever before. Messaging is extensively used as a fail-safe mechanism in case of Sitecore EXM. By default, Sitecore is capable of handling messages via Azure Service Bus or sql Server with a toggle of the centralised messagingTransport:require switch in web.config. A couple of pain points with this; when you specify AzureServieBus as messagingTransport, multiple queues part of Sitecore setup will be created in the target ASB. This might not be desirable if you don't own the queue and all you are allowed to do is connect to the queue and read messages. Plus, since this is an application-wide switch, you have to choose either sql server or Azure Service Bus. This Sitecore Messaging Framework on Azure Service Bus (Queue) — step by step tutorial blog post is a wonderful primer to not only highlight about messaging but also adding a custom EXM queue to existing messaging setup. On the other hand, what if you don’t want to touch this centralized EXM messaging setup but wish to add your own custom messaging to a third-party bus. Then, this blog post could be useful since it just takes the original post and adds the necessary toppings but the use-case is totally different here since we are talking about connecting to an external third-party service bus totally unrelated to Sitecore.
So, without much ado, to add the custom ASB messaging mechanism to existing setup, add this patch messaging config file that asks Sitecore to leave out the existing EXM messaging switch and handle the new custom ASB configuration in a de-coupled/independent manner. In other words, you severe the link to the messagingTransport:require switch by removing the concerned attribute altogether as part of this rebus configurator definition.
#####
#####
Next, add this custom transport config that has details about the custom queue and most importantly it stays away from the messagingTransport:require option, part of the centralized EXM setup -
######
######
Now, it is time to add the handler(s) -
1. Receive the JObject from the ASB queue and do further processing by deserialising it but in our current example, we will just keep it simple by logging the incoming message to the CM log
2. We will retain the Custom send message contract and the CD api controller as-is from the original post to send messages to the external Service bus system - needs implementation by connecting to the external message queue and sending the message
////
/////
Also, ensure to make adjustments to DI service registration:
That’s it. Finally, add the autonomous ASB connection string in ConnectionStrings.config matching the connection string name in the custom queue config file.
Now, we can send and receive messages to a custom stand-alone ASB queue while the centralised EXM messaging could function with SQL option. You can see this new one-off configuration in the showconfig aspx page:
ASB send message (with headers to the right-side):
Comments
Post a Comment