Custom Transport Handler in CQ5/AEM

13 / Oct / 2014 by Vivek Sachdeva 0 comments

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

[java]

@Service(TransportHandler.class)
@Component(label = “My Transport Handler”, immediate = true, enabled = true)
class CustomTransportHandler implements TransportHandler {

}

[/java]

  • Following 2 methods need to be implemented:

[java]

@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.
}

[/java]

This way you can customize and manage your own transport handler and have full control over it.

Hope this helps!!

Vivek Sachdeva
@vivek_sach

FOUND THIS USEFUL? SHARE IT

Leave a Reply

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