WSO2动态地将一个端点添加到LoadBalance端点 [英] WSO2 Dynamically Adding an EndPoint to LoadBalance Endpoint
问题描述
我有此配置:
1)WSO2 4.7.0 ESB
1) WSO2 4.7.0 ESB
2)WSO2 MB 2.1.0
2) WSO2 MB 2.1.0
3)主题= MyTopic
3) a topic = MyTopic
4)MyTopic的一名订阅者
4) one subscriber to MyTopic
5)MyTopic上的 N 个发布者
5) N publishers on MyTopic
6)在ESB上部署了静态LoadBalance端点
6) Static LoadBalance Endpoint deployed on ESB
我的目标是,当 N 个端点之一在MyTopic上发布消息时,ESB上的订户应该能够将端点添加到LoadBalanceEndpoint
列表中.
My goal is that when one of the N endpoints publishes a message on MyTopic, the subscriber on the ESB should be able to add an endpoint to the LoadBalanceEndpoint
list.
有可能吗?我是否需要使用DynamicLoadBalanceEndpoint,如果需要,如何使用?
Is that possible? Do I need to use DynamicLoadBalanceEndpoint, and if so, how?
推荐答案
好,我自己找到了答案. 可以通过访问WSO2注册表来完成. 您必须将负载均衡点保存到注册表中. 然后参考这些链接
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)下面说明了访问注册表的方式: http://vvratha.blogspot.it/2013/02 /accessing-registry-resources-from-class.html
1) here is illustrated the way you can access the registry: http://vvratha.blogspot.it/2013/02/accessing-registry-resources-from-class.html
2)在这里,您可以找到如何将regInstance.getResource(resourceKey)生成的OMElment转换为LoadBalance端点
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)通过此代码,您可以为其添加新的AddressEndpoint:
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)添加地址点后,请使用
4) After you have added the address point use the
regInstance.updateResource("key", LoadbalanceEndpointSerializer.getElementFromEndpoint(endpoint));
声明以更新注册表.
这是在本地注册表上工作的完整代码:
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));
这篇关于WSO2动态地将一个端点添加到LoadBalance端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!