Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:34:48+00:00 2026-06-11T20:34:48+00:00

I am trying to run a very basic application to learn Spring JMS +

  • 0

I am trying to run a very basic application to learn Spring JMS + ActiveMQ. I see my Producer creating the message (sysout), but nothing shows up in my Consumer and no exception is thrown. I think I am missing something simple here; would really appreciate any help.

[EDITED, THE FOLLOWING CODE WORKS]

Producer:

@Component
public class JmsMessageProducer
{
    @Autowired
    private JmsTemplate template;

    public void generateMessages() throws JMSException
    {
        template.send(new MessageCreator()
        {
            public Message createMessage(Session session) throws JMSException
            {
                System.out.println("sending..");
                TextMessage message = session.createTextMessage("this is a Producer created message!");
                return message;
            }
        });
    }
}

Consumer:

@Component
public class JmsMessageConsumer implements MessageListener {
    @Override
    public void onMessage(Message message) {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            try {
                System.out.println("CONSUMER - received ["+tm.getText()+"]");
            }
            catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }
}

Producer Configuration:

<context:component-scan base-package="mrpomario.springcore.jms"/> <!-- finds the JmsMessageProducer -->

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:8082"/>
</bean>

<bean id="pomarioQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="mrpomario.springcore.jms.queue"/>
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="defaultDestination" ref="pomarioQueue"/>
</bean>

Consumer Configuration:

<jms:listener-container>
    <jms:listener ref="jmsMessageConsumer" method="onMessage" destination="mrpomario.springcore.jms.queue"/>
</jms:listener-container>

<bean id="pomarioQueue" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="mrpomario.springcore.jms.queue"/>
</bean>

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:8082"/>
</bean>

<amq:broker id="broker" useJmx="false" persistent="false">
    <amq:transportConnectors>
        <amq:transportConnector uri="tcp://localhost:8082" />
    </amq:transportConnectors>
</amq:broker>

Test Case:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:mrpomario/springcore/jms/jms-config.xml")
public class JmsTest
{
    @Autowired
    JmsMessageProducer jmsMessageProducer;

    @Test
    public void test_Single_Queue_Producer_and_Consumer_Unidirectional() throws JMSException
    {
        try
        {
            jmsMessageProducer.generateMessages();
            assertTrue(true);
        }
        catch (Throwable th)
        {
            System.out.println("\n\nJmsTest: remote invocation failed. Ensure the web server is running.\n\n");
        }
    }
}

I run the producer inside a Java EE container (mvn jetty:run) where a Spring MVC application also runs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:34:49+00:00Added an answer on June 11, 2026 at 8:34 pm

    I think you are ending up sending to and consuming from two completely different brokers(and subsequently different queues):

    Have your broker defined in only one place, say your producer config:

    <amq:broker id="broker" useJmx="false" persistent="false">
        <amq:transportConnectors>
            <amq:transportConnector uri="tcp://localhost:8082" />
            <amq:transportConnector uri="vm://localhost" />
        </amq:transportConnectors>
    </amq:broker>
    
    <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost" />
    

    From your consumer config remove the broker configuration and have only the connectionFactory:
    Either (if you are in the same VM):

    <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost" />
    

    Or(If remote):

    <amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:8082" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run our very old application on Windows 7 64 bit.
I'm trying out wiQuery to see if it suits my needs, but I've run
I'm trying to send a very basic XML string from a Windows Phone application
I am trying to run this very basic socket example: import socket host =
Just trying to get a very basic install of slime and clojure working, but
I have two very similar programs each trying to run two threads OddThread and
I am trying to run a hadoop job on a very large amount of
I am trying to run a Winsorized regression in pandas for Python. The very
I am very new to MPI programming, I am trying to run a program
This very likely a setup issue on my part. I am trying to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.