Could somebody pls check this....... I originally posted it in the MediationRouter forums but got told to post it here instead.
Why do you need to use?
Camel spring main app is a development tool for quickly trying out camel.
It has newer been targeted as production usage. Most people use some sort of server for that.
There may bee a problem in the startup logic.
Can you create a small camel application that demonstrates this. Eg try removing as much of your application and it still fails. Then we can use that to track down the issue and add it as an unit test as well.
Thanks for the answer. I am using this statement because I need to send something to a Camel endpoint (a queue in fact) from within my code.
This is how our application works:
(1) Our application server is based only on Camel and ActiveMQ. We start our application by directly invoking the Spring Main.main(springConfigFile) passing in our camel-server.xml file. Within the XML file, we declare a local broker and so activeMQ is started. We also declare a JmsComponent bean which references another broker which may or may not be up at this time.
(2) At this point after Camel has initialized, we expect that if we execute the code Main.getInstance().getApplicationContext() within the same JVM as Camel, it should return a context but it fails to do so if failover is used and does not connect to the remote broker.
(3) We start a totally separate home-made TCP server application. This application is a client to the Camel/ActiveMQ Server. It sends messages to our ActiveMQ instance in (1) using the request/reply pattern. This means that a queue is defined to handle incoming requests and a temporary queue is used to send back the reply.
(4) When the client in (3) sends a request to the application in (1), a bean is called to handle the incoming request on the server side (1). This bean does some business logic processing and then before it returns something back to the client (3), it wants to put a message on a local queue programmatically for some asynchronous processing. This is why we need to call Main.getInstance().getApplicationContext() because although we are within the same JVM as the running Camel Instance, at this point of the thread of execution we have no reference to Camel and therefore cannot send anything to a queue. The entire code we want execute is:
camelContext = Main.getInstance().getApplicationContext();
// Create a producer template
camelTemplate = (ProducerTemplate) camelContext.getBean("camelTemplate");
// Send to queue
We are not using an application server of any type, just Camel and ActiveMQ. We were not aware that starting Camel like this was just for development purposes so please feel free to suggest a better way of launching our application if we are missing something fundamental.
Thanks a lot
Not having the source in front of me at the moment. Gotta go soon, so no time to start the IDE editor.
I assume you can get hold of CamelContext without the spring application context.
And use getRegistry().lookup to lookup your bean
And you can also use the method: createNewProducerTemplate on CamelContext to get a template instead of doing lookup.
You can disable the autoStartup of the JMS consumer
And then Camel should be able to startup and you should get your application context.
Then you can manually start the JMS consumer afterwards
Hi use the option maxReconnectAttempts on the brokerURL to limit the number of retries.
For example maxReconnectAttempts=5
Many thanks for suggestions and opening issue. Will probably take the option of manually starting the consumer afterwards since we need to keep retrying the connection as it is major part of application.