当前位置:网站首页>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}");
}
}
边栏推荐
- Postgresql14 installation and use tutorial
- Wait function in SystemC
- 测试工程师如何转型测开
- C secret arts script Chapter 2 (detailed explanation of pointers) (Section 3)
- Leetcode 2176. Count equal and divisible pairs in an array
- JS (II) syntaxerror: cannot use import statement outside a module
- Conversion of player's actual 10 pixel format and size
- And, or, not equal, operator
- Mémoire de l'examen d'entrée à l'université
- Solve the problem that IEEE latex template cannot display Chinese
猜你喜欢

我愿称之为史上最全的深度学习面经总结(附答案详解)

QT realize picture dragging

【OCR】AspriseOCR C# 英文、数字识别(中文不行)

JS (II) syntaxerror: cannot use import statement outside a module

Redis核心配置和高级数据类型

Player practice 17 xvideowidget

新技术:高效的自监督视觉预训练,局部遮挡再也不用担心!

Introduction to QT reflection mechanism and signal slot mechanism

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

Player practice 20 unpacking thread
随机推荐
Appnium (I) basic use of appnium
Leetcode 2185. 统计包含给定前缀的字符串
Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?
What is automatic bidding? What are its advantages?
chapter19 Allocation
In C language, the main function calls another function, which is understood by assembly code
Array one
[early knowledge of activities] list of recent activities of livevideostack
Codeforces Round #798 (Div. 2)(A~D)
Nesting of C language annotations
Remote code injection
Player practice 26 adding slider and window maximization
Variable parameters
Notepad common settings
Soft test (VI) Chrome browser installation selenium IDE
Location (I) error: command erred out with exit status
Huawei equipment is configured with H virtual private network
Communication flow analysis
Create a slice slice pit using the make method
SystemC:SC_ Thread and SC_ METHOD