April 10, 2020
Estimated Post Reading Time ~

Custom Transport Handler in CQ5/AEM

While integrating ElasticSearch with AEM, I used custom replication agent, for indexing data to  ElasticSearch server, as replication agent manages a queue in case replication is not successful and tries it again(after specified time).
But the problem I faced was that on successful indexing(insertion/updation), ElasticSearch return “201 OK” response but the replication agent considers only “200” response code as success and even 201 is considered as “fail” . So the replication content was never removed from the queue even though data was indexed.
The solution I came up with was to use my own transport handler that handles replication for “Elastic Server Replication Agent”. Following are the steps to do it:
  • Create a class that implements TransportHandler interface
1
2
3
4
5
@Service(TransportHandler.class)
@Component(label = "My Transport Handler", immediate = true, enabled = true)
class CustomTransportHandler implements TransportHandler {
 
}
  • Following 2 methods need to be implemented:
1
2
3
4
5
6
7
8
9
@Override
boolean canHandle(AgentConfig agentConfig) {
// return true in case agentConfig.getTransportURI() matches the one for our own replication agent
}
 
@Override
ReplicationResult deliver(TransportContext transportContext, ReplicationTransaction replicationTransaction) throws ReplicationException {
// return ReplicationResult.OK in case of successful indexing. In this case content is deleted from the queue.
}
This way you can customize and manage your own transport handler and have full control over it.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.