Use reverse replication

How do I use reverse replication and what's necessary to make sure that it works?

Out-of-the box, only cq:Page nodes are reverse replicated. For any other node, it's necessary to use the two last methods, as a project-specific implementation.

There are three possibilities

  • Use the SlingPostServlet (that is, do not create any custom post servlets or POST.jsp to handle the incoming requests) so that it implicitly triggers a related PageEvent. Then set a property name "cq:distribute" and set its value to "true" on the nodes you want to reverse replicate.
    • To implement this solution, it's unnecessary to write any code. You can use the Form component to set all the necessary hidden fields.
  • Use your own code that accesses the repository, modify the properties "cq:lastModified," "cq:lastModifiedBy" and "cq:distribute."
    • Posted data can be controlled, internal code writes the data.
    • To implement this solution, it's necessary to write the code for your project.
  • Use your own code that calls the replicate method from Replicator service with options to use distribution mode.
    • Replication is controlled from your code.
    • To implement this solution, write the code specific for your project.

Use your own code to implement a reverse replication solution

  • Add the following code to fire the event related to the page you want to reverse replicate (the example below was extracted from sample PostDataServlet.java):
...
  // set the page to hide in the navigation
  Node pageContainer = newCommentPage.getContentResource().adaptTo(Node.class);
  pageContainer.setProperty("cq:lastModified", Calendar.getInstance());
  pageContainer.setProperty("cq:lastModifiedBy", session.getUserID());
  pageContainer.setProperty("cq:distribute", true);
...
  session.save();
...

 

Attached is an example using a component to render the form and display the previous post. For each post, it creates a subpage that contains a paragraph with text in it. By doing so, it ensures that each post can be managed separately (and avoids collision with posts that could be generated from other publish instances). The storage location is defined as a parameter in the component dialog (that is, /content/usergenerated/comments/form1, which you can create using a folder in the siteadmin).

On the author instance, you can define a workflow model that would be launched when a page is created below your comments page.

Make sure that you clear the cq:distribute value in your workflow, if you reactivate the content on author to the publish, otherwise it goes in an endless loop !!!

On the publish instance, make sure that the user has sufficient rights to create content. If you test with anonymous, then change the rights accordingly using CRX Explorer for the given jcr path).

Note on replication

For replication to work properly then store data with the following rules:
(1) the replicated (root) node's nodetype must extend nt:hierarchyNode
(2) all direct child nodes that are not nt:hierarchyNodes must be aggregated
(3) the subtrees of all nodes from (2), apart from nodetypes, must be aggregated

Adobe recommends to use the cq:Page (/jcr:content) as container for your data, as you can then easily manage it and use it with the user interface (siteadmin, and so on). You can use PageManager API to create the page.

Logs on the publish showing reverse replication outgoing

07.04.2010 11:58:04.398 *INFO* [ReplicateOnModification Processor] class com.day.cq.replication.impl.queue.Queue.outbox      Replication request queued for outbox at /content/usergenerated/comments/form1/c1270634282059-715.
07.04.2010 11:58:04.474 *INFO* [ReplicateOnModification Processor] com.day.cq.replication.impl.ReplicatorImpl Processed replication: setup 1ms, pre 275ms, build 41ms, queued 1ms, status 76ms, total 394ms
07.04.2010 11:58:04.474 *INFO* [ReplicateOnModification Processor] com.day.cq.wcm.core.impl.event.ReplicateOnModification Auto-Replicated ACTIVATE of /content/usergenerated/comments/form1/c1270634282059-715

Logs on the author showing reverse replication incoming

07.04.2010 12:09:22.360 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse Sending GET request to http://localhost:4503/bin/receive?sling:authRequestLogin=1
07.04.2010 12:09:22.384 *INFO* [Reverse Replication Processor] com.day.cq.replication.impl.AgentManagerImpl Created new repository content at /var/replication/data/publish_reverse/eed89cd3-a832-4833-bec7-7fa4e474c359
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse sent. Resonse: 200 OK
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse ------------------------------------------------
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse Sending message to localhost:4503
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse >> GET /bin/receive HTTP/1.0
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse >> Action: {action}
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse >> Path: {path}
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse >> Handle: {path}
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse --
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << HTTP/1.1 200 OK
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << Connection: Keep-Alive
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << Server: Day-Servlet-Engine/4.1.8
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << Content-Type: application/octet-stream
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << Content-Length: 1486
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse << Date: Wed, 07 Apr 2010 10:09:22 GMT
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse Message sent.
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse ------------------------------------------------
07.04.2010 12:09:22.385 *INFO* [Reverse Replication Processor] com.day.cq.replication.Agent.publish_reverse Reverse replication successful.
07.04.2010 12:09:22.460 *INFO* [Reverse Replication Processor] com.day.cq.replication.content.durbo.DurboImporter imported content in 68ms for durbo request on path: /content/usergenerated/comments/form1/c1270634936890-882

Stáhnout

 

Other Related Articles:

 Adobe

Získejte pomoc rychleji a snáze

Nový uživatel?