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
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 = * ;
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 = * ;
long period = * ;
int repeat = ;
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

ActiveMq C# 消息特性:延迟和定时消息投递的更多相关文章

  1. JMS学习(八)-ActiveMQ Consumer 使用 push 还是 pull 获取消息

    ActiveMQ是一个消息中间件,对于消费者而言有两种方式从消息中间件获取消息: ①Push方式:由消息中间件主动地将消息推送给消费者:②Pull方式:由消费者主动向消息中间件拉取消息.看一段官网对P ...

  2. RabbitMQ使用 prefetch_count优化队列的消费,使用死信队列和延迟队列实现消息的定时重试,golang版本

    RabbitMQ 的优化 channel prefetch Count 死信队列 什么是死信队列 使用场景 代码实现 延迟队列 什么是延迟队列 使用场景 实现延迟队列的方式 Queue TTL Mes ...

  3. activemq的高级特性:消息持久订阅

    activemq的高级特性之消息持久订阅 如果采用topic模式发送的时候,mq关闭了或消费者关闭了.在启动的时候,就会收不到mq发送的消息,所以就会出现消息持久订阅. 消息持久订阅:第一:消息要持久 ...

  4. activemq的高级特性:消息的可靠性

    高级特性之消息的可靠性 可靠性分为:生产者.消费者.生产者必须让mq收到消息,消费者必须能够接收到消息并且消费成功,这就是消息的可靠性. 1:生产者可靠性 Session session = conn ...

  5. 一文带你认知定时消息发布RocketMQ

    摘要:DMS任意时间定时消息能力发布. DMS是华为云的分布式消息中间件服务.适用于解决分布式架构中的系统解耦.跨系统跨地域数据流通.分布式事务协调等难题,协助构建优雅的现代化应用架构,提供可兼容 K ...

  6. Apache ActiveMQ实战(1)-基本安装配置与消息类型

    ActiveMQ简介 ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信.ActiveMQ使用Apache ...

  7. MQ发送定时消息

    通过延时发送来发送定时消息. RocketMQ只支持固定精度时间的延时消息发送:1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 若 ...

  8. RabbitMQ延迟消息的延迟极限是多少?

    之前在写Spring Cloud Stream专题内容的时候,特地介绍了一下如何使用RabbitMQ的延迟消息来实现定时任务.最近正好因为开发碰到了使用过程中发现,延迟消息没有效果,消息直接就被消费了 ...

  9. 【mq读书笔记】定时消息

    mq不支持任意的时间京都,如果要支持,不可避免的需要在Broker层做消息排序,加上持久化方面的考量,将不可避免地带来巨大的性能消耗,所以rocketMQ只支持特定级别的延迟消息. 在Broker短通 ...

随机推荐

  1. hashlib(hmac)进阶之client跟server交互

    首先我还是要强调不管任何相同的字符串通过hashlib加密之后都会产生相同的32位字符串,这个是日常Web中常用的加密算法如果我的client发送一个请求过来我server接受到后就要对该密码进行判断 ...

  2. centos7 下 通过终端 连接 蓝牙设备

    #首先确定硬件上有支持蓝牙的设备,插入蓝牙发射器.然后运行如下命令,就可以开到我们的蓝牙设备了: lsusb [root@localhost ~]# lsusbBus 002 Device 003: ...

  3. 【MySQL高可用架构设计】(一)-- mysql复制功能介绍

    一. 介绍 Mysql的复制功能是构建基于SQL数据库的大规模高性能应用的基础,主要用于分担主数据库的读负载,同时也为高可用.灾难恢复.备份等工作提供了更多的选择. 二.为什么要使用mysql复制功能 ...

  4. 2016 ACM-ICPC Asia Regional Dalian Online HDU 5875 Function(线段树)

    题意 求区间l~r的a[l]%a[l+1]%--%a[r]的值 思路 因为取模的变化是很快的,所以线段树查找区间内第一个小于等于a[l]的数的位置,更新ans后继续查找即可. 注意查询满足某种条件的位 ...

  5. POJ 1321 棋盘问题 题解

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 70224 Accepted: 33254 Description 在一 ...

  6. 笔试12:Bootstrap知识

    BootStrap Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. ...

  7. 为什么tcp的TIME_WAIT状态要维持2MSL

    本文主要分析为什么TIME_WAIT状态的持续时间是2MSL而不是1MSL,3MSL或其它的时长,而不会详细描述为什么需要TIME_WAIT状态. 阅读本文需要的预备知识: 了解TCP协议的状态变迁: ...

  8. 201871010131-张兴盼《面向对象程序设计(java)》第十一周学习总结

    项目 内容 <面向对象程序设计(java)> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/ ...

  9. 网络服务—NFS

    什么是NFS ? NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操作 ...

  10. 04-人脸识别-triplets loss 的解释(转载)

    转载至: https://blog.csdn.net/tangwei2014/article/details/46788025 下面是内容: [前言] 最近,learning to rank 的思想逐 ...