0

我有这个配置:

1) WSO2 4.7.0 ESB

2) WSO2 MB 2.1.0

3) 一个主题 = MyTopic

4) MyTopic 的一名订阅者

5) MyTopic 上有N个出版商

6) 部署在 ESB 上的静态负载平衡端点

我的目标是当N个端点之一在 MyTopic 上发布消息时,ESB 上的订阅者应该能够将端点添加到LoadBalanceEndpoint列表中。

那可能吗?我是否需要使用 DynamicLoadBalanceEndpoint,如果需要,如何使用?

4

1 回答 1

1

ok i found the answer by myself. It can be done by accessing the WSO2 registry. You have to save the loadbalance enpoint into registry. Then make reference to these links

1) here is illustrated the way you can access the registry: http://vvratha.blogspot.it/2013/02/accessing-registry-resources-from-class.html

2)here you can find how to convert the OMElment resulting from the regInstance.getResource(resourceKey) into a LoadBalance endpoint https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/dependencies/synapse/2.1.1-wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/endpoints/LoadBalanceEndpointSerializationTest.java

3) by this code you can add a new AddressEndpoint to it:

    List<Endpoint>list = le.getChildren(); //le is LoadBalanceEndpoint instance
    AddressEndpoint ad = new AddressEndpoint();
    EndpointDefinition  def = new EndpointDefinition();
    def.setAddress("http:///your_address_url");
    def.setAddressingOn(false);
    def.setTimeoutAction(100);
    ad.setDefinition(def);
    list.add(ad);
    le.setChildren(list);

note: if you want to access the loadbalance endpoint and to modify it in memory, use this:

LoadbalanceEndpoint le =(LoadbalanceEndpoint) synapseMsgContext.getConfiguration().getEndpoint("test");

4) After you have added the address point use the

regInstance.updateResource("key", LoadbalanceEndpointSerializer.getElementFromEndpoint(endpoint));

statement to update the registry.

This is the full code for working on the local registry:

Registry regInstance = synapseMsgContext.getConfiguration()
            .getRegistry();                         
    Object obj = (Object) regInstance.getResource(new Entry("diogene/diogeneEndpoints.xml"),null);
    LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) LoadbalanceEndpointFactory.getEndpointFromElement((OMElement) obj, false, null);
    List<Endpoint>list = endpoint.getChildren();
    AddressEndpoint ad = new AddressEndpoint();
    EndpointDefinition  def = new EndpointDefinition();
    def.setAddress("http://your_address_url/");
    def.setAddressingOn(false);
    def.setTimeoutAction(100);
    ad.setDefinition(def);
    list.add(ad);
    endpoint.setChildren(list);
    regInstance.updateResource("key", LoadbalanceEndpointSerializer.getElementFromEndpoint(endpoint));
于 2013-11-28T09:04:35.517 回答