zoukankan      html  css  js  c++  java
  • ActiveMQ 重发机制(消息发送失败后的重新发送)

    一、重新传递消息的情况

    ActiveMQ在接收消息的Client有以下几种操作的时候,需要重新传递消息:

     1:Client用了transactions(事务),且在session中调用了rollback()

     2:Client用了transactions,且在调用commit()之前关闭

     3:Client在CLIENT_ACKNOWLEDGE的传递模式下,在session中调用了recover()

    二、写RedeliveryPolicy配置文件

    <!-- 定义ReDelivery(重发机制)机制 ,重发时间间隔是100毫秒,最大重发次数是3次 -->  
        <bean id="activeMQRedeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">  
            <!--是否在每次尝试重新发送失败后,增长这个等待时间 -->  
            <property name="useExponentialBackOff" value="true"></property>  
            <!--重发次数,默认为6次   这里设置为1次 -->  
            <property name="maximumRedeliveries" value="1"></property>  
            <!--重发时间间隔,默认为1秒 -->  
            <property name="initialRedeliveryDelay" value="1000"></property>  
            <!--第一次失败后重新发送之前等待500毫秒,第二次失败再等待500 * 2毫秒,这里的2就是value -->  
            <property name="backOffMultiplier" value="2"></property>  
            <!--最大传送延迟,只在useExponentialBackOff为true时有效(V5.5),假设首次重连间隔为10ms,倍数为2,那么第   
                二次重连时间间隔为 20ms,第三次重连时间间隔为40ms,当重连时间间隔大的最大重连时间间隔时,以后每次重连时间间隔都为最大重连时间间隔。 -->  
            <property name="maximumRedeliveryDelay" value="1000"></property>  
        </bean>  

    三、引用RedeliveryPolicy的配置:

    <!--创建连接工厂 -->  
    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">  
        <property name="brokerURL" value="tcp://localhost:61616"></property>  
        <property name="redeliveryPolicy" ref="activeMQRedeliveryPolicy" />  <!-- 引用重发机制 -->  
    </bean>  
  • 相关阅读:
    (三)openwrt主Makefile解析
    (二)我的Makefile学习冲动&&编译过程概述
    openwrt修改flash大小
    (一)openwrt源码目录概述
    git_sop 脚本使用说明
    Openwrt LuCI模块练习详细步骤
    openwrt简单ipk生成及Makefile解释
    oracle中比较两表表结构差异和数据差异的方法
    C#泛型集合之Dictionary<k, v>使用技巧
    SQL语句添加,删除主键
  • 原文地址:https://www.cnblogs.com/sjshare/p/8915669.html
Copyright © 2011-2022 走看看