Sitecore Messaging Framework
Recently I have implemented Sitecore Message Framework. Hopefully, it will be helpful for you.
Scenario:
I had a scenario where I was using a scaled environment and I wanted to save some data on the master DB from content delivery. As you know content delivery can access Core and Web Db and it cannot access master DB so to achieve this functionality I have used Sitecore Messaging Framework.
What is a Sitecore Messaging Framework?
Sitecore Messaging was introduced in Sitecore 9.0.1 version (Only SQL Transport). It supports message-based communication in Sitecore. It is part of the XP, not part of the XM configuration. It wraps up the Rebus library.
Please install the following libraries
- Sitecore.Framework.Messaging.Abstractions
- Sitecore.Framework.Messaging.Configuration
Below are the steps:
- You need to create a configuration file for the bus which you need to copy to CM and CD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:eds="http://www.sitecore.net/xmlconfig/eds/" xmlns:exmEnabled="http://www.sitecore.net/xmlconfig/exmEnabled/"> | |
<sitecore exmEnabled:require="yes"> | |
<Messaging> | |
<Rebus> | |
<Namespace.UnsubscribeMessageBus> | |
<Transport> | |
<SqlServer> | |
<OneWay role:require="(Standalone or ContentManagement) and !ContentDelivery">false</OneWay> | |
<OneWay role:require="ContentDelivery">true</OneWay> | |
<ConnectionStringOrName>messaging</ConnectionStringOrName> | |
<TableName>Sitecore_Transport</TableName> | |
<InputQueueName>EventMessagesQueue</InputQueueName> | |
</SqlServer> | |
</Transport> | |
<Routing> | |
<TypeBasedMappings> | |
<TypeMappings> | |
<EmailBounceMapping> | |
<Type>Namespace.UbsubscribeItemMessage, Namespace</Type> | |
<DestinationQueue>EventMessagesQueue</DestinationQueue> | |
</EmailBounceMapping> | |
</TypeMappings> | |
</TypeBasedMappings> | |
</Routing> | |
<Options role:require="Standalone or ContentManagement"> | |
<SetNumberOfWorkers>1</SetNumberOfWorkers> | |
<SimpleRetryStrategy> | |
<ErrorQueueAddress>Error</ErrorQueueAddress> | |
<MaxDeliveryAttempts>1</MaxDeliveryAttempts> | |
<SecondLevelRetriesEnabled>false</SecondLevelRetriesEnabled> | |
</SimpleRetryStrategy> | |
</Options> | |
<Logging Type="Sitecore.Messaging.SitecoreLoggerFactory,Sitecore.Messaging"/> | |
</Namespace.UnsubscribeMessageBus> | |
</Rebus> | |
</Messaging> | |
</sitecore> | |
</configuration> |
- Then you need to create an empty class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class UnsubscribeMessageBus | |
{ | |
} |
- Now you need to create a class and in that class define all properties which you want. I am mentioning Email and Name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UbsubscribeItemMessage | |
{ | |
public string Email { get; set; } | |
public string Name { get; set; } | |
} |
- Let's create a config file where you need to initialize the bus connections via the Sitecore Initialization pipeline
Comments