惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
Y
Y Combinator Blog
博客园_首页
有赞技术团队
有赞技术团队
博客园 - Franky
腾讯CDC
G
Google Developers Blog
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
D
Docker
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
V
V2EX
U
Unit 42
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学

博客园 - Leo

在Windows上使用Docker 创建MongoDB 副本集的极简方法(翻译) 19-EasyNetQ:用EasyNetQ.Hosepipe重新提交错误信息 18-EasyNetQ:发生错误的情况 17-EasyNetQ:非泛型的发布&订阅扩展方法 16-EasyNetQ之自动订阅者 15-EasyNetQ之对延迟消息插件的支持 - Leo - 博客园 13-EasyNetQ之发布者确认 12-EasyNetQ之消息版本控制 11-EasyNetQ之多态发布和订阅 10-EasyNetQ之控制队列名称 9-EasyNetQ之基于主题的路由 - Leo - 博客园 8-EasyNetQ之Send & Receive 7-EasyNetQ之Request & Response 6-EasyNetQ之订阅 5-EasyNetQ之Publish(黄亮翻译) 4-EasyNetQ之Logging(黄亮翻译) 3-在EasyNetQ上使用SSL连接(黄亮翻译) 2-用EasyNetQ连接RabbitMQ(黄亮翻译) 1-EasyNetQ介绍(黄亮翻译) - Leo - 博客园
14-EasyNetQ之用Future Publish发布预定中事件
Leo · 2017-07-11 · via 博客园 - Leo

很多商业流程需要事件在未来的时间按照预定时间发布。例如,在初次与客户接触后,可以在未来某个时间去电话回访客户。EasyNetQ可以用它的Future Publish功能帮你实现这个功能。举例:这里我们使用FuturePublish扩展方法去预定未来一个月后打销售回访电话。注意:FuturePublish使用UTC时间。

var followUpCallMessage = new FollowUpCallMessage(..);

bus.FuturePublish(DateTime.UtcNow.AddMonths(1),followUpCallMessage);

从现在开始一个月后,这个消息通过EasyNetQ将会发布这个消息,任何FollowUpCallMessage的订阅者将接收到一个原始消息拷贝。

FuturePublish需要EasyNetQ.Scheduler服务处于运行中状态。

它是如何运作的?

当你调用bus.FuturePublish(publishDate,Message)时,EasyNetQ包装这个消息到一个系统消息'ScheduleMe'中,然后发布这个消息到RabbitMQ。这个调度服务订阅这个消息。当它接收到一个ScheduleMe消息时,它会存储这个消息到它的本地数据库中,这个调度服务去数据库查询日程日期到期的消息,当有任何消息到期时,它会从这个ScheduleMe消息中解开原始的消息,然后发送消息到事件总线。

安装调度服务

  1. 在SQL Server中,创建一个名称为EasyNetQ.Scheduler的数据库。

  2. 获取EasyNetQ源码

git clone git@github.com:mikehadlow/EasyNetQ.git
  1. 在Visual Studio中打开EasyNetQ.2012这个解决方案。在DatabaseScripts->EasyNetQ.Scheduler文件夹下你会发现一些SQL脚本。在EasyNetQ.Scheduler数据库中打开并执行这些脚本。你需要先执行CreateWorkTables.sql,其他是存储过程脚本,执行这些脚本没有先后顺序。

  2. 编译这个解决方案。

  3. 找到\Source\EasyNetQ.Scheduler\bin\Debug 这个文件夹,拷贝其下所有文件到你选择的部署文件夹中。

  4. 用一个文本编辑器打开EasyNetQ.Scheduler.exe.Config ,修改'rabbit'和'scheduleDb'连接字符串为你的RabbitMQ代理和SQL Server各自的实例。

  5. 打开控制台窗口,进入你部署EasyNetQ.Scheduler所在的文件夹。

  6. 运行后面的命令,把EasyNetQ.Scheduler安装为一个windows 服务。

EasyNetQ.Scheduler.exe install

执行后,显示下面信息:

Configuration Result: [Success] Name EasyNetQ.Scheduler [Success] ServiceName EasyNetQ.Scheduler Topshelf v3.1.106.0, .NET Framework v4.0.30319.18051

Running a transacted installation.

Beginning the Install phase of the installation. Installing EasyNetQ.Scheduler service Installing service EasyNetQ.Scheduler... Service EasyNetQ.Scheduler has been successfully installed. Creating EventLog source EasyNetQ.Scheduler in log Application...

The Install phase completed successfully, and the Commit phase is beginning.

The Commit phase completed successfully.

The transacted install has completed.

现在你应该能够调用FuturePublish方法,在指定时间到来时,你会收到消息。

卸载EasyNetQ.Scheduler,运行:

EasyNetQ.Scheduler.exe uninstall

英文地址:https://github.com/EasyNetQ/EasyNetQ/wiki/Scheduling-Events-with-Future-Publish
本文地址:http://www.cnblogs.com/HuangLiang/p/EasyNetQ_Scheduling_Events_with_Future_Publish.html
我的微信订阅号:open_dotNET