2

I have several different fuse bundles, some with camel routes defined in their own camel contexts.

I would like to access all the camel contexts from a single bundle.

Something like:

fuse.getCamelContext("someOtherCamelContextId")

or maybe:

fuse.getBundleContext("someOtherBundleName").getCamelContext("someOtherCamelContextId")

I am aware of how to implement a CamelContextAware class and inject it using spring, however, that only gives access to the local camel context.

Fuse does record service ids for the camel contexts - is there a way to look them up?

Or does Fuse only allow access to a bundles services to that bundle??

thanks!

Peter Keller
  • 7,526
  • 2
  • 26
  • 29
sicotron
  • 245
  • 2
  • 9
  • well here is a solution of sorts, although it would need a fair amount of _reflection_ to get it to work! I can inject the blueprintContainer into an object and from there, when debugging I can find the other bundles camelContext. blueprintContainer.registration.m_registry.m_regsMap[""].value[].m_ref registration is a private field on the BlueprintContainerImpl class though - so I'm going to try and use reflection to get through this and will update here accordingly – sicotron Jun 10 '14 at 03:31
  • Can you explain the reason for accessing other camel context in difference bundle? I hope NMR endpoint can be used for inter-bundle communication and if you need only the data through processing through these bundles then you can use the NMR endpoint and retrieve the processed data from other bundles. – Naveen Raj Jun 10 '14 at 05:27
  • We have a generic component that is used to write to an activeMQ endpoint. I need that generic component to take notice of the camel routes in other contexts (specifically intercepts) when writing to that endpoint. So I need to change the generic component to write via a camel context instead. – sicotron Jun 10 '14 at 22:28
  • I suppose you can still use a common bundle with a NMR endpoint which will write to active mq. You can call that bundle as a In-out pattern and use to call other bundles. In the other bundle you can have as many routes as possible and you can use only one route for this purpose.GO through this link : http://camel.apache.org/nmr.html – Naveen Raj Jun 11 '14 at 05:01

2 Answers2

1

Here it is with an example!

ServiceReference[] srs = bundleContext.getServiceReferences(CamelContext.class.getName(), "(camel.context.name=myother-camel-context-name)");
CamelContext camelContext = (CamelContext) bundleContext.getService(srs[0])

Quite simple really...

sicotron
  • 245
  • 2
  • 9
  • and use this to get the bundleContext... http://stackoverflow.com/questions/6745004/how-could-i-get-bundlecontext-in-spring-dm – sicotron Jun 11 '14 at 00:28
0

The CamelContext is registered into the OSGi Service Registry. So just use that to lookup the CamelContexts, eg its standard OSGi how to do that.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • thanks for your answer Claus, I thought it should be that simple but was getting confused... Your answer helped point me in the right direction! – sicotron Jun 11 '14 at 00:32