Today, we are going to see how to extend the default SDL Tridion deployment functionality, using Custom Deployer Extension. Before we move forward and start building/set up the project let's first understand the use of Deployer Extension. When a user publishes content, the Content Deployer unpacks the incoming Transport Package and processes its transport instructions and we can extend the default behavior of the Content Deployer by creating a custom Module and adding it to a Step, or by extending an existing Module.
Deployer Extension:-
2. Enter the Project Name
4. Copy all the JARs in lib, you can find all the default JAR files in the deployer microservice lib folder. Once copied then we need to Add the Build PATH.
Deployer Extension:-
- Deployer Extension is used to inject additional functionality in the default SDL Tridion deployment process.
- If you want to implement your custom logic/data. "Event System might be useful here as well 🤔 We need to be absolutely sure about it".
- If you want to use some specific data/info which is only available at the time of deployment.
- Based on JAVA.
- You can extend the default behavior of the Content Deployer by creating a custom Module and adding it to a Step, or by extending an existing Module.
In order to set up the JAVA project for the Deployer Extension, I have used Eclipse IDE, default JARs provided by SDL and JAVA 8.
First, we need to configure the JAVA project using Eclipse.
1. Click on File --> New --> Other Project and then select Java Project and click Next.
Create New JAVA Project |
2. Enter the Project Name
4. Copy all the JARs in lib, you can find all the default JAR files in the deployer microservice lib folder. Once copied then we need to Add the Build PATH.
5 Next, is create a Java package and then create a CLASS file.
6. Start Importing all the Namespace that's required in order to extend the deployer.
7. Next is we must implement the abstract method Module.process(TransportPackage)
package com.tridion.deployer.extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.deployer.Module;
import com.tridion.deployer.ProcessingException;
import com.tridion.deployer.Processor;
import com.tridion.transport.transportpackage.TransportPackage;
public class PurgeCache extends Module {
protected static Logger log = LoggerFactory.getLogger(PurgeCache.class);
public PurgeCache(Configuration config, Processor processor) throws ConfigurationException
{
super(config,processor);
}
// This is called once for each Transport Package that is deployed.
@Override
public void process(TransportPackage data) throws ProcessingException
{
log.debug("This is custom logs");
int publicationId =data.getProcessorInstructions().getPublicationId().getItemId();
log.debug("PublicationId : " + String.valueOf(publicationId));
}
}
That's it Export this into a JAR and next is the configuration in the deployer_config.xml of Deployer Microservice. "Don't forget to restart the service".
Click Export |
Finally, we need to deploy the custom JAR in the deployer microservice lib folder and open the deployer_config.xml file in your favorite editor add the below configuration, save the file Don't forget to take a backup before you start editing.
<Step Factory="com.sdl.delivery.deployer.steps.TridionExecutableStepFactory" Id="PurgeCacheSteps">
<Module Type="PurgeCache" Class="com.tridion.deployer.extension.PurgeCache">
</Module>
</Step>
We also need to edit the logback.xml
Let's do some publishing and see if everything is working fine. Ideally, we should be able to see the logs entries. If you see the custom logs in the log file that means your custom code is interesting with default deployment process and you've built the extension successfully.
<logger name="com.tridion.deployer.extension">
<appender-ref ref="rollingDeployerLog"/>
</logger>
In the next blog, we will use the deployer extension with a very interesting use-case, until then.
Happy Coding and Keep Sharing !!!
Happy Coding and Keep Sharing !!!
No comments:
Post a Comment