Hi

You should use a servlet this is how web apps is supposed to be
deployed and have your apps lifecycle handled by the container.


On Mon, Mar 5, 2012 at 4:00 PM, ShlomiJ <shlomij...@gmail.com> wrote:
> Tomcat
>
> A servlet, which is set to be initialized on startup using Tomcat's
> <load-on-startup>1</load-on-startup> in web.xml, initiates a singleton. That
> singleton holds a CamelContext member.
> This context is initialized exactly as described in my previous post, except
> for the try/catch (this is simply because that the method in the singleton
> that initializes the context declares throwing exception, which the servlet
> catches).
> There is no XML here.
>
> CamelContext context = new DefaultCamelContext();
>>
>> String brokerUri =
>> "failover:(tcp://localhost:61616)?maxReconnectAttempts=-1&initialReconnectDelay=10000";
>> ConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory(brokerUri);
>> context.addComponent("jms",
>> JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
>>
>> context.addRoutes(new RouteBuilder() {
>>
>>               @Override
>>               public void configure() throws Exception
>>               {
>>                               from("jms:queueName")
>>                               .log("${body}");
>>               }
>> });
>> context.start();
>
> Standalone - Spring Style
>
> My main class initiates a org.apache.camel.spring.Main and sets its
> camel-context.xml.
> org.apache.camel.spring.Main.start() is called.
> org.apache.camel.spring.Main.enableHangupSupport is NOT called.
> The camel configuration is as described in my first post.
>
> <bean id="jmsConnectionFactory"
> class="org.apache.activemq.ActiveMQConnectionFactory">
>>       <property name="brokerURL"
>> value="failover:(tcp://localhost:61616)?maxReconnectAttempts=-1&initialReconnectDelay=10000"
>> />
>> </bean>
>> <bean id="pooledConnectionFactory"
>> class="org.apache.activemq.pool.PooledConnectionFactory">
>>       <property name="maxConnections" value="8" />
>>       <property name="maximumActive" value="500" />
>>       <property name="connectionFactory" ref="jmsConnectionFactory" />
>> </bean>
>> <bean id="jmsConfig"
>> class="org.apache.camel.component.jms.JmsConfiguration">
>>       <property name="connectionFactory" ref="pooledConnectionFactory"/>
>>       <property name="transacted" value="false"/>
>>       <property name="concurrentConsumers" value="20"/>
>> </bean>
>> <bean id="activemq"
>> class="org.apache.activemq.camel.component.ActiveMQComponent">
>>       <property name="configuration" ref="jmsConfig"/>
>> </bean>
>>
>> <camel:camelContext id="camel"
>> xmlns="http://camel.apache.org/schema/spring";>
>>       <camel:route>
>>               <camel:from uri="activemq:queue:queueName"/>
>>               <camel:log message="${body}" />
>>       </camel:route>
>> </camel:camelContext>
>
> Standalone - Java Style
>
> In this solution my main class creates a new Thread T with an anonymous
> Runnable, and calls T.start().
> The runnable's run method is as described below.
> There is no XML here.
>
> CamelContext context = new DefaultCamelContext();
>>
>> String brokerUri =
>> "failover:(tcp://localhost:61616)?maxReconnectAttempts=-1&initialReconnectDelay=10000";
>> ConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory(brokerUri);
>> context.addComponent("jms",
>> JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
>>
>> try {
>>         context.addRoutes(new RouteBuilder() {
>>
>>                 @Override
>>                 public void configure() throws Exception
>>                 {
>>                         from("jms:queueName")
>>                         .log("${body}");
>>                 }
>>         });
>>         context.start();
>> } catch (Exception e) {
>>         e.printStackTrace();
>> }
>
> So we have 2 solutions with a standalone main, one with spring DSL and the
> other with Java. In both, the application crashes upon ActiveMQ restart.
> And we have one solution in a Tomcat container, using Java. Here the
> application does not crash upon ActiveMQ restart, and a connection is
> successfully established once the broker is up again.
> In ALL of the solutions the application was able to *start before* the
> broker, and later establish a connection once the broker has started (but
> again, 2 of them did not stand during a broker shutdown).
>
> thanks
> SJ
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-crashes-upon-ActiveMQ-shutdown-tp5534910p5537761.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to