• 【activemq classic】 消息特性:延迟和定时消息投递


    ActiveMQ from version 5.4 has an optional persistent scheduler built into the ActiveMQ message broker. It is enabled by setting the broker schedulerSupport attribute to true in the xml configuration

    !!! (xml broker 要配置schedulerSupport 为true)例如:<broker xmlns="http://activemq.apache.org/schema/core"  ... schedulerSupport="true">

    An ActiveMQ client can take advantage of a delayed delivery by using the following message properties:

    Property name

    type

    description

    AMQ_SCHEDULED_DELAY

    long

    The time in milliseconds(毫秒) that a message will wait before being scheduled to be delivered by the broker

    AMQ_SCHEDULED_PERIOD

    long

    The time in milliseconds to wait after the start time to wait before scheduling the message again

    AMQ_SCHEDULED_REPEAT

    int

    The number of times to repeat scheduling a message for delivery

    AMQ_SCHEDULED_CRON

    String

    Use a Cron entry to set the schedule

    For example, to have a message scheduled for delivery in 60 seconds - you would need to set the AMQ_SCHEDULED_DELAY property:

    IMessageProducer producer = session.CreateProducer(destination);
    ITextMessage message = session.CreateTextMessage("test msg");
    long time = 60 * 1000;
    message.Properties["AMQ_SCHEDULED_DELAY"] = time;
    producer.Send(message);

    You can set a message to wait with an initial delay, and the repeat delivery 10 times, waiting 10 seconds between each re-delivery:

    IMessageProducer producer = session.CreateProducer(destination);
    ITextMessage message = session.CreateTextMessage("test msg");
    long delay = 30 * 1000;
    long period = 10 * 1000;
    int repeat = 9;
    message.Properties["AMQ_SCHEDULED_DELAY"] = delay;
    message.Properties["AMQ_SCHEDULED_PERIOD"] = period;
    message.Properties["AMQ_SCHEDULED_REPEAT"] = repeat;
    producer.Send(message);

    You can also use CRON to schedule a message, for example, if you want a message scheduled to be delivered every hour, you would need to set the CRON entry to be - 0 * * * * - e.g.

    IMessageProducer producer = session.CreateProducer(destination);
    ITextMessage message = session.CreateTextMessage("test msg");
    message.Properties["AMQ_SCHEDULED_CRON"] = "0 * * * *";
    producer.Send(message);

    CRON scheduling takes priority over using message delay - however, if a repeat and period is set with a CRON entry, the ActiveMQ scheduler will schedule delivery of the message for every time the CRON entry fires. Easier to explain with an example. Supposing that you want a message to be delivered 10 times, with a one second delay between each message - and you wanted this to happen every hour - you'd do this:

    IMessageProducer producer = session.CreateProducer(destination);
    ITextMessage message = session.CreateTextMessage("test msg");
    message.Properties["AMQ_SCHEDULED_CRON"] = "0 * * * *";
    message.Properties["AMQ_SCHEDULED_DELAY"] = 1000;
    message.Properties["AMQ_SCHEDULED_PERIOD"] = 1000;
    message.Properties["AMQ_SCHEDULED_REPEAT"] = 9;
    producer.Send(message);
     
    摘抄自:http://activemq.apache.org/nms/stomp-delayed-and-scheduled-message-feature.html
  • 相关阅读:
    C语言得到当前系统时间
    【solr这四个主题】在Tomcat 部署Solr4.x
    MySQL 一般查询日志(General Query Log)
    iOS7 UIKit动力学-碰撞特性UICollisionBehavior 上
    Java Persistence with MyBatis 3(中国版) 第五章 与Spring集成
    Kaggle入门——使用scikit-learn解决DigitRecognition问题
    Effective C++:规定34:区分接口继承和实现继承
    Critical thinking and Thoughtful writing
    我的时间,GTD做主
    jquery自己主动旋转的登录界面的背景代码登录页背景图
  • 原文地址:https://www.cnblogs.com/heweiquan123/p/8966211.html
Copyright © 2020-2023  润新知