Skip to content

Adding zookeeper.xml

rmuthupandian edited this page Feb 11, 2015 · 1 revision

Zookeeper service needs different configuration in different environments (dev, qa, prod). There is a simple way to utilize system property to specify the zookeeper server configuration: jetstream.runtime.zkserver.host and jetstream.runtime.zkserver.port. If it is not specified, it can be localhost and 2181.

And the zookeeper can also support multiple zk host configuration. Each zk host will be an instance of ZooKeeperNode and add it into the zknodes list. This can not be overwrite by the system configuration but it can utilize spring profile to separate the configuration for different environment.

  1. Create a xml file and name it "zookeeper.xml"
  2. Copy below content into it:
   <beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation=" 
           http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
   
       <bean id="zookeeper" class="com.ebay.jetstream.messaging.transport.zookeeper.ZooKeeperTransportConfig">
           <property name="transportClass" value="com.ebay.jetstream.messaging.transport.zookeeper.ZooKeeperTransport" />
           <property name="transportName" value="zookeeper" />
           <property name="protocol" value="tcp" />
           <property name="contextList">
               <list>
                   <bean class="com.ebay.jetstream.messaging.config.ContextConfig">
                       <property name="contextname" value="Rtbdpod.local" />
                   </bean>
                   <bean class="com.ebay.jetstream.messaging.config.ContextConfig">
                       <property name="contextname" value="Rtbdpod.Messaging" />
                   </bean>
               </list>
           </property>
           <property name="sessionTimeoutInMillis" value="300000" />
           <property name="zknodes">
               <list>
                   <bean class="com.ebay.jetstream.messaging.transport.zookeeper.ZooKeeperNode">
                       <property name="hostname" value="#{systemProperties['jetstream.runtime.zkserver.host'] ?: 'localhost'}"></property>
                       <property name="port" value="#{systemProperties['jetstream.runtime.zkserver.port'] ?: 2181}"></property>
                   </bean>
               </list>
   
           </property>
       </bean>
   
   </beans>
  1. The transport instance named “zookeeper” is bound to two root contexts viz. “Rtbdpod.local” & “Rtbdpod.Messaging”. In addition it has a property named “zknodes” which specifies a list of zookeeper nodes to which this transport will establish connections with.

  2. In messagecontext.xml add ref to zookeeper.xml inside bean with id="MessageServiceProperties". Reference bean value should match the bean id used in zookeeper.xml. It will thus look like this

   <bean id="MessageServiceProperties"
   	class="com.ebay.jetstream.messaging.config.MessageServiceProperties">
   	<property name="nicUsage" ref="NICUsage" />
   	<!-- <property name="dnsMap" ref="DNSMap" /> -->
   	<property name="transports">
   		<list>
   			<ref bean="zookeeper" />
                         <!-- Netty Bean -->
                 </list>
        </property>
 </bean>
Clone this wiki locally