You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Paul French <pa...@frenchiesystems.com> on 2006/07/28 12:47:37 UTC

Simple JMS outbound program never exits

Here is a simple JMS program that sends 10 text messages. The program never
exits?? Anyone can tell me why? The spring config file is also given. I
suspect it is to do with the
org.springframework.jms.connection.SingleConnectio nFactory that reuses a
single JMS connection. As you can see I have also specified the destroy
method on the SingleConnectionFactory to be destroy. This does not help.
Also if I call classPathXmlApplicationContext.destroy() after doSomeStuff()
I get an exception saying

org.apache.activemq.ConnectionClosedException: The connection is already
closed
at org.apache.activemq.ActiveMQConnection.checkClosed
(ActiveMQConnection.java:1182)
at org.apache.activemq.ActiveMQConnection.close(Activ
eMQConnection.java:529)
at org.springframework.jms.connection.SingleConnectio
nFactory.destroy(SingleConnectionFactory.java:162) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native
MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.beans.factory.support.Abstract
BeanFactory.invokeCustomDestroyMethod(AbstractBean Factory.java:1052)
at org.springframework.beans.factory.support.Abstract
BeanFactory$1.destroy(AbstractBeanFactory.java:923 )
at org.springframework.beans.factory.support.Abstract
BeanFactory.destroyBean(AbstractBeanFactory.java:1 007)
at org.springframework.beans.factory.support.Abstract
BeanFactory.destroyDisposableBean(AbstractBeanFact ory.java:979)
at org.springframework.beans.factory.support.Abstract
BeanFactory.destroySingletons(AbstractBeanFactory. java:557)
at org.springframework.context.support.AbstractApplic
ationContext.close(AbstractApplicationContext.java :528)
at org.springframework.context.support.AbstractApplic
ationContext.destroy(AbstractApplicationContext.ja va:544)
at com.frenchiesystems.ttre.client.TestClient.main(Te stClient.java:27)



Simple Client (ActiveMQ has already been started)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


public class TestClient implements InitializingBean
{
private JmsTemplate jmsTemplate = null;
private static ClassPathXmlApplicationContext ac;

public static void main(String[] args)
{
String[] params = new String[1];
params[0] = "test_client_model.xml";
ac = new ClassPathXmlApplicationContext(params);

TestClient client = (TestClient)ac.getBean("client");

client.doSomeStuff(); 
//ac.destroy(); if used then get above exception
}

public void doSomeStuff()
{
for (int i =0; i < 10; i++)
{
jmsTemplate.send(new MessageCreator(){
public Message createMessage(Session session) throws JMSException
{
return session.createTextMessage("A message");
}
});
}
}

public void afterPropertiesSet()
{
if (getJmsTemplate() == null)
{
throw new BeanCreationException("The property jmsTemplate needs to be set");
}
}

public JmsTemplate getJmsTemplate()
{
return jmsTemplate;
}

public void setJmsTemplate(JmsTemplate jmsTemplate)
{
this.jmsTemplate = jmsTemplate;
}
}


Spring Config File
~~~~~~~~~~~

<beans>
<bean id="client" class="com.frenchiesystems.ttre.client.TestClient" >
<property name="jmsTemplate"><ref local="jmsTemplate"/></property>
</bean>

<bean id="connectionFactory"
class="org.springframework.jms.connection.SingleCo nnectionFactory"
destroy-method="destroy">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFacto ry">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="useAsyncSend"><value>TRUE</value></property> 
</bean>
</property>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="receiveTimeout"><value>10000</value></property>
<property name="connectionFactory"><ref
local="connectionFactory"/></property>
<property name="defaultDestination">
<bean class="org.apache.activemq.command.ActiveMQQueue"> 
<constructor-arg index="0" value="TTRE.TimetableRequests" />
</bean>
</property>
</bean>

</beans>


I've also posted on Spring forum since I'm not sure if it is Spring related
or ActiveMQ
-- 
View this message in context: http://www.nabble.com/Simple-JMS-outbound-program-never-exits-tf2014745.html#a5537335
Sent from the ActiveMQ - User forum at Nabble.com.