You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by rranjan <rr...@2wire.com> on 2009/09/09 23:59:27 UTC

Embedding activeMQ stops automatically

I have a basic requirement that I am struggling with for the last 3 days.

I want to create a zip file which contains the required Jar files from my
application and the activeMQ jars. I want activeMQ to be embedded into my
JVM.

In order to do this I followed the instructions and created a spring
configuration that looks as below.
<bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
    <property name="config" value="classpath:activemq.xml" />
    <property name="start" value="true" />
  </bean>

I have a basic Java class with a main method that loads the spring config.
The main method has a single line.
ApplicationContext context = new
ClassPathXmlApplicationContext("config.xml");

In my activeMQ.xml I provided the basic needs of my app and it looks as
follows.
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd   
  http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

    <!-- Allows us to use system properties as variables in this
configuration file -->
    <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="locations">
            <value>classpath:credentials.properties</value>
         </property>      
    </bean>
    <broker xmlns="http://activemq.apache.org/schema/core"
brokerName="localhost"  dataDirectory="${home}/data" >
        <!-- Destination specific policies using destination names or
wildcards -->
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" memoryLimit="5mb"/>
                    <policyEntry topic=">" memoryLimit="5mb">
                      <!-- you can add other policies too such as these
                        <dispatchPolicy>
                            <strictOrderDispatchPolicy/>
                        </dispatchPolicy>
                        <subscriptionRecoveryPolicy>
                            <lastImageSubscriptionRecoveryPolicy/>
                        </subscriptionRecoveryPolicy>
                      -->
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <!-- Use the following to configure how ActiveMQ is exposed in JMX
-->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <persistenceAdapter>
            <amqPersistenceAdapter syncOnWrite="false"
directory="${home}/data" maxFileLength="20 mb"/>
        </persistenceAdapter>

        <!--  The maximum about of space the broker will use before slowing
down producers -->
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>
        <!-- The transport connectors ActiveMQ will listen to -->
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://localhost:61616"
discoveryUri="multicast://default"/>
        </transportConnectors>
    </broker>
</beans>
<!-- END SNIPPET: example -->

When I start my app I see that the activeMQ server is started but it shuts
down immediately.
2009-09-09 14:56:44,830 [MQ ShutdownHook] INFO  BrokerService                 
- ActiveMQ Message Broker (localhost,
ID:rranjan.2wire.com-60937-1252533403938-0:0) is shutting down
2009-09-09 14:56:44,834 [MQ ShutdownHook] DEBUG BrokerService                 
- Caught exception, must be shutting down: java.lang.IllegalStateException:
Shutdown in progress

I'm assuming someone send a kill message or a stop request. 

I modified my Java startup class to the following to keep the thread alive.
ApplicationContext context = new
ClassPathXmlApplicationContext("config.xml");
		boolean shouldRun = true;
		while (shouldRun){
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				shouldRun = false;
			}
		}

I see that now activeMQ happily starts up.

Any clues why? 
-- 
View this message in context: http://www.nabble.com/Embedding-activeMQ-stops-automatically-tp25373857p25373857.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Embedding activeMQ stops automatically

Posted by Rob Davies <ra...@gmail.com>.
All the threads in the broker are daemon threads - you'll need your  
application to have at least one thread alive -  which looks like what  
you've now done in keeping the main thread going ;)

On 9 Sep 2009, at 22:59, rranjan wrote:

