Skip to content

Document replication

Dannes Wessels edited this page Dec 8, 2013 · 35 revisions

For the document [replication](http://en.wikipedia.org/wiki/Replication_(computing\)) feature two types of eXist-db instances are involved: The instance in which a document is added or modified (the producer or 'master' instance) and the instances that shall receive a copy of the document(change): the consumer or 'slave' instances.

The JMS broker receives the document from the producer instance and distributes the data to one or more consumer instances. Theoretically there is no limit on the number of consumer instances, the performance of the producer instance is independent of the number of consumer instances.

Producer (Master)

The replication extension uses eXist-db triggers to detect when document has been changed. Triggers must defined in collection.xconf files on a per collection basis.

The following XML example shows show to connect to an ActiveMQ server on the myserver.local host, the topic name is dynamicTopics/eXistdb:

<collection xmlns="http://exist-db.org/collection-config/1.0">
    <triggers>
        <trigger class="org.exist.replication.jms.publish.ReplicationTrigger">
            <!-- 
                Class name of the initial context provider, default value 
                for ActiveMQ
                see javax.naming.Context#INITIAL_CONTEXT_FACTORY
            -->
            <parameter name="java.naming.factory.initial" 
                value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/>
            <!-- 
                URL of the message broker, default value for ActiveMQ 
                see javax.naming.Context#PROVIDER_URL
            --> 
            <parameter name="java.naming.provider.url" 
                          value="tcp://myserver.local:61616"/>
            <!-- 
                Lookup connection factory
                see javax.naming.InitialContext#lookup(String) 
            -->
            <parameter name="connection-factory" value="ConnectionFactory"/>
            <!--
                Lookup destination (topic)
                see javax.naming.InitialContext#lookup(String) 
            -->
            <parameter name="destination" value="dynamicTopics/eXistdb"/>
        </trigger>
    </triggers>
</collection>

Consumer (Slave)

<!--
    Start JMS listener for listener of the clustering feature. 
-->
<trigger 
    class="org.exist.replication.jms.subscribe.MessageReceiverStartupTrigger">
    <!-- 
        Class name of the initial context provider, default value for ActiveMQ
        see javax.naming.Context#INITIAL_CONTEXT_FACTORY
    -->
    <parameter name="java.naming.factory.initial" 
        value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/>
    
    <!-- 
        URL of the message broker, default value for ActiveMQ
        see javax.naming.Context#PROVIDER_URL
    -->
    <parameter name="java.naming.provider.url" 
        value="tcp://myserver.local:61616"/>
    
    <!-- 
        Lookup connection factory
        see javax.naming.InitialContext#lookup(String) 
    -->
    <parameter name="connection-factory" value="ConnectionFactory"/>
    
    <!--
        Lookup destination (topic)
        see javax.naming.InitialContext#lookup(String) 
    -->
    <parameter name="destination" value="dynamicTopics/eXistdb"/>
    
    <!-- 
        Set the name used to identify this subscription
        see JMS javax.jms.TopicSession#createDurableSubscriber(Topic,String) 
    -->
    <parameter name="subscriber.name" value="SubscriptionId"/>
    
</trigger>
Clone this wiki locally