views:

469

answers:

2

Hi, I am currently setting up a Tomcat Server that is running an embedded ActiveMQ broker. I'm using Spring to configure JMS. I wrote a test application to listen to topics and when I exit the test application the ActiveMQ broker throws a SocketException. Here is the exception:

2009-06-09 13:12:48,005 DEBUG Transport:229 - Transport failed: java.net.SocketException: Connection reset java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at org.apache.activemq.transport.tcp.TcpBufferedInputStream.fill(TcpBufferedInputStream.java:50) at org.apache.activemq.transport.tcp.TcpBufferedInputStream.read(TcpBufferedInputStream.java:58) at java.io.DataInputStream.readInt(DataInputStream.java:370) at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:269) at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:210) at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:202) at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:185) at java.lang.Thread.run(Thread.java:619)

My test application just loads the context xml file, loops sleeps every 60 seconds.

public static void main(String[] args) { long numMillisecondsToSleep = 60000; new ClassPathXmlApplicationContext("client-context.xml");

 while (true) {
  try {
   logger.info("Sleeping for 60 seconds");
   Thread.sleep(numMillisecondsToSleep);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }
}

I was wondering if anyone might know why I'm getting this exception. I'm very new to ActiveMQ and JMS in general so any ideas would be greatly appreciated.

Thanks for your help!!

A: 

I think there's a way to shut down an embedded broker nicely via a method call. Posting your config along with your embedding code will help people figure out what's going on.

ShabbyDoo
I figured this out. I need to call close() on the ClassPathXmlApplicationContext object before the test program terminates. This will allow spring to properly close the Message Listeners and connections that were created to consume messages with the ActiveMQ broker.
Ok. you probably have init/destroy methods specified in your Spring XML for ActiveMQ-related stuff? That makes sense.
ShabbyDoo
A: 

I would recommend looking in to Spring's JmsTemplates; it wraps all of the complexity of MQ into a nice package and ensures little errors like this dont cause you hours of problems.

http://activemq.apache.org/spring-support.html

Aaron Saunders