Announcement Announcement Module
Collapse
No announcement yet.
JMS Example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS Example

    Hello,

    I was wondering if someone could point me to an example on how to configure and use the Spring JMS template. I would like to run this on JBoss so any example that is appserver based where the topics, queues, etc are looked up through JNDI.

    thanks for your help.
    Suneet

  • #2
    Originally posted by sshah View Post
    Hello,

    I was wondering if someone could point me to an example on how to configure and use the Spring JMS template. I would like to run this on JBoss so any example that is appserver based where the topics, queues, etc are looked up through JNDI.

    thanks for your help.
    Suneet
    asyncronous example with jboss jms and with added comments for you

    Spring config
    =============
    Code:
    <!-- jboss stuff ... -->
    <!-------------------------------->
    <bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    	<property name="jndiName" value="java:ConnectionFactory" />
    </bean>
    
    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    	<property name="connectionFactory" ref="jmsConnectionFactory" />
    </bean>
    
    <!-- jms destination already defined in jboss -->
    <!-------------------------------->
    <bean name="testDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
    	<property name="jndiName" value="queue/test" />
    </bean>
    
    <!-- jmsTemplate for client -->
    <!-------------------------------->
    <bean name="testMessageTemplate" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="jmsConnectionFactory" />
    	<property name="defaultDestination" ref="testDestination" />
    	<property name="receiveTimeout" value="1" />
    </bean>
    
    <!-- jms asynchronous listener for client -->
    <!-------------------------------->
    <bean id="testMessageListener" class="youpackage.TestMessageListener"/>
    <bean id="testMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    	<property name="concurrentConsumers" value="1"/>
    	<property name="connectionFactory" ref="jmsConnectionFactory"/>
    	<property name="transactionManager" ref="jmsTransactionManager" />
    	<property name="destination" ref="testDestination"/>
    	<property name="messageListener" ref="testMessageListener"/>
    </bean>
    JMS Client
    ==========
    Code:
    jmsTemplate.send(new MessageCreator() {
    
    	public Message createMessage(Session session) throws JMSException {
    
    		MapMessage message = session.createMapMessage();
    		message.setString("test", "foo");
    		return message;
    	}
    });
    JMS Listener
    ============
    Code:
    public class TestMessageListener implements SessionAwareMessageListener {
    ...
    	public void onMessage(Message message, Session session) throws JMSException {
    
    		MapMessage mapMessage = (MapMessage) message;
    		log.debug("message received: " + mapMessage.getString("test"));
    }
    ...
    }
    Jboss queue configuration
    =========================
    Code:
    ...
    <mbean code="org.jboss.mq.server.jmx.Queue"
    	 name="jboss.mq.destination:service=Queue,name=test">
      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
    </mbean>
    ...

    Comment


    • #3
      Can you help me out on converting this to ActiveMQ style ?
      I've been at it for weeks and can't figure things out.
      I triead a couple examples, such as the ones at ActiveMQ's site, IBM's examples, ONJava, and even at the Spring documentation, but to no help.

      Comment


      • #4
        Never mind, I found it at this other older thread.

        Salut!

        Comment


        • #5
          Originally posted by renatopb View Post
          Never mind...
          thanks for having stopped me !

          Comment


          • #6
            If you want to access IBM's WebSphere MQ...

            Do a google search "ibm jms spring jndi" The top hit should be titled as below. It explains this pretty well.

            The Spring series, Part 4: 1-2-3 messaging with Spring JMS

            Comment


            • #7
              Thanks a lot paolo_denti.
              I am pretty new to the Spring world and I was trying to do exactly the thing you have described. All over the net I was getting solutions using .binding files.
              This one worked at the first attempt.

              Thanks again

              Comment

              Working...
              X