Just another blog.

How stop embedded ActiveMQ in Spring

Java

Today I ran into problems with embedded ActiveMQ broker in Spring Framework. The goal is to run local application, which uses Spring context to start AMQ and after this application is finished, AMQ should stop.

My setup of spring context xml is following (I’m using the amq schema and this is only the needed part).

<amq:broker id="broker" useJmx="false" persistent="false" start="true"  >
  <amq:transportConnectors>
    <amq:transportConnector uri="tcp://localhost:0" />
  </amq:transportConnectors>
</amq:broker>
<amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/>
<amq:queue id="replyQueue" physicalName="replyQueue" />
<amq:queue id="requestQueue" physicalName="requestQueue" />

And the app looks like this:

context = new ClassPathXmlApplicationContext("client-local-context.xml");

 ComputingStarterService computingStarterService = (ComputingService)context.getBean("computingStarterService");
 computingStarterService.start("Test");

And the problem is, that the main part of application stops, but the AMQ is still running. I tried a lot of things and the only working thing is to use

context.close();

I don’t know if there is another way to stop embedded AMQ. How it works eg. in JUnit tests?

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>