>
> I have a basic requirement that I am struggling with for the last 3  
> days.
>
> I want to create a zip file which contains the required Jar files  
> from my
> application and the activeMQ jars. I want activeMQ to be embedded  
> into my
> JVM.
>
> In order to do this I followed the instructions and created a spring
> configuration that looks as below.
> <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
>    <property name="config" value="classpath:activemq.xml" />
>    <property name="start" value="true" />
>  </bean>
>
> I have a basic Java class with a main method that loads the spring  
> config.
> The main method has a single line.
> ApplicationContext context = new
> ClassPathXmlApplicationContext("config.xml");
>
> In my activeMQ.xml I provided the basic needs of my app and it looks  
> as
> follows.
> <beans
>  xmlns="http://www.springframework.org/schema/beans"
>  xmlns:amq="http://activemq.apache.org/schema/core"
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>  http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd
>  http://activemq.apache.org/camel/schema/spring
> http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
>
>    <!-- Allows us to use system properties as variables in this
> configuration file -->
>    <bean
> class 
> = 
> "org 
> .springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>         <property name="locations">
>            <value>classpath:credentials.properties</value>
>         </property>
>    </bean>
>    <broker xmlns="http://activemq.apache.org/schema/core"
> brokerName="localhost"  dataDirectory="${home}/data" >
>        <!-- Destination specific policies using destination names or
> wildcards -->
>        <destinationPolicy>
>            <policyMap>
>                <policyEntries>
>                    <policyEntry queue=">" memoryLimit="5mb"/>
>                    <policyEntry topic=">" memoryLimit="5mb">
>                      <!-- you can add other policies too such as these
>                        <dispatchPolicy>
>                            <strictOrderDispatchPolicy/>
>                        </dispatchPolicy>
>                        <subscriptionRecoveryPolicy>
>                            <lastImageSubscriptionRecoveryPolicy/>
>                        </subscriptionRecoveryPolicy>
>                      -->
>                    </policyEntry>
>                </policyEntries>
>            </policyMap>
>        </destinationPolicy>
>
>        <!-- Use the following to configure how ActiveMQ is exposed  
> in JMX
> -->
>        <managementContext>
>            <managementContext createConnector="false"/>
>        </managementContext>
>
>        <persistenceAdapter>
>            <amqPersistenceAdapter syncOnWrite="false"
> directory="${home}/data" maxFileLength="20 mb"/>
>        </persistenceAdapter>
>
>        <!--  The maximum about of space the broker will use before  
> slowing
> down producers -->
>        <systemUsage>
>            <systemUsage>
>                <memoryUsage>
>                    <memoryUsage limit="20 mb"/>
>                </memoryUsage>
>                <storeUsage>
>                    <storeUsage limit="1 gb" name="foo"/>
>                </storeUsage>
>                <tempUsage>
>                    <tempUsage limit="100 mb"/>
>                </tempUsage>
>            </systemUsage>
>        </systemUsage>
>        <!-- The transport connectors ActiveMQ will listen to -->
>        <transportConnectors>
>            <transportConnector name="openwire" uri="tcp://localhost: 
> 61616"
> discoveryUri="multicast://default"/>
>        </transportConnectors>
>    </broker>
> </beans>
> <!-- END SNIPPET: example -->
>
> When I start my app I see that the activeMQ server is started but it  
> shuts
> down immediately.
> 2009-09-09 14:56:44,830 [MQ ShutdownHook] INFO  BrokerService
> - ActiveMQ Message Broker (localhost,
> ID:rranjan.2wire.com-60937-1252533403938-0:0) is shutting down
> 2009-09-09 14:56:44,834 [MQ ShutdownHook] DEBUG BrokerService
> - Caught exception, must be shutting down:  
> java.lang.IllegalStateException:
> Shutdown in progress
>
> I'm assuming someone send a kill message or a stop request.
>
> I modified my Java startup class to the following to keep the thread  
> alive.
> ApplicationContext context = new
> ClassPathXmlApplicationContext("config.xml");
> 		boolean shouldRun = true;
> 		while (shouldRun){
> 			try {
> 				Thread.sleep(10000);
> 			} catch (InterruptedException e) {
> 				shouldRun = false;
> 			}
> 		}
>
> I see that now activeMQ happily starts up.
>
> Any clues why?
> -- 
> View this message in context: http://www.nabble.com/Embedding-activeMQ-stops-automatically-tp25373857p25373857.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Rob Davies
I work here: http://fusesource.com
My Blog: http://rajdavies.blogspot.com/
I'm writing this: http://www.manning.com/snyder/