• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Need help with JMS+ Spring + ActiveMQ

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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="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: " );
    Bookmark Topic Watch Topic
  • New Topic