{"id":15735,"date":"2014-10-13T16:17:32","date_gmt":"2014-10-13T10:47:32","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15735"},"modified":"2014-10-13T16:17:32","modified_gmt":"2014-10-13T10:47:32","slug":"custom-transport-handler-in-cq5aem","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/custom-transport-handler-in-cq5aem\/","title":{"rendered":"Custom Transport Handler in CQ5\/AEM"},"content":{"rendered":"<p>While integrating ElasticSearch with AEM, I used\u00a0custom replication agent, for indexing data to \u00a0ElasticSearch server, as replication agent manages a queue in case replication is not successful and tries it again(after specified time).<\/p>\n<p>But the problem I faced was that on successful indexing(insertion\/updation), ElasticSearch return &#8220;201 OK&#8221; response but the replication agent considers only &#8220;200&#8221; response code as success and even 201 is considered as &#8220;fail&#8221; . So the replication content was never removed from the queue\u00a0even though data was indexed.<\/p>\n<p>The solution I came up with was to use my own transport handler that handles replication for &#8220;Elastic Server Replication Agent&#8221;. Following are the steps to do it:<\/p>\n<ul>\n<li>Create a <a href=\"https:\/\/github.com\/viveksachdeva\/elasticsearch-cq\/blob\/master\/bundle\/src\/main\/java\/com\/vivek\/CustomTransportHandler.groovy\">class<\/a> that implements\u00a0TransportHandler interface<\/li>\n<\/ul>\n<p>[java]<\/p>\n<p>@Service(TransportHandler.class)<br \/>\n@Component(label = &#8220;My Transport Handler&#8221;, immediate = true, enabled = true)<br \/>\nclass CustomTransportHandler implements TransportHandler {<\/p>\n<p>}<\/p>\n<p>[\/java]<\/p>\n<ul>\n<li>Following 2 methods need to be implemented:<\/li>\n<\/ul>\n<p>[java]<\/p>\n<p>@Override<br \/>\nboolean canHandle(AgentConfig agentConfig) {<br \/>\n\/\/ return true in case\u00a0agentConfig.getTransportURI() matches the one for our own replication agent<br \/>\n}<\/p>\n<p>@Override<br \/>\nReplicationResult deliver(TransportContext transportContext, ReplicationTransaction replicationTransaction) throws ReplicationException {<br \/>\n\/\/ return\u00a0ReplicationResult.OK in case of successful indexing. In this case content is deleted from the queue.<br \/>\n}<\/p>\n<p>[\/java]<\/p>\n<p>This way you can customize and manage your own transport handler and have full control over it.<\/p>\n<p>Hope this helps!!<\/p>\n<p>Vivek Sachdeva<br \/>\n@vivek_sach<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While integrating ElasticSearch with AEM, I used\u00a0custom replication agent, for indexing data to \u00a0ElasticSearch 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 &#8220;201 OK&#8221; response but the replication agent considers only &#8220;200&#8221; [&hellip;]<\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":24},"categories":[1],"tags":[4847,1207,1531],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15735"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15735"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15735\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}