See if replication listener  fullfill your requirements otherwise pseudo steps for own custom agent would be .
Here are the steps to create a custom agent :
1) Create a custom transport handler class that implement com.day.cq.replication.TransportHandler. Make it an OSGi service with com.day.cq.replication.TransportHandler as a service interface.
* Implement the deliver(TransportContext ctx, ReplicationTransaction tx) method to communicate with given url
* Implement canHandle(AgentConfig config) method. This method will be called by the replication service to determine if this agent should handle the content being activated before calling deliver() method.
2) Create a Content Builder class by implementing com.day.cq.replication.ContentBuilder interface. Make this an OSGi component as well with com.day.cq.replication.ContentBuilder as it's service interface. This class would be responsible for building content to be replicated. This class should create ReplicationContent object that would represent content to be replicated. You will be able to retrieve ReplicationContent object from ReplicationTransaction in the deliver() method of your transport handler from ReplicationTransaction.
3) Create an agent page component and template. This would be used to configure the agent. As a starting point you can simply copy the page component and template for the default replication agent.
* see /libs/cq/replication/components/agent and /libs/cq/replication/templates/agent.
For your TransportHandler and ContentBuilder implementation you will need to create an OSGi bundle.
Thank you for this solution. I have another question connected with this issue. I was able to create my own Content Builder. Unfortunately when I chose it as Serialization Type with default agent an error occured:
ERROR - my-agent : << HTTP/1.1 400 Bad Request
ERROR - my-agent : << Connection: Close
ERROR - my-agent : << Server: Day-Servlet-Engine/4.1.24
ERROR - my-agent : << Content-Type: text/plain;charset=utf-8
ERROR - my-agent : << Content-Length: 114
ERROR - my-agent : <<
ERROR - my-agent : << error: com.day.cq.replication.ReplicationException: Repository error during page import: Protocol Header expected.
ERROR - my-agent : Message sent.
Additionally test connection works perfect.
It might be different isssue. Clean all your queue & reverify. Also at end point of agent verify what is the Content-Length header size.
Hello Sham HC,
As far as I can see, this is the only description about how to write your own costum replication agent. Thanks for that!
Anyway, I'm facing a problem following your descriptions:
I implemented the interfaces com.day.cq.replication.TransportHandler + com.day.cq.replication.ContentBuilder and registered both as OSGi components. The Web Console tells me, everything is fine, as both classes occure as components in the corresponding tab. In addition, I can create a new replication agent (using the standard template "Replication Agent") and assign my ContentBuilder to this agent by setting it's Serialization Type to the value I retrieve in my method ContentBuilder.getTitle() ("XML ContentBuilder"). (The URI on tab "Transport" is set too.)
Using CRXDE Lite I can browse to /etc/replication/agents.author/myAgent/jcr:content and see, that the property serializationType is set to the value I provide in my method ContentBuilder.getName() ("xmlContent").
Everything seems fine. But when I try to enable my agent I always get the following error on the agent's settings page:
Agent is not valid. ContentBuilder not available
In addition, the error.log shows the following message:
*ERROR* [ObservationManager] com.day.cq.replication.Agent.myAgent Agent not valid yet. No content builder for xmlContent
*INFO* [ObservationManager] com.day.cq.replication.Agent.myAgent Agent updated. State is enabled and invalid
What am I doing wrong?
Shouldn't this work perfectly?
Do I miss something?
Thanks in advance for any hints and advices!
1 person found this helpful
The steps I have provided are correct. As an sample implementation refer "Refetch flush agent" source code at . Te details of the agent is covered for five minutes at .
I now came across my problem:
In order for CQ to find the ContentBuilder it needs a service property name that has exactly the same value as the method getName() returns.
So in my example (as I use scr annotations) I just added the following line to my ContenBuilder class:
@Property(name = "name", value = "xmlContent")