重试在RabbitMQ&;中不起作用;春季amqp

重试在RabbitMQ&;中不起作用;春季amqp,rabbitmq,spring-amqp,Rabbitmq,Spring Amqp,即使我在Spring项目的rabbitMQConfig.xml中提到了重试配置,使用RabbitMQ&Spring AMQP retry也不起作用 根据我的配置,它应该重试2次,但它不断地重试“n”次。下面提到的配置文件仅用于RabbitMQ配置 消费者代码: public void onMessage ( Message message, Channel channel ) throws Exception { System.out.println ( "-------

即使我在Spring项目的rabbitMQConfig.xml中提到了重试配置,使用RabbitMQ&Spring AMQP retry也不起作用

根据我的配置,它应该重试2次,但它不断地重试“n”次。下面提到的配置文件仅用于RabbitMQ配置

消费者代码:

public void onMessage ( Message message, Channel channel ) throws Exception
    {
        System.out.println ( "------------RabbitMQConsumer -------------" );
        LOGGER.info ( "Enter in to  RabbitMQConsumer: onMessage " );
        boolean isAck = false;
        try
        {
            String s = new String ( message.getBody () );
            System.out.println ("Message:"+s);
            System.out.println ("Message From"+message.getMessageProperties ().getReceivedRoutingKey ());
            channel.basicNAck ( message.getMessageProperties ().getDeliveryTag (), false , true);
        }
        catch ( Exception e )
        {
            // currently on exception i am unack the channel
            // channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
            LOGGER.info ( "Message RabbitMQ Exception:" + e );

        }
        LOGGER.info ( "Exit from  RabbitMQConsumer: onMessage " );
    }
xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/rabbit
           http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
           http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- Provides connection to the RabbitMQ broker -->
    <bean id="connectionFactoryRabbit"
        class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"
        p:username="guest" p:password="guest" p:port="5672">
        <constructor-arg value="localhost" />

    </bean>

    <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate"
        p:connectionFactory-ref="connectionFactoryRabbit">
    </bean>

    <bean id="simpleMessageConverter"
        class="org.springframework.amqp.support.converter.SimpleMessageConverter">
        <property name="createMessageIds" value="true" />
    </bean>
    <!-- A template for sending messages and performing other commands to RabbitMQ -->

    <bean
        class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"
        p:connectionFactory-ref="connectionFactoryRabbit" p:queueNames="test123"
        p:messageListener-ref="messageListener">
        <property name="adviceChain" ref="retryInterceptor"></property>
        <property name="acknowledgeMode" value="AUTO" />
    </bean>

    <bean id="retryInterceptor"
        class="org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean">
        <property name="retryOperations" ref="retryTemplate" />
    </bean>

    <!-- <bean id="missingMessageId" class="org.springframework.amqp.rabbit.retry.MissingMessageIdAdvice" 
        /> -->
    <bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
        <property name="backOffPolicy">
            <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                <property name="initialInterval" value="300" />
                <property name="multiplier" value="2.0" />
                <property name="maxInterval" value="10000" />
            </bean>
        </property>
        <property name="retryPolicy" ref="simpleRetryPolicy" />
    </bean>
    <bean id="simpleRetryPolicy" class="org.springframework.retry.policy.SimpleRetryPolicy">
     <property name="maxAttempts" value="5" /> 

    </bean>

    <bean id="messageListener" class="com.gnax.sola.portal.jms.RabbitMQConsumer">
    </bean>
    <!-- This helps in configuring the AMQP broker, like creating a new queue -->
    <bean id="amqpAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
        <constructor-arg ref="connectionFactoryRabbit" />
    </bean>




    </beans>

对不起,您的问题不清楚。你真的应该提供更多关于这件事的信息。我们可以帮你做一些你想做的事