wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Need help with JMS+ Spring + ActiveMQ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Need help with JMS+ Spring + ActiveMQ" Watch "Need help with JMS+ Spring + ActiveMQ" New topic

Need help with JMS+ Spring + ActiveMQ

luo luo
Ranch Hand

Joined: Dec 09, 2003
Posts: 36

I'm learning to using JMS + Spring + ActiveMQ for a simple application. The following is my configs and MD Pojo. My question is that when I tried to send <300 messages, it gave me java out of memory error and it seems so slow. Please tell me what's wrong with it... it's kind of urgent, much apprecicated!!!

Server-side config:

<bean id="activeMQContainer" class="org.activemq.jca.JCAContainer">
<property name="workManager">
<bean id="workManager" class="org.activemq.work.SpringWorkManager"/>

<property name="resourceAdapter">
<bean id="activeMQResourceAdapter"
<property name="serverUrl" value="tcp://localhost:61616"/>

<bean id="HelloMDP" factory-method="addConnector" factory-bean="activeMQContainer">
<property name="activationSpec">
<bean class="org.activemq.ra.ActiveMQActivationSpec">
<property name="destination" value="Hello.Queue"/>
<property name="destinationType" value="javax.jms.Queue"/>
<property name="ref" value="helloBean" />

<bean id="helloBean" class="com.icrossing.mdpojo.lingo.impl.HelloBean">


<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="defaultDestinationName" value="Hello.Queue" />
<property name="connectionFactory" ref="connectionFactory" />

<bean id="connectionFactory" class="org.activemq.ActiveMQConnectionFactory" init-method="start">
<property name="brokerURL" value="tcp://localhost:61616" />

My java code:

code snippet for producing Messages:

for (int i = 0; i < messageCount ; i++) {

final String text = "Text for message: " + i;
template.send(new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage message = session.createTextMessage(text);
message.setStringProperty("next", "foo");
return message;

// Consumer

public class HelloBean extends implements MessageListener {

private String myId = "foo";
private Connection connection;
private Session session;
private MessageConsumer consumer;
private Destination destination;
private ActiveMQQueue queue;
private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(Hello Bean.class);

public void start(JmsTemplate template) {
String myId ="foo";

ConnectionFactory factory = template.getConnectionFactory();
connection = factory.createConnection();

session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = (org.activemq.message.ActiveMQQueue)session.create Queue(template.getDefaultDestinationName().toStrin g());
consumer = session.createConsumer(queue);

/*QueueBrowser qb= session.createBrowser(queue);*/

log.info("The default destination is " + template.getDefaultDestinationName().toString());

} catch(JMSException e) {
log.info("In the customer start error" + e.getMessage());

public void destroy() throws JMSException {
consumer = null;
connection = null;

public void onMessage(Message message) {
try {
//log.info("receiving message :" + ((ObjectMessage)message).getObject().toString());
if(message instanceof TextMessage){
log.info("The txt msg is: " + ((TextMessage)message).getText());
if(message instanceof ObjectMessage){
//log.info("The object msg is: " + ((ObjectMessage)message).getObject().toString());

catch (JMSException e) {
log.info("Failed to acknowledge: " );

Let it snow~
I agree. Here's the link: http://aspose.com/file-tools
subject: Need help with JMS+ Spring + ActiveMQ
Similar Threads
JMS (Transaction ?) problemen on Weblogic 10.3
Access hibernate session inside onMessage using ActiveMQ
Queue and session is closed! problem
JMS Consumer not receiving any messages.
Spring JMS with IBM Websphere MQ5.3.1