The "CLIHelper" bean was introduced with release 8.0.0 and can be used to execute CLI commands on startup and/or shutdown of the Spring application. This is useful for unit tests. Example:
<bean id="CLIHelper"
class="com.swiftmq.jms.springsupport.CLIHelper"
init-method="initialize" destroy-method="destroy"
depends-on="swiftmqLauncher" singleton="true">
<property name="connectionFactory">
<ref bean="jndiConnectionFactory"/>
</property>
<property name="router">
<value>router1</value>
</property>
<property name="initCommands">
<list>
<value>cc /sys$queuemanager/queues</value>
<value>new q1</value>
<value>new q2</value>
<value>new q3</value>
<value>new q4</value>
</list>
</property>
<property name="destroyCommands">
<list>
<value>cc /sys$queuemanager/queues</value>
<value>delete q1</value>
<value>delete q2</value>
<value>delete q3</value>
<value>delete q4</value>
</list>
</property>
</bean>
The bean has 4 properties. "connectionFactory" is the JMS connection factory to use, "router" is the name of the managed router (the bean issues a "sr" command as the first command), "initCommands" is a list of commands to be executed when the bean initializes and "destroyCommands" are commands when the bean is destroyed (usually during shutdown).
The init-method can be set to "initialize" and destroy-method to "destroy". Both are optional. All commands defined in the "initCommands" property are executed when the bean intializes and all commands defined in "destroyCommands" are executed when the bean is being destroyed. To ensure the destroy-method is executed during shutdown, the Spring application needs to register a shutdown hook like this:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(args[0]);
context.registerShutdownHook();
context.start();