Sitecore Publishing Service 2.0 – How to setup a publishing target

In a previous post we discussed what Sitecore Publishing Service is, in this one we are going to see how to setup a publishing target so that it works with this alternative publishing service.

Sitecore Publishing Service 2.0 is complatible with Sitecore 8.2 Update 2, so that is the version of Sitecore we are going to use. By default Sitecore already have a publishing target setup called “Internet” which points to our “web” database.

Internet publishing target
Internet publishing target

So let’s go ahead and setup a new publishing target and set it up to point to whatever other database you like, in my case I will use a database from a Sitecore instance I have deployed in AWS (Asia-Pacific region) and I will call it “Singapore”. We will not cover how to do this, if you don’t know how to do it, there are plenty of articles about that, like this one, a simple Google search will help you too. This is how I have my custom publishing target:

Singapore publishing target
Singapore publishing target (points to “sg” database)

To make sure it is working you can publish a couple of item using the default publishing method Sitecore have before installing the alternative one.

Ok, now we have to install the Sitecore Publishing Service 2.0, in order to do that you can follow the instructions in it’s official Installation Guide, it has a manual and scripted version about how to do it, I recommend the scripted one. I found this article to be very detailed as well.

Again, to make sure it is working you can try publishing to your “Internet” publishing target, it won’t work for your custom target by default, that is what this post is about.

At this point we have a custom publishing target setup, as we normally do for the standard Sitecore publishing method and also we already have Sitecore Publishing Service 2.0 setup, let’s go ahead and do the following configurations in order to make this custom publishing target work with the new publishing service.

First we need to add the connection string for the custom target, we could use the command prompt or just manually modify the ConnectionString section of “config\sitecore\publishing\sc.publishing.xml” config file:

<ConnectionStrings>
    <!-- The Service connection is registered to map to the same connection string as the master database by default. -->
    <Service>${Sitecore:Publishing:ConnectionStrings:Master}</Service>
    <sg>user id={user};password={password};data source={target_server};database={target_database};MultipleActiveResultSets=True;</sg>
</ConnectionStrings>

Notice that in my case, I don’t have the connection strings for core, web and master databases here, this is because, as you probably read in the documentation, you can also setup your connection strings in “config\global\sc.connectionstrings.json”, so for these databases I have them setup in that file, like this:

{
  "Sitecore": {
    "Publishing": {
      "ConnectionStrings": {
        "core": "user id={user};password={password};data source=localhost;database=sc82Sitecore_core;MultipleActiveResultSets=True;",
        "web": "user id={user};password={password};data source=localhost;database=sc82Sitecore_web;MultipleActiveResultSets=True;",
        "master": "user id={user};password={password};data source=localhost;database=sc82Sitecore_master;MultipleActiveResultSets=True;"
      }
    }
  }
}

I’m using {user}, {password}, etc. but you should put real information there. Also you can setup your connection string in whatever file you like, it will work however you choose to do it.

Next step is to setup the the connection factory for the target, you can do that in the DefaultConnectionFactory:

<Singapore>	
	<Type>Sitecore.Framework.Publishing.Data.AdoNet.SqlDatabaseConnection, Sitecore.Framework.Publishing.Data</Type>
	<LifeTime>Transient</LifeTime>
	<Options>
		<ConnectionString>${Sitecore:Publishing:ConnectionStrings:sg}</ConnectionString>
		<DefaultCommandTimeout>120</DefaultCommandTimeout>
		<Behaviours>
			<backend>sql-backend-default</backend>
			<api>sql-api-default</api>
		</Behaviours>
	</Options>
</Singapore>

The easy way of doing this is by replicating the one for the “Internet” target that is configured by default and then modify it, the name of the “root” element should match the name of your publishing target, in my case “Singapore”, and the value for the ConnectionString element should point to your connection string, in my case “${Sitecore:Publishing:ConnectionStrings:sg}”, notice the “sg” at the end.

Now we need to add a new store factory in the StoreFactory section, this factory is the one responsible for creating connections for the publishing service to use:

<Singapore>
	<Type>Sitecore.Framework.Publishing.Data.TargetStore, Sitecore.Framework.Publishing.Data</Type>
	<ConnectionName>Singapore</ConnectionName>
	<FeaturesListName>TargetStoreFeatures</FeaturesListName>
	<Id>2E773BB7-6B3E-4E6B-8791-878A79C92D47</Id>
	<ScDatabase>sg</ScDatabase>
</Singapore>

Again, the easiest way of doing it is also replicating the one for “Internet” and modify it, in this case you have to modify the ConnectionName, the Id, which is the Sitecore item Id for your custom target, and the SCDatabase, which the name of your connection string.

One last thing to do before you can try to publish to the custom publishing target, it is to upgrade the publishing schema for the target database, the same way as you probably did when setting up the service, by running:

Sitecore.Framework.Publishing.Host schema upgrade --force

And that’s it, you can now try publishing to this custom target.

You can read the Sitecore Publishing Service 2.0 documentation for more details about all the configurations we did.

Sitecore Publishing Service 2.0 – How to setup a publishing target
Tagged on:         

One thought on “Sitecore Publishing Service 2.0 – How to setup a publishing target

Leave a Reply

Your email address will not be published. Required fields are marked *