6 Replies Latest reply on Nov 9, 2012 9:18 PM by jbertram

    jboss7.1 configured  with hornetq JMS error queue

    mathewvino

      I am configuring Jboss7.1 using hornetq. My problems is how do I send the JMS unsucessfull Message ( due to some data base error) back to the same JMS queue.

       

      1) Is it something I need to catch the Exception on onMessage object of the MessageListener and send the ObjectMessage back to the Same JMS queue

      2) or Is it something I can configure in standalone.xml

       

       

      try{

      mapMessage = (ObjectMessage) tfnEventMessage;

      if (mapMessage != null) {

        // here it throws the Exception

      }

       

      tfnEventMessage.acknowledge()

      }catch (Exception e){

        // how do I send it back to the same Queue

      }

       

       

      Please find the standalone.xml file attached.

       

      Note: For me any error happens it is not going back to the Same queue. When I look through the jboss console of the JMSQUEUE I can see the message as processed and the count is incremented.

       

      thanks for the help.Really appreciate

        • 1. Re: jboss7.1 configured  with hornetq JMS error queue
          jbertram

          The exact process is different depending on what kind of client you are using (e.g. MDB, stand-alone JMS client, core client, etc.), but basically you need to consume the message transactionally and if you have an error then rollback the transaction and that will send the message back to the destination it came from.

          • 2. Re: jboss7.1 configured  with hornetq JMS error queue
            mathewvino

            Thanks Justin for the quick reply

             

            I am using the Spring JMS Client configured through Spring xml file . May be  I am dumb:) How do i Consume the message trnasactionally, Is is some setting /configuring the xml file

             

             

            Please find the spring configuration i am using org.springframework.jms.core.JmsTemplate to publish the event.

             

            Thanks for the help

             

             

             

             

            ****************** configration in spring xml file ******************************** 

             

             

            <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">

                                <property name="environment">

                                           <props>

                                                       <prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>

                                                       <prop key="java.naming.provider.url">remote://localhost:4447</prop>

                                                     <prop key="java.naming.security.principal">guest</prop>

                                                    <prop key="java.naming.security.credentials">pass</prop>

                                          </props>

                                </property>

                </bean>

             

             

                 <bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

                                <property name="jndiTemplate">

                                           <ref bean="jndiTemplate" />

                                </property>

                                <property name="jndiName">

                                           <value>jms/RemoteConnectionFactory</value>

                                </property>

                      </bean>

             

             

               <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">

                    <property name="jndiTemplate">

                                           <ref bean="jndiTemplate" />

                                </property>

                          <property name="jndiName">

                                           <value>jms/tfnQueueEvents</value>

                                </property>

                      </bean>

             

             

             

              <bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">

                                <property name="jndiTemplate">

                                           <ref bean="jndiTemplate" />

                                </property>

                                <property name="cache">

                                           <value>true</value>

                                </property>

              </bean>

             

             

                       <bean id="queueTemplate" class="org.springframework.jms.core.JmsTemplate">

                                <property name="connectionFactory">

                                           <ref bean="queueConnectionFactory" />

                                </property>

                                <property name="destinationResolver">

                                           <ref bean="jmsDestinationResolver" />

                                </property>

                                <property name="pubSubDomain" value="false"/>

                                <property name="defaultDestination" ref="destination"/>

                                <property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE"/>

             

                      </bean>

             

             

                      <bean id="jmsQueueEventPublisher" class="com.xxx.xxx.core.jms.event.JMSQueueEventPublisher">

                                 <property name="jmsTemplate"

                                           ref ="queueTemplate" />

                      </bean>

             

             

            ****************** configration in spring xml file ends ******************************** 

             

             

             

             

            Publisher code starts from here ***********************

             

             

            public class JMSQueueEventPublisher {

             

             

                      private static final Logger logger = LoggerFactory.getLogger(JMSQueueEventPublisher.class);

             

                      private JmsTemplate jmsTemplate;

             

             

             

                      public JmsTemplate getJmsTemplate() {

                                return jmsTemplate;

                      }

             

             

                      public void setJmsTemplate(JmsTemplate jmsTemplate) {

                                this.jmsTemplate = jmsTemplate;

                      }

                      /**

                       * @param TfnEventVO

                       *            Sets the message in the Queue

                       */

                      public void sendMessage(final Collection<String> tfnList)

                                          throws Exception {

                                logger.info("sendMessage CALLED" + this.jmsTemplate);

                                   this.jmsTemplate.send(new MessageCreator() {

                                          public Message createMessage(Session session) throws JMSException {

                                                    logger.info("PUBLISH SESSSION -------" + session);

                                                    ObjectMessage message = session.createObjectMessage();

                                                    message.setStringProperty("username", "xxxxx");

                                                    long time = new Date().getTime();

                                                    message.setLongProperty("timestamp", new Timestamp(time).getTime());

                                                    message.setObject((Serializable) tfnList);

                                                    logger.info("PUBLISH message --------" + message);

                                                    return message;

                                          }

                                });

             

             

                      }

             

             

             

            }

            • 3. Re: jboss7.1 configured  with hornetq JMS error queue
              jbertram

              You'll have to consult the Spring documentation for your answer as I'm not terribly familiar with their JmsTemplate.

              • 4. Re: jboss7.1 configured  with hornetq JMS error queue
                jbertram

                BTW, it's the configuration of the consumer that is relevant, not the configuration of the producer (which you've shared here).

                • 5. Re: jboss7.1 configured  with hornetq JMS error queue
                  mathewvino

                  Thanks justin for  helping me out. Here is the producer configuration

                   

                  <bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">

                                      <property name="jndiTemplate">

                                                 <ref bean="jndiTemplate" />

                                      </property>

                                      <property name="cache">

                                                 <value>true</value>

                                      </property>

                    </bean>

                   

                   

                     <bean id="queueErrorTemplate" class="org.springframework.jms.core.JmsTemplate">

                                      <property name="connectionFactory">

                                                 <ref bean="queueConnectionFactory" />

                                      </property>

                                      <property name="destinationResolver">

                                                 <ref bean="jmsDestinationResolver" />

                                      </property>

                                      <property name="pubSubDomain" value="false"/>

                                      <property name="defaultDestination" ref="receiverDestination"/>

                                      <property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE"/>

                  </bean>

                   

                    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">

                                      <property name="environment">

                                                 <props>

                                                             <prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>

                                                             <prop key="java.naming.provider.url">${environment.jmsserver}</prop>

                                                          <prop key="java.naming.security.principal">guest</prop>

                                                          <prop key="java.naming.security.credentials">pass</prop>

                                                </props>

                                      </property>

                      </bean>

                   

                   

                       <bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">

                                      <property name="jndiTemplate">

                                                 <ref bean="jndiTemplate"/>

                                      </property>

                                      <property name="jndiName">

                                                 <value>jms/RemoteConnectionFactory</value>

                                      </property>

                            </bean>

                    

                     <bean id="receiverDestination" class="org.springframework.jndi.JndiObjectFactoryBean">

                          <property name="jndiTemplate">

                                                 <ref bean="jndiTemplate" />

                                      </property>

                                <property name="jndiName">

                                                 <value>jms/tfnQueueEvents</value>

                                      </property>

                            </bean>

                   

                   

                     <!-- this is the Message Driven POJO (MDP) -->

                            <bean id="messageListener" class="com.xxx.xxx.core.jms.listener.QueueEventListener">

                                      <property name="jmsTemplate" ref="queueErrorTemplate" />

                   

                            </bean>

                   

                   

                     <bean id="jmsContainer"

                                      class="org.springframework.jms.listener.DefaultMessageListenerContainer">

                                      <property name="concurrentConsumers" value="1" />

                                      <property name="connectionFactory" ref="queueConnectionFactory" />

                                      <property name="destination" ref="receiverDestination" />

                                      <property name="messageListener" ref="messageListener" />

                                      <property name="sessionTransacted" value="true"/>

                                      <property name="receiveTimeout" value="60000" />

                   

                            </bean>

                  • 6. Re: jboss7.1 configured  with hornetq JMS error queue
                    jbertram

                    I'm not sure what you want me to do with this.  As I indicated previously, I'm not terribly familiar with Spring.  You need to consult the Spring documentation yourself and figure this out.