Results 1 to 4 of 4

Thread: Message loss after retry max-times

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Question Message loss after retry max-times

    Hi,

    I use Dead Letter Exchange(DLX) and spring-retry for the bussness exceptions handling when consuming a message.

    I hope, when certain exception is throwed, i will retry it. if max-retry-count is exhausted, and the message is still not be processing appropriately, i will not requeue it any more, and put it to the dead-letter-exchange.

    Actual case, the message has been retry max-times, and processing still fails. But, the message has not been delivered to the dead-letter-exchange. it's gone, lost.

    i don't know why? here is my xml files:

    Producer:
    Code:
    	<rabbit:connection-factory id="connectionFactory"
    		username="guest" password="guest"
    		host="192.168.1.234"/>
    
    	<rabbit:admin connection-factory="connectionFactory" />
    	
    	<rabbit:template id="rabbitTemplate"
    		connection-factory="connectionFactory" channel-transacted="true"
    		exchange="asyncservice.order.exchange" />
    
    	<rabbit:queue name="ha.order.fujian.queue" />
    	
    	<rabbit:queue name="ha.order.yunan.queue" />
    
    	<rabbit:topic-exchange name="asyncservice.order.exchange">
    		<rabbit:bindings>
    			<rabbit:binding queue="ha.order.fujian.queue" pattern="#.fujian" />
    			<rabbit:binding queue="ha.order.yunan.queue" pattern="#.yunan" />
    		</rabbit:bindings>
    	</rabbit:topic-exchange>
    consumer:
    Code:
    	<rabbit:connection-factory id="connectionFactory"
    		username="guest" password="guest"
    		host="192.168.1.234"/>
    
    	<rabbit:admin connection-factory="connectionFactory" />
    
    	<rabbit:queue name="ha.order.fujian.queue" />
    	
    	<rabbit:queue name="ha.order.yunan.queue" />
    		
    	<rabbit:queue name="ha.order.fujian.queue.dead">
    		<rabbit:queue-arguments>
    			<entry key="x-dead-letter-exchange" value="asyncservice.order.exchange.dead" />
    		</rabbit:queue-arguments>
    	</rabbit:queue>
    	
    	<rabbit:queue name="ha.order.yunan.queue.dead">
    		<rabbit:queue-arguments>
    			<entry key="x-dead-letter-exchange" value="asyncservice.order.exchange.dead" />
    		</rabbit:queue-arguments>
    	</rabbit:queue>
    
    	<rabbit:topic-exchange name="asyncservice.order.exchange.dead">
    		<rabbit:bindings>
    			<rabbit:binding queue="ha.order.fujian.queue.dead" pattern="#.fujian" />
    			<rabbit:binding queue="ha.order.yunan.queue.dead" pattern="#.yunan" />
    		</rabbit:bindings>
    	</rabbit:topic-exchange>
    	
    	<rabbit:listener-container
    		connection-factory="connectionFactory" channel-transacted="true"
    		transaction-manager="rabbitTransactionManager" transaction-size="1"
    		prefetch="100" concurrency="10" advice-chain="retryInterceptor" >
    		<rabbit:listener queues="ha.order.fujian.queue" ref="fujianMsgHandle"
    			method="handleMessage" />
    		<rabbit:listener queues="ha.order.yunan.queue" ref="yunanMsgHandle"
    			method="handleMessage" />
    	</rabbit:listener-container>
    	
    	<bean id="rabbitTransactionManager" class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
    		<property name="connectionFactory" ref="connectionFactory"/>
    	</bean>
    	
    	<bean id="retryInterceptor" class="org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean">
    		<property name="messageRecoverer" ref="rejectAndDontRequeueRecoverer"/>
    		<property name="retryOperations" ref="retryTemplate" />
    	</bean>	
    	
    	<bean id="rejectAndDontRequeueRecoverer" class="org.springframework.amqp.rabbit.retry.RejectAndDontRequeueRecoverer"/>
    	
    	<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
    		<property name="backOffPolicy">
    			<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
    				<property name="initialInterval" value="5000" />
    				<property name="maxInterval" value="120000" />
    				<property name="multiplier" value="2" />
    			</bean>		
    		</property>
    		<property name="retryPolicy">
    			<bean class="org.springframework.retry.policy.SimpleRetryPolicy">
    				<property name="maxAttempts" value="3" />
    			</bean>		
    		</property>
    	</bean>

    Am I missing a configuration setting or is it a bug?
    I am using spring-amqp 1.1.3

    Thanks for your help.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,015

    Default

    You have the x-dead-lettter-exchange argument on the dead letter queue instead of the original queue.

    Rabbit needs to know where to route the dead letter when the message is rejected (from the original queue). You have the DLX argument on the wrong queues, it should be on the other queues. Given that the original queues have no DLX, Rabbit silently drops the rejected message.

    http://www.rabbitmq.com/dlx.html
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Nov 2012
    Posts
    18

    Default

    x-dead-lettter-exchange argument should add to the original queue. And, you also need Binding a DLQ(dead-letter queue) to DLX. like this:

    Both Producer & Consumer side:
    Code:
    <rabbit:queue name="ha.order.fujian.queue" >
      <rabbit:queue-arguments>
        <entry key="x-dead-letter-exchange" value="asyncservice.order.exchange.dead" />
        <entry key="x-dead-letter-routing-key" value="ha.order.fujian.queue.dead" />
      </rabbit:queue-arguments>
    </rabbit:queue>
    DLX & DLQ & Binding on Consumer side:
    Code:
    <rabbit:queue name="ha.order.fujian.queue.dead" />
    
    <!-- or topic type, whatever -->
    <rabbit:direct-exchange name="asyncservice.order.exchange.dead" >
      <rabbit:bindings>
        <rabbit:binding queue="ha.order.fujian.queue.dead" key="ha.order.fujian.queue.dead" />
      </rabbit:bindings>
    </rabbit:direct-exchange>
    Last edited by Wuaner; Jan 5th, 2013 at 07:33 PM.

  4. #4
    Join Date
    Jul 2011
    Posts
    2

    Default

    thks a lot, Gary , Wuaner

    Beautiful, it's working.

    Cheers.
    -Franklin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •