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 1100575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:54:07+00:00 2026-05-17T00:54:07+00:00

I have a small Spring MVC webapp (which embeds ActiveMQ) that is designed to

  • 0

I have a small Spring MVC webapp (which embeds ActiveMQ) that is designed to run in a local Tomcat, and reliably message to a queue on a remote ActiveMQ.

All of that’s in place, except for the “reliably”. At the moment, if the remote site goes down, the send fails dramatically. My send config:

<!-- Connection setup -->
<bean id="connectionFactory" 
    class="org.apache.activemq.ActiveMQConnectionFactory" 
    p:brokerURL="tcp://backend-server-box:61616" />

<bean id="cachedConnectionFactory" 
    class="org.springframework.jms.connection.CachingConnectionFactory"
    p:targetConnectionFactory-ref="connectionFactory" 
    p:sessionCacheSize="10" />

<!-- Bean that represents the correct destination on the backend server -->
<bean id="backendDestination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="jmsQueueName" />
</bean>

<bean id="backendTemplate" 
    class="org.springframework.jms.core.JmsTemplate"
    p:connectionFactory-ref="cachedConnectionFactory"
    p:defaultDestination-ref="backendDestination" />

<!-- Bean that sends to the correct destination on the backend server -->
<bean id="simpleSender" class="uk.co.mycompany.client.messaging.SimpleSender">
    <property name="jmsTemplate" ref="backendTemplate" />
</bean>

I think what I need is a local, persistent broker that the connectionFactory (the first bean defined above) points to, which is aware of the remote broker (a JMS to JMS bridge?) If there’s a clear bit of documentation to deal with this I’d be very happy to be pointed at it, but I’ve had to cobble things together, mostly from the extremely helpful BruceBlog. Or any direct help would be great.

Thanks

Update. Some fixes:

  1. Eclipse doesn’t find the amq namespace properly. This is where you find out why that’s broken, and it’s an easy fix.
  2. As Miklos says in a comment below, you need the org.osgi.core-4.1.0.jar in your webapp lib. Get this from the ActiveMQ lib/optional folder.
  3. You also need the Apache Commons xbean-spring-3.4.jar. Get it here.
  4. This guide got me through the next few hurdles. It’s perfect, except in a couple of places attribute names are incorrect (brokername should be brokerName, and physicalname should be physicalName).

Update 2. I’ve answered it properly, below. Doesn’t need any of that amq stuff!

  • 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-05-17T00:54:08+00:00Added an answer on May 17, 2026 at 12:54 am

    This is how to do it.

    Assumptions

    1. You’re connecting to a remote destination on http://destination-box:61616
    2. You’ll connect to your local broker via VM transport, on vm://localhost:7001
    3. You have two remote queues you want to bridge to: queue1 and queue2

    Pre: namespaces

    You need to declare the following namespaces:

    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jms="http://www.springframework.org/schema/jms"
    

    1. Create a local broker:

    <bean id="bridgedBroker" class="org.apache.activemq.broker.BrokerService"
     init-method="start" destroy-method="stop">
      <property name="brokerName" value="bridgedBroker"/>
      <property name="persistent" value="true"/>
      <property name="transportConnectorURIs"> 
        <value>vm://localhost:7001</value>
      </property>
      <property name="jmsBridgeConnectors">
        <bean class="org.apache.activemq.network.jms.JmsQueueConnector">
          <property name="outboundQueueConnectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
              <property name="brokerURL" 
               value="failover:(tcp://destination-box:61616)?maxReconnectDelay=10" />
            </bean>
          </property>
          <property name="outboundQueueBridges">
            <list>
              <bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
                <constructor-arg value="queue1"/>
              </bean>
              <bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
                <constructor-arg value="queue2"/>
              </bean>
            </list>
          </property>
        </bean>
      </property>
    </bean>
    

    So you’re using persistence, activated by a property, and a Broker Configuration URI to configure retry behaviour. You have to list the name of each remote queue you want to connect to in the outboundBridgeQueues list.

    2. Create broker connection factories

    This one connects to the above broker:

    <bean id="brokerConnectionFactory"
     class="org.apache.activemq.ActiveMQConnectionFactory"
     p:brokerURL="vm://localhost:7001" />
    

    Then wrap it with a CachingConnectionFactory (almost always a good idea):

    <bean id="cachingBrokerConnectionFactory"
     class="org.springframework.jms.connection.CachingConnectionFactory"
     p:targetConnectionFactory-ref="brokerConnectionFactory"
     p:sessionCacheSize="10" />
    

    3. Create local equivalents of the remote destinations

    Each destination you’ll be talking to now needs a local representation:

    <bean id="queue1destination" class="org.apache.activemq.command.ActiveMQQueue">
      <constructor-arg value="queue1" />
    </bean>
    
    <bean id="queue2destination" class="org.apache.activemq.command.ActiveMQQueue">
      <constructor-arg value="queue2" />
    </bean>
    

    4. Create JMS templates to be wired into local beans

    I’ll just make one for queue1 here; queue2 is exactly the same process:

    <bean id="queue1JMSTemplate"
     class="org.springframework.jms.core.JmsTemplate"
     p:connectionFactory-ref="cachingBrokerConnectionFactory"
     p:defaultDestination-ref="queue1destination" />
    

    5. Use the JMS template

    Some sample code:

    public class SendToQueue1
    {
      @Autowired protected JmsTemplate queue1JMSTemplate; 
    
      public void sendMessage(final String message) throws JMSException
      {
        queue1JMSTemplate.send(new MessageCreator()
        {
          public Message createMessage(Session session) throws JMSException
          {
            return session.createTextMessage(message);
          }
        });
      }
    }
    

    And you’re done! Not actually too painful, but it took a while to get it working. Hope this helps people in the future; it’s a great way to quickly add persistent messaging to a small app.

    Note: this isn’t a great way to wire up the class. You’d probably pass in a JMSTemplate from config, so you could use one class definition and wire it into different templates for different queues. I’ve just done it like this for speed. Just use your Spring instincts 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written a small webapp using spring-security and spring-mvc with an annotation based
I have small problem with Spring MVC. Basically what I'm trying to do is
I have a small Spring (3.1.0.RELEASE) application, which was working just fine, until I
I succeeded to make simple and small example which integrates between Spring MVC and
I have put together a small ASP.NET MVC 2 site that does some very
I am developing a small Spring application. I have to store the details of
I have a small algorithm which replaces the position of characters in a String:
I have a string which holds a small amount of HTML generated content. I
I have a Spring MVC web app running on my server. Recently I wanted
I have small Asp MVC 3 project where I need to create link to

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.