ActiveMq C# 消息特性:延迟和定时消息投递
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);ActiveMq C# 消息特性:延迟和定时消息投递的更多相关文章
- JMS学习(八)-ActiveMQ Consumer 使用 push 还是 pull 获取消息
ActiveMQ是一个消息中间件,对于消费者而言有两种方式从消息中间件获取消息: ①Push方式:由消息中间件主动地将消息推送给消费者:②Pull方式:由消费者主动向消息中间件拉取消息.看一段官网对P ...
- RabbitMQ使用 prefetch_count优化队列的消费,使用死信队列和延迟队列实现消息的定时重试,golang版本
RabbitMQ 的优化 channel prefetch Count 死信队列 什么是死信队列 使用场景 代码实现 延迟队列 什么是延迟队列 使用场景 实现延迟队列的方式 Queue TTL Mes ...
- activemq的高级特性:消息持久订阅
activemq的高级特性之消息持久订阅 如果采用topic模式发送的时候,mq关闭了或消费者关闭了.在启动的时候,就会收不到mq发送的消息,所以就会出现消息持久订阅. 消息持久订阅:第一:消息要持久 ...
- activemq的高级特性:消息的可靠性
高级特性之消息的可靠性 可靠性分为:生产者.消费者.生产者必须让mq收到消息,消费者必须能够接收到消息并且消费成功,这就是消息的可靠性. 1:生产者可靠性 Session session = conn ...
- 一文带你认知定时消息发布RocketMQ
摘要:DMS任意时间定时消息能力发布. DMS是华为云的分布式消息中间件服务.适用于解决分布式架构中的系统解耦.跨系统跨地域数据流通.分布式事务协调等难题,协助构建优雅的现代化应用架构,提供可兼容 K ...
- Apache ActiveMQ实战(1)-基本安装配置与消息类型
ActiveMQ简介 ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信.ActiveMQ使用Apache ...
- MQ发送定时消息
通过延时发送来发送定时消息. RocketMQ只支持固定精度时间的延时消息发送:1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 若 ...
- RabbitMQ延迟消息的延迟极限是多少?
之前在写Spring Cloud Stream专题内容的时候,特地介绍了一下如何使用RabbitMQ的延迟消息来实现定时任务.最近正好因为开发碰到了使用过程中发现,延迟消息没有效果,消息直接就被消费了 ...
- 【mq读书笔记】定时消息
mq不支持任意的时间京都,如果要支持,不可避免的需要在Broker层做消息排序,加上持久化方面的考量,将不可避免地带来巨大的性能消耗,所以rocketMQ只支持特定级别的延迟消息. 在Broker短通 ...
随机推荐
- spark2.4.2 源码编译
基于Maven的构建是Apache Spark的参考构建.使用Maven构建Spark需要Maven 3.5.4和Java 8.请注意,从Spark 2.2.0开始,对Java 7的支持已被删除. 包 ...
- Prometheus node_exporter grafana部署安装
1.环境 centos7 prometheus-2.10.0.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64.tar.gz 2.安装 创建sys ...
- django学习-管理界面、视图
django管理界面 设计背景 为你的员工或客户生成一个用户添加,修改和删除内容的后台是一项缺乏创造性和乏味的工作.因此,django全自动地根据模型创建后台界面. django产生于一个公众页面和内 ...
- 【入门篇一】SpringBoot简介(1)
官网:https://spring.io/projects/spring-boot 一.什么是SpringBoot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新S ...
- Redis笔记2-Redis安装、配置
下载安装包 wget http://download.redis.io/releases/redis-4.0.8.tar.gz解压 tar xzvf redis-4.0.8.tar.gz安装 cd r ...
- JavaScript中的对象与原型—你不知道的JavaScript上卷读书笔记(四)
一.对象 对象可以通过两种形式定义:声明(文字)形式和构造形式.即: var myObj = { key: value // ... }; 或: var myObj = new Object(); m ...
- 【oracle】存储过程:将select查询的结果存到变量中
- 使用arthas 生成火焰图分析jvm
arthas 是阿里巴巴开源的强大的jvm 应该分析工具,以下是使用arthas 生成jvm 火焰图的一个学习 项目使用docker-compose 运行,对于生成的火焰图使用nginx 提供一个访问 ...
- js将字符串内空格去除的方法
function noSpace(x){ if(x.match(/\s*/g)){ return x.replace(/\s*/g,""); }else{ return x; } ...
- 关于被malloc分配内存的指针
例如创建了一个链表指针p并为其malloc()分配了内存,那么这个指针指向的地方其实是有数据的. 你可以把p->data打印出来,会发现是一个随机值 因为只是分配内存而没有指定data的值,所以 ...