如何动态更改ZooKeeper-Master-Component骆驼组件中的zookeeper网址?

时间:2019-11-03 17:45:52

标签: apache-camel

我用骆驼和卡拉夫作为容器 我创建了一个捆绑包,其中包含我作为服务导出的curatorFramework bean的构造:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"

    xsi:schemaLocation="
        http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
        http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
        "
    default-activation="lazy">

    <cm:property-placeholder persistent-id="cluster.zookeepermaster" update-strategy="reload">
        <cm:default-properties>
            <cm:property name="zookeeper-cluster-master.id" value="node-zk" />
            <cm:property name="zookeeper-cluster-master.basePath" value="/camel/cluster/tesb" />
            <!-- nodes = list of zookeeper nodes separeted bt , ie host1:port1,host2:port2 -->
            <cm:property name="zookeeper-cluster-master.nodes" value="localhost:2181" />
        </cm:default-properties>
    </cm:property-placeholder>
<bean id="curator" class="org.apache.curator.framework.CuratorFrameworkFactory" factory-method="newClient" destroy-method="close" init-method="start">
  <argument value="${zookeeper-cluster-master.nodes}"/>
  <argument value="${zookeeper-cluster-master.session-timeout-ms}"/>
  <argument value="${zookeeper-cluster-master.connection-timeout-ms}"/>
  <argument type="org.apache.curator.RetryPolicy">
     <bean class="org.apache.curator.retry.ExponentialBackoffRetry">
        <argument value="${zookeeper-cluster-master.base-sleep-time-ms}"/>
        <argument value="${zookeeper-cluster-master.max-retries}"/>
        <argument value="${zookeeper-cluster-master.max-sleep-ms}"/>
     </bean>
  </argument>
</bean>

<service ref="curator" interface="org.apache.curator.framework.CuratorFramework" />
</blueprint>

然后在我的骆驼路线中,我将导出的服务注入到MasterComponent组件(ZooKeeper-Master-Component)中:

<bp:blueprint xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:camel="http://camel.apache.org/schema/blueprint" xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
            http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
            http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

...
<bean id="zookeeper-master" class="org.apache.camel.component.zookeepermaster.MasterComponent">
<property name="curator" ref="curator"/>
</bean>
<bp:reference id="curator" interface="org.apache.curator.framework.CuratorFramework"/>
...
</bp:blueprint>

当我更改/etc/cluster.zookeepermaster中的属性(例如url ==> zookeeper-cluster-master.nodes)时,束会重新启动,但 更改不会传播到MasterComponent组件。 我的方法好还是应该以不同的方式进行?

0 个答案:

没有答案