2016-08-16

I want to add a feature that leverages the AMQ built into JBoss FUSE, and which will start up with the container--i.e., will be added to the startup features, with start level <= 100.

This feature will immediately try to send some messages via AMQ, so I am hoping to add logic to 'listen' or simply wait for the broker start event.

The only handle I have on that currently is a logged message like:

Within my feature file, I tried creating a couple of feature dependencies, like:

...but that did not work. I also tried setting the start level to something in the 90's, but that did not work either.

Did I just miss something in these approaches?

Is there a relevant OSGi service that I could inject in my blueprint? -- i.e., maybe one that has some .isBrokerStarted() method?

My latest thought is that perhaps I can register a callback for an advisory message... will post this as an answer if it works.

Unfortunately, I no longer believe that an attempt to connect and listen to an advisory topic is a viable approach. I have deployed this feature. It works fine if installed after the above 'broker start' log message, but fails otherwise.

The problem seems to be that because the blueprint context initialization takes place while AMQ is asynchronously starting, any resulting connection(s) are invalid. I'd have thought that the AMQ connection factory, or the Camel component would opaquely provide some assurance against this condition. Apparently that is not so. Investigating their APIs (specifically, org.apache.activemq.ActiveMQSslConnectionFactory and org.apache.camel.component.jms.JmsConfiguration), I do not find a public method for status checking either... only the ability to set the "testConnectionOnStartup" property of the Camel component. Presumably this would have done as documented, and thrown 1+ Exceptions, but it has not. Very confusing.

UPDATE 24-AUG-2016:

finally had just a bit more time to work with this, and tried a couple things...
I put in a feature dependency on camel-amq, because it is at the 'top' of a feature dependency chain:

camel-amq -> depends on mq-fabric -> depends on activemq -> depends on activemq-client

This did not work. After tailoring the logging a bit more though, I believe that I have confirmed what I was hinting at above. Start-levels and feature dependencies cannot solve this problem as it stands. All of the dependent-features or bundles of lower start levels will report installed/started prior to the amq broker actually being ready (and logging the above message).

As such, my features will install, start, and fail--unless I can find a way to do just what the post title suggests: 'listen for AMQ broker start'. Does anyone know of a way to do this?

UPDATE 25-AUG-2016:

I see that ActiveMQServiceFactory (which logs the broker start message) itself has a handle on an instance of org.apache.activemq.broker.BrokerService local to its context. If this is also provided as an OSGi service, then I think that I may be able to wait on “broker.waitUntilStarted();” and then programmatically create my JMS connection. Will report back when I have time to try this...

Show more