Announcement Announcement Module
Collapse
No announcement yet.
Remote broker offline -> Queue messages and retry sending Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote broker offline -> Queue messages and retry sending

    Hallo :-)

    I have a central logging server which is supposed to receive logging-messages from a number of clients. Basically it works well. If the logging-server is down I want the clients to retry sending the messages until he is online again (or at lest some times). Unfortunately i was not able to find out how to do this yet. I hope you can help me.

    I use spring-3.0.3 and activemq 5.2.0.

    This is my server-configuration:

    Code:
    <amq:broker useJmx="false" persistent="false">
        	<amq:transportConnectors>
          		<amq:transportConnector uri="tcp://localhost:61616" />
       	</amq:transportConnectors>
    </amq:broker>
    
    <jms:listener-container concurrency="10">
         <jms:listener 
              id="QueryLoggerListener" 
              destination="QueryLogger"
    	  ref="queryLogger" />
    </jms:listener-container>
    		
    <!--QueryLogger implements MessageListener -->
    <!--Writes the log-msg into a db -->
    <bean id="queryLogger"  class="de.it2media.smsc.statisticserver.logger.QueryLogger">
    </bean>
    
    <amq:connectionFactory 
    	id="amqConnectionFactory"
    	brokerURL="tcp://localhost:61616" />
    	
    <bean id="connectionFactory"
    	class="org.springframework.jms.connection.CachingConnectionFactory">
    	<constructor-arg ref="amqConnectionFactory" />
    	<property name="exceptionListener" ref="jmsExceptionListener" />
    	<property name="sessionCacheSize" value="100" />
    </bean> 
    	
    <bean id="jmsExceptionListener" class="de.it2media.smsc.logging.JmsExceptionListener"></bean>
    The client configuration looks like :

    Code:
    <amq:connectionFactory 
    	id="amqConnectionFactory"
    	brokerURL="tcp://localhost:61616" />
    
    <bean id="connectionFactory"
    		class="org.springframework.jms.connection.CachingConnectionFactory">
    	<constructor-arg ref="amqConnectionFactory" />
    	<property name="exceptionListener" ref="jmsExceptionListener" />
    	<property name="sessionCacheSize" value="10" />
    </bean> 
    
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" >
    	<constructor-arg ref="connectionFactory" />
    </bean>
    
    <!-- This bean is used by the different client classes to send log-msg to the logging-server -->
    <bean id="statisticLogger" class="de.it2media.smsc.logging.StatisticLogger">
       	 <constructor-arg ref="jmsTemplate" />
    </bean>   
    
    <bean id="jmsExceptionListener" class="de.it2media.smsc.logging.JmsExceptionListener"></bean>
    This class is used to send the messages to the server :

    Code:
    public class StatisticLogger {
    	
      private final JmsTemplate jmsTemplate;
      public static enum Destinations { QueryLogger };  
    	  
      public StatisticLogger( final JmsTemplate jmsTemplate ) {
    	       this.jmsTemplate = jmsTemplate;
      }
    	  
      public void send( String message, Destinations destination ) {
    	  try{
    	     this.jmsTemplate.
                     convertAndSend(destination.toString(),message);
    	  } catch(Exception e) {
    		  LOGGER.debug("Error : {}",e.getMessage());
    	  }
      }
    	
    }
    If the logging-server is down i get a

    Code:
    Error : Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect
    Exception.

    Thank you for your help in advance!

  • #2
    Ok, i just recognized that i messed the concept. Of course the broker has to be on the sender site and on the server side are only the listeners with a connection factory pointing to the senders broker. Now everything works very well.

    This thread was very helpfull : http://forum.springsource.org/showthread.php?t=50334

    Comment

    Working...
    X