标签:tst serial 成功 存在 back new object pos handle
public abstract class Event
{
public Event()
{
Id = Guid.NewGuid();
CreationTime = DateTime.UtcNow;
}
public Guid Id { get; set; }
public DateTime CreationTime { get; set; }
}
public class PublishEvent : Event
{
public PublishEvent(Event @event)
{
Id = @event.Id;
CreationTime = @event.CreationTime;
Type = @event.GetType().FullName;
Data = JsonConvert.SerializeObject(@event);
Status = PublishEventStatus.NotPublished;
}
public String Type { get; set; }
public String Data { get; set; }
public PublishEventStatus Status { get; set; }
}
public enum PublishEventStatus
{
NotPublished = 0,
Published = 1,
PublishedFailed = 2
}
public class SubscribeEvent
{
public SubscribeEvent(Event @event, IEventHandler handler)
{
EventId = @event.Id;
EventCreationTime = @event.CreationTime;
EventType = @event.GetType().FullName;
EventData = JsonConvert.SerializeObject(@event);
HandlerType = handler.GetType().FullName;
HandlingStatus = HandlingStatus.HandleSucceeded;
HandlingTime = DateTime.Now;
}
public Guid EventId { get; set; }
public String EventType { get; set; }
public String EventData { get; set; }
public DateTime EventCreationTime { get; set; }
public String HandlerType { get; set; }
public DateTime HandlingTime { get; set; }
public HandlingStatus HandlingStatus { get; set; }
}
public enum HandlingStatus
{
HandleSucceeded = 0,
HandleFailed = 1
}
try
{
BeginTransaction(); // ①
//Biz Flow
EventRepository.PubilshEvent(@event);// ②
CommitTransaction();
}
catch(Exception ex){
RollbackTransaction();
throw ex;
}
EventBus.Publish(@event); // ③
EventResitory.EventPublished(@event.ToString()); // ④
try
{
BeginTransaction();
//Biz Flow
EventRepository.SubscribeEvent(@event , eventHandler); // ⑤
CommitTransaction();
}
catch(Exception ex){
RollbackTransaction();
throw ex;
}
Install-Package SmartEventBus.RabbitMQImpl
Install-Package SmartEventBus.Repository
SmartSql = Dapper + MyBatis + Cache(Memory | Redis) + ZooKeeper + R/W Splitting + ......
如何通过本地化事件正确实现微服务内部强一致性,事件总线跨微服务间最终一致性
标签:tst serial 成功 存在 back new object pos handle
原文地址:https://www.cnblogs.com/Ahoo-Wang/p/micoservice-eventbus.html