You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by maorbl <ma...@gmail.com> on 2018/05/13 12:50:02 UTC
Add multiple network connectors dynamically
Hi,
When adding a network connector, the first one goes OK:
// create network connector over JMX
ObjectName brokerObjectName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker1Name);
BrokerViewMBean proxyBroker = (BrokerViewMBean)
broker.getManagementContext().newProxyInstance(brokerObjectName,
BrokerViewMBean.class, true);
// add the NC
proxyBroker.addNetworkConnector("static://"+urlBroker2);
Sometime after I try to add another one:
brokerObjectName = new
ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker1Name);
proxyBroker = (BrokerViewMBean)
broker.getManagementContext().newProxyInstance(brokerObjectName,
BrokerViewMBean.class, true);
// let's add the NC
networkConnectorName =
proxyBroker.addNetworkConnector("static://"+urlBroker3);
This time it fails.
Caused by: javax.management.InstanceAlreadyExistsException:
org.apache.activemq:type=Broker,brokerName=ig2-1,connector=networkConnectors,networkConnectorName=NC
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
I understand that it fails on InstanceAlreadyExistsException, but I don't
know
how to overcome it.
A workaround is to remove the fist network connector
proxyBroker.removeNetworkConnector("NC");
and then add both network connectors:
proxyBroker.addNetworkConnector("static://"+urlBroker2+","+urlBroker3);
Any help will be appreciated.
Thanks,
Maor
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Re: Add multiple network connectors dynamically
Posted by Tim Bain <tb...@alumni.duke.edu>.
Great, thanks for sharing the code in case someone else has the same
question in the future.
Tim
On Tue, May 22, 2018, 11:37 PM maorbl <ma...@gmail.com> wrote:
> Just wanted to update that eventually I added the network connectors
> not with the proxy (BrokerViewMBean), but with the broker itself
> (BrokerService).
> This is the code that adds a new network connector (similar to how
> activemq code handles a new network connector):
>
>
> NetworkConnector networkConnector =
> m_broker.addNetworkConnector(friendBrokerUrl);
> networkConnector.setName(DEFAULT_NETWORK_CONNECTOR_NAME + "_" +
> friendBrokerName + "_" + serviceName.toLowerCase());
> networkConnector.setLocalUri(m_broker.getVmConnectorURI());
> networkConnector.setBrokerName(m_broker.getBrokerName());
>
>
> networkConnector.setDurableDestinations(m_broker.getBroker().getDurableDestinations());
> if(m_broker.getDefaultSocketURIString() != null) {
>
> networkConnector.setBrokerURL(m_broker.getDefaultSocketURIString());
> }
>
> // register network connector MBean
> m_broker.registerNetworkConnectorMBean(networkConnector);
>
> // start network connector
> networkConnector.start();
>
>
>
> --
> Sent from:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
>
Re: Add multiple network connectors dynamically
Posted by maorbl <ma...@gmail.com>.
Just wanted to update that eventually I added the network connectors
not with the proxy (BrokerViewMBean), but with the broker itself
(BrokerService).
This is the code that adds a new network connector (similar to how
activemq code handles a new network connector):
NetworkConnector networkConnector =
m_broker.addNetworkConnector(friendBrokerUrl);
networkConnector.setName(DEFAULT_NETWORK_CONNECTOR_NAME + "_" +
friendBrokerName + "_" + serviceName.toLowerCase());
networkConnector.setLocalUri(m_broker.getVmConnectorURI());
networkConnector.setBrokerName(m_broker.getBrokerName());
networkConnector.setDurableDestinations(m_broker.getBroker().getDurableDestinations());
if(m_broker.getDefaultSocketURIString() != null) {
networkConnector.setBrokerURL(m_broker.getDefaultSocketURIString());
}
// register network connector MBean
m_broker.registerNetworkConnectorMBean(networkConnector);
// start network connector
networkConnector.start();
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Re: Add multiple network connectors dynamically
Posted by maorbl <ma...@gmail.com>.
Hi Tim,
Thanks a lot for your answer!
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Re: Add multiple network connectors dynamically
Posted by Tim Bain <tb...@alumni.duke.edu>.
This appears to be a consequence of the fact that
org.apache.activemq.network.NetworkBridgeConfiguration.name is defaulted to
"NC" and there's not a simple way to set it to another value when calling
org.apache.activemq.broker.jmx.BrokerView.addNetworkConnector(String) nor
to rename it after it's created. (Or at least, not one that I, as someone
who's not very familiar with that code, see.)
I'd suggest you submit an enhancement request in JIRA to ask for a
BrokerView.addNetworkConnector(String discoveryAddress, String
networkConnectorName) method to be added, to allow the name to be specified
by the caller.
Tim
On Sun, May 13, 2018 at 6:50 AM, maorbl <ma...@gmail.com> wrote:
> Hi,
>
> When adding a network connector, the first one goes OK:
> // create network connector over JMX
> ObjectName brokerObjectName = new
> ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker1Name);
>
> BrokerViewMBean proxyBroker = (BrokerViewMBean)
> broker.getManagementContext().newProxyInstance(brokerObjectName,
> BrokerViewMBean.class, true);
> // add the NC
> proxyBroker.addNetworkConnector("static://"+urlBroker2);
>
> Sometime after I try to add another one:
>
> brokerObjectName = new
> ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker1Name);
> proxyBroker = (BrokerViewMBean)
> broker.getManagementContext().newProxyInstance(brokerObjectName,
> BrokerViewMBean.class, true);
> // let's add the NC
> networkConnectorName =
> proxyBroker.addNetworkConnector("static://"+urlBroker3);
>
> This time it fails.
>
> Caused by: javax.management.InstanceAlreadyExistsException:
> org.apache.activemq:type=Broker,brokerName=ig2-1,
> connector=networkConnectors,networkConnectorName=NC
> at com.sun.jmx.mbeanserver.Repository.addMBean(
> Repository.java:437)
>
> I understand that it fails on InstanceAlreadyExistsException, but I don't
> know
> how to overcome it.
>
> A workaround is to remove the fist network connector
> proxyBroker.removeNetworkConnector("NC");
>
> and then add both network connectors:
> proxyBroker.addNetworkConnector("static://"+urlBroker2+","+urlBroker3);
>
> Any help will be appreciated.
>
> Thanks,
> Maor
>
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>