Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with JMS+ Spring + ActiveMQ  RSS feed

luo luo
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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=""/>

<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);*/"The default destination is " + template.getDefaultDestinationName().toString());

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

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

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

catch (JMSException e) {"Failed to acknowledge: " );
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!