You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Jason Dillon <ja...@planet57.com> on 2011/12/09 00:50:49 UTC

Possible to add new transport connector post broker start?

Is it possible to add a new transport connector to a broker post starting the BrokerService?

I'd like to start up a broker w/o any transports for vm:// use only, but may need to configure a transport (tcp or ssl) after the application is already up and using the broker, so it would be a pita to stop the broker add the transport connector and then start it again.

Is this possible?  If so any thing to watch out for here?

--jason

Re: Possible to add new transport connector post broker start?

Posted by Jason Dillon <ja...@planet57.com>.
Is there a better place to ask this question?

BTW, looks like removeConnector(TransportConnector) also doesn't really stop the component even though the javadocs for the method indicate it will:

Stops and removes a transport connector from the broker.

Looks like it only removes the reference from the services collection of transport connectors and then attempts to unregister JMX components if JMX was enabled.

The following extension of BrokerService seem to resolve the add & remove issues.   Is there any reason why BrokerService does not behave like this OOTB?

<snip>
public class ExtBrokerService
    extends BrokerService
{
    /**
     * Allows adding and starting transport connector after the service has started.
     */
    @Override
    public TransportConnector addConnector(final TransportConnector connector) throws Exception {
        TransportConnector c = super.addConnector(connector);
        if (isStarted()) {
            c.setBrokerService(this);
            c = startTransportConnector(c);
        }
        return c;
    }

    /**
     * Actually stops the connector when removed if it was previously added.
     */
    @Override
    public boolean removeConnector(final TransportConnector connector) throws Exception {
        boolean result = super.removeConnector(connector);
        if (result) {
            ServiceStopper stopper = new ServiceStopper();
            stopper.stop(connector);
            stopper.throwFirstException();
        }
        return result;
    }
}
</snip>

--jason


On Dec 8, 2011, at 7:09 PM, Jason Dillon wrote:

> I tried this and found out that calling addConnector() post-start won't do anything.  But I can make a tiny sub-class that will:
> 
>    public class BrokerService2
>        extends BrokerService
>    {
>        @Override
>        public TransportConnector addConnector(final TransportConnector connector) throws Exception {
>            TransportConnector c = super.addConnector(connector);
>            if (isStarted()) {
>                c.setBrokerService(this);
>                c = startTransportConnector(c);
>            }
>            return c;
>        }
>    }
> 
> It looks like the setBrokerService() + startTransportConnector() are the calls that BrokerService.start() would end up calling anyways.
> 
> The above code also looks like it hooks up to the bits on shutdown, so BrokerService.stop() will actually stop this connector added post-start.
> 
> Does this look correct?
> 
> Is there any risk to adding a connector post-start like this?
> 
> --jason
> 
> 
> On Dec 8, 2011, at 3:50 PM, Jason Dillon wrote:
> 
>> Is it possible to add a new transport connector to a broker post starting the BrokerService?
>> 
>> I'd like to start up a broker w/o any transports for vm:// use only, but may need to configure a transport (tcp or ssl) after the application is already up and using the broker, so it would be a pita to stop the broker add the transport connector and then start it again.
>> 
>> Is this possible?  If so any thing to watch out for here?
>> 
>> --jason
> 


Re: Possible to add new transport connector post broker start?

Posted by Jason Dillon <ja...@planet57.com>.
I tried this and found out that calling addConnector() post-start won't do anything.  But I can make a tiny sub-class that will:

    public class BrokerService2
        extends BrokerService
    {
        @Override
        public TransportConnector addConnector(final TransportConnector connector) throws Exception {
            TransportConnector c = super.addConnector(connector);
            if (isStarted()) {
                c.setBrokerService(this);
                c = startTransportConnector(c);
            }
            return c;
        }
    }

It looks like the setBrokerService() + startTransportConnector() are the calls that BrokerService.start() would end up calling anyways.

The above code also looks like it hooks up to the bits on shutdown, so BrokerService.stop() will actually stop this connector added post-start.

Does this look correct?

Is there any risk to adding a connector post-start like this?

--jason


On Dec 8, 2011, at 3:50 PM, Jason Dillon wrote:

> Is it possible to add a new transport connector to a broker post starting the BrokerService?
> 
> I'd like to start up a broker w/o any transports for vm:// use only, but may need to configure a transport (tcp or ssl) after the application is already up and using the broker, so it would be a pita to stop the broker add the transport connector and then start it again.
> 
> Is this possible?  If so any thing to watch out for here?
> 
> --jason