当前位置:网站首页>NetCore结合CAP事件总线实现分布式事务——消息(2)
NetCore结合CAP事件总线实现分布式事务——消息(2)
2022-06-12 14:18:00 【有诗亦有远方】
一、CAP 中的自定义配置
- DefaultGroupName
默认值:cap.queue.{
程序集名称}
- TopicNamePrefix
为 Topic 统一添加前缀。 https://github.com/dotnetcore/CAP/pull/780
- Version
默认值:v1
这是在CAP v2.4 版本中引入的新配置项,用于给消息指定版本来隔离不同版本服务的消息,常用于A/B测试或者多服务版本的场景
- FailedRetryInterval
默认值:60 秒
在消息发送的时候,如果发送失败,CAP将会对消息进行重试,此配置项用来配置每次重试的间隔时间
- SucceedMessageExpiredAfter
默认值:24*3600 秒(1天后)
成功消息的过期时间(秒)。 当消息发送或者消费成功时候,在时间达到 SucceedMessageExpiredAfter 秒时候将会从 Persistent 中删除,你可以通过指定此值来设置过期的时间。
二、补偿事务
某些情况下,消费者需要返回值以告诉发布者执行结果,以便于发布者实施一些动作,通常情况下这属于补偿范围。
你可以在消费者执行的代码中通过重新发布一个新消息来通知上游,CAP 提供了一种简单的方式来做到这一点。 你可以在发送的时候指定 callbackName 来得到消费者的执行结果,通常这仅适用于点对点的消费
1.发布
1.发布者,发布路由键为angel消息
2.收到发布的订阅者,处理消息
3.返回处理结果
4.发布者,调用回调函数来
5.发布消息,路由键为,image
6.订阅者image,收到发布,处理消息
_capBus.Publish("angel", contentObj: new Person {
Id = 1, Name = "11" },callbackName:"image");
[NonAction]
[CapSubscribe("angel")]
public Person ReceiveMsg(Person str)
{
if(str!=null)
{
Console.WriteLine($"接收{
str.Id}");
_log.LogInformation($"我是订阅者,收到的内容为:{
str.Id},{
str.Name}");
//处理完的结果,返回回去
return str;
}
throw new Exception();
}
[NonAction]
[CapSubscribe("image")]
public void CallBackMsg(Person str)
{
if(str!=null)
{
Console.WriteLine($"回调{
str.Id}");
_log.LogInformation($"我是回调,回调的内容为:{
str.Id},{
str.Name}");
}
}
边栏推荐
- Shell脚本到底是什么高大上的技术吗?
- 工业机械臂(机器人)视觉定位引导系统
- Implementation and debug of process hiding under x64
- 程序分析与优化 - 6 循环优化
- IAT hook hijacking process API call
- JS (III) convert ES6 syntax to Es5 syntax
- 面向优化科学研究领域的软件包
- SystemC:SC_ Thread and SC_ METHOD
- C secret script Chapter 1: data storage (in-depth analysis) supplement
- Soft test (VI) Chrome browser installation selenium IDE
猜你喜欢

Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?

Copy word content to excel and automatically divide it into multiple columns
![[early knowledge of activities] list of recent activities of livevideostack](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[early knowledge of activities] list of recent activities of livevideostack

C語言中主函數調用另外一個函數,匯編代碼理解

Easygui query the company name in the document

Shell脚本到底是什么高大上的技术吗?

华为设备配置BGP AS号替换

TestEngine with ID ‘junit-vintage‘ failed to discover tests

Introduction to QT reflection mechanism and signal slot mechanism

高考回忆录
随机推荐
How to set, reset and reverse bit
WinDbg preview debug analysis createtoolhelp32snapshot
Reverse the encryption parameters of a hot water software
Huawei equipment is configured with H virtual private network
Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?
Appnium (II) installation and basic use of mitmproxy
Lua callinfo structure, stkid structure resolution
Tool notes - common custom tool classes (regular, random, etc.)
QT multi thread drawing and real-time refreshing method
SystemC:SC_ Thread and SC_ METHOD
C secret script Chapter 3 (detailed explanation of string function) (Section 2)
Two methods of implementing asynchronous calling function with QT
Crack WinRAR to ad pop-up window
华为设备配置OSPF伪连接
chapter19 Allocation
Player actual combat 21 audio and video synchronization
Printing colored messages on the console with printf
Easygui query the company name in the document
OAuth2学习中的一些高频问题的QA
Player practice 18 xresample