当前位置:网站首页>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}");
}
}
边栏推荐
- Reverse analysis from x86 to x64tips
- Socket model of punctual atom stm32f429 core board
- C secret arts script Chapter 2 (detailed explanation of pointer) (Section 1)
- 对某热水软件的加密参数逆向
- If you want to build brand awareness, what bidding strategy can you choose?
- Location (I) error: command erred out with exit status
- For cross-border e-commerce, the bidding strategy focusing more on revenue - Google SEM
- Player actual combat 12 QT playing audio
- Recursive summary of learning function
- Player practice 15 xdemux and avcodecparameters
猜你喜欢
Redis core configuration and advanced data types
Player actual combat 21 audio and video synchronization
程序分析与优化 - 6 循环优化
Perfect ending | detailed explanation of the implementation principle of go Distributed Link Tracking
Dynamic search advertising intelligent search for matching keywords
Postgresql14 installation and use tutorial
通信流量分析
Lua callinfo structure, stkid structure resolution
Player practice 18 xresample
【OCR】AspriseOCR C# 英文、數字識別(中文不行)
随机推荐
Player practice 26 adding slider and window maximization
G++ error in compiling Win32 program: undefined reference to '__ imp_ GetStockObject‘
C secret arts script Chapter 2 (detailed explanation of pointer) (Section 2)
Simple code implementation of addition, subtraction, multiplication and division calculator
PMP agile knowledge points
String concatenation and ternary operators
QA of some high frequency problems in oauth2 learning
Player practice 15 xdemux and avcodecparameters
Is Shell Scripting really a big technology?
JS (III) convert ES6 syntax to Es5 syntax
新技术:高效的自监督视觉预训练,局部遮挡再也不用担心!
Huawei equipment is configured with H virtual private network
The difference between parameter and argument in C language
And, or, not equal, operator
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
Crawler problem set (I) record
Two months' experience in C language
Player practice 11 audio resampling
Player actual combat 25 unpacking module add close
QT link error: undefined reference to VTable for "XXX“