Skip to content

Fast.EventBus 公开 API

目标 net8.0;net9.0;net10.0。本页为语法声明与 XML 注释参考,运行示例和边界见模块用法

源码提交:43554c07f6c216f80b509bd535c0a5b66ae7f2e8。维护流程:scripts/export-dotnet-api.ps1;普通站点构建直接消费此文件。

Fast.EventBus.EventSubscribeAttribute

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public sealed class EventSubscribeAttribute : Attribute

事件处理程序特性

说明:作用于 IEventSubscriber 实现类实例方法支持多个事件Id触发同一个事件处理程序

Fast.EventBus.EventSubscribeAttribute.EventSubscribeAttribute

源码 · 目标:net8.0、net9.0、net10.0

csharp
public EventSubscribeAttribute(object eventId)

初始化类的新实例

说明:只支持事件类型和 Enum 类型

  • 参数 eventId:日志事件标识

Fast.EventBus.EventSubscribeAttribute.EventId

源码 · 目标:net8.0、net9.0、net10.0

csharp
public string EventId { get; set; }

事件Id

Fast.EventBus.EventSubscribeAttribute.GCCollect

源码 · 目标:net8.0、net9.0、net10.0

csharp
public object GCCollect { get; set; } = false;

是否启用执行完成触发 GC 回收

说明:类型,默认关闭;通常应交由运行时自行决定垃圾回收时机

Fast.EventBus.EventSubscribeAttribute.NumRetries

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int NumRetries { get; set; } = 0;

重试次数

Fast.EventBus.EventSubscribeAttribute.RetryTimeout

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int RetryTimeout { get; set; } = 1000;

重试间隔时间

说明:默认 1000 毫秒

Fast.EventBus.EventSubscribeAttribute.ExceptionTypes

源码 · 目标:net8.0、net9.0、net10.0

csharp
public Type[] ExceptionTypes { get; set; }

可以指定特定异常类型才重试

Fast.EventBus.EventSubscribeAttribute.FallbackPolicy

源码 · 目标:net8.0、net9.0、net10.0

csharp
public Type FallbackPolicy { get; set; }

重试失败策略配置

Fast.EventBus.EventSubscribeAttribute.Order

源码 · 目标:net8.0、net9.0、net10.0

csharp
public int Order { get; set; } = 0;

排序

说明:数值越大的先执行

Fast.EventBus.EventHandlerContext

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public abstract class EventHandlerContext

事件处理程序上下文

Fast.EventBus.EventHandlerContext.Source

源码 · 目标:net8.0、net9.0、net10.0

csharp
public IEventSource Source { get; }

事件源(事件承载对象)

Fast.EventBus.EventHandlerContext.Properties

源码 · 目标:net8.0、net9.0、net10.0

csharp
public IDictionary<object, object> Properties { get; set; }

共享上下文数据

Fast.EventBus.EventHandlerContext.HandlerMethod

源码 · 目标:net8.0、net9.0、net10.0

csharp
public MethodInfo HandlerMethod { get; }

触发的方法

说明:如果是动态订阅,可能为 null

Fast.EventBus.EventHandlerContext.Attribute

源码 · 目标:net8.0、net9.0、net10.0

csharp
public EventSubscribeAttribute Attribute { get; }

订阅特性

说明:如果是动态订阅,可能为 null

Fast.EventBus.EventHandlerExecutedContext

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public sealed class EventHandlerExecutedContext : EventHandlerContext

事件处理程序执行后上下文

Fast.EventBus.EventHandlerExecutedContext.ExecutedTime

源码 · 目标:net8.0、net9.0、net10.0

csharp
public DateTime ExecutedTime { get; internal set; }

执行后时间

Fast.EventBus.EventHandlerExecutedContext.Exception

源码 · 目标:net8.0、net9.0、net10.0

csharp
public InvalidOperationException Exception { get; internal set; }

异常信息

Fast.EventBus.EventHandlerExecutingContext

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public sealed class EventHandlerExecutingContext : EventHandlerContext

事件处理程序执行前上下文

Fast.EventBus.EventHandlerExecutingContext.ExecutingTime

源码 · 目标:net8.0、net9.0、net10.0

csharp
public DateTime ExecutingTime { get; internal set; }

执行前时间

Fast.EventBus.EventBusExtension

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public static class EventBusExtension

提供事件总线扩展方法

Fast.EventBus.EventBusExtension.EventBusToString

源码 · 目标:net8.0、net9.0、net10.0

csharp
public static string EventBusToString(this Enum em)

将事件枚举Id转换成字符串对象

  • 参数 em:要转换为事件标识字符串的枚举值
  • 返回:将事件枚举Id转换成字符串对象

Fast.EventBus.EventBusExtension.EventBusToEnum

源码 · 目标:net8.0、net9.0、net10.0

csharp
public static Enum EventBusToEnum(this string str)

将事件枚举字符串转换成枚举对象

  • 参数 str:要处理的字符串
  • 返回:将事件枚举字符串转换成枚举对象

Fast.EventBus.IServiceCollectionExtension

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public static class IServiceCollectionExtension

IServiceCollection 提供动态 API 扩展方法

Fast.EventBus.IServiceCollectionExtension.AddEventBus

源码 · 目标:net8.0、net9.0、net10.0

csharp
public static IServiceCollection AddEventBus(this IServiceCollection services)

添加事件总线服务

  • 参数 services:要添加服务的服务集合
  • 返回:返回 services,便于链式调用

Fast.EventBus.IEventBusFactory

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventBusFactory

事件总线工厂

Fast.EventBus.IEventBusFactory.Subscribe

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task Subscribe(string eventId, Func<EventHandlerExecutingContext, Task> handler, EventSubscribeAttribute attribute = null,
        MethodInfo handlerMethod = null, CancellationToken cancellationToken = default);

添加事件订阅者

  • 参数 eventId:日志事件标识
  • 参数 handler:处理当前事件或请求的委托
  • 参数 attribute:EventSubscribeAttribute 特性对象
  • 参数 handlerMethod:事件处理器方法
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“添加事件订阅者”操作的任务

Fast.EventBus.IEventBusFactory.Unsubscribe

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task Unsubscribe(string eventId, CancellationToken cancellationToken = default);

删除事件订阅者

  • 参数 eventId:日志事件标识
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“删除事件订阅者”操作的任务

Fast.EventBus.IEventSubscriber

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventSubscriber

事件订阅者依赖接口

说明:可自定义事件处理方法,但须符合 Func{EventSubscribeExecutingContext, Task} 签名通常只做依赖查找,不做服务调用

Fast.EventBus.IEventHandlerMonitor

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventHandlerMonitor

事件处理程序监视器

Fast.EventBus.IEventHandlerMonitor.OnExecutingAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task OnExecutingAsync(EventHandlerExecutingContext context);

事件处理程序执行前

  • 参数 context:当前事件处理上下文
  • 返回:表示异步“事件处理程序执行前”操作的任务

Fast.EventBus.IEventHandlerMonitor.OnExecutedAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task OnExecutedAsync(EventHandlerExecutedContext context);

事件处理程序执行后

  • 参数 context:当前事件处理上下文
  • 返回:表示异步“事件处理程序执行后”操作的任务

Fast.EventBus.IEventFallbackPolicy

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventFallbackPolicy

事件重试失败回调服务

Fast.EventBus.IEventFallbackPolicy.CallbackAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task CallbackAsync(EventHandlerExecutingContext context, Exception ex);

重试失败回调

  • 参数 context:当前事件处理上下文
  • 参数 ex:触发当前处理流程的异常
  • 返回:表示异步“重试失败回调”操作的任务

Fast.EventBus.IEventPublisher

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventPublisher

事件发布服务依赖接口

Fast.EventBus.IEventPublisher.PublishAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishAsync(IEventSource eventSource);

发布一条消息

  • 参数 eventSource:要发布的事件消息
  • 返回:表示异步“发布一条消息”操作的任务

Fast.EventBus.IEventPublisher.PublishDelayAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishDelayAsync(IEventSource eventSource, long delay);

延迟发布一条消息

  • 参数 eventSource:要发布的事件消息
  • 参数 delay:延迟执行时长
  • 返回:表示异步“延迟发布一条消息”操作的任务

Fast.EventBus.IEventPublisher.PublishAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishAsync(string eventId, object payload = null, CancellationToken cancellationToken = default);

发布一条消息

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“发布一条消息”操作的任务

Fast.EventBus.IEventPublisher.PublishAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishAsync(Enum eventId, object payload = null, CancellationToken cancellationToken = default);

发布一条消息

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“发布一条消息”操作的任务

Fast.EventBus.IEventPublisher.PublishDelayAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishDelayAsync(string eventId, long delay, object payload = null, CancellationToken cancellationToken = default);

延迟发布一条消息

  • 参数 eventId:日志事件标识
  • 参数 delay:延迟执行时长
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“延迟发布一条消息”操作的任务

Fast.EventBus.IEventPublisher.PublishDelayAsync

源码 · 目标:net8.0、net9.0、net10.0

csharp
Task PublishDelayAsync(Enum eventId, long delay, object payload = null, CancellationToken cancellationToken = default);

延迟发布一条消息

  • 参数 eventId:日志事件标识
  • 参数 delay:延迟执行时长
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌
  • 返回:表示异步“延迟发布一条消息”操作的任务

Fast.EventBus.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public sealed class ChannelEventSource : IEventSource

内存通道事件源(事件承载对象)

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource()

初始化类的新实例

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(string eventId)

初始化类的新实例

  • 参数 eventId:日志事件标识

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(string eventId, object payload) : this(eventId)

初始化类的新实例

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(string eventId, object payload, CancellationToken cancellationToken) : this(eventId, payload)

初始化类的新实例

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(Enum eventId) : this(eventId.EventBusToString())

初始化类的新实例

  • 参数 eventId:日志事件标识

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(Enum eventId, object payload) : this(eventId.EventBusToString(), payload)

初始化类的新实例

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷

Fast.EventBus.ChannelEventSource.ChannelEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
public ChannelEventSource(Enum eventId, object payload, CancellationToken cancellationToken) : this(
        eventId.EventBusToString(), payload, cancellationToken)

初始化类的新实例

  • 参数 eventId:日志事件标识
  • 参数 payload:要写入令牌的载荷
  • 参数 cancellationToken:用于取消异步操作的令牌

Fast.EventBus.ChannelEventSource.EventId

源码 · 目标:net8.0、net9.0、net10.0

csharp
public string EventId { get; set; }

说明继承自接口或基类,需结合对应声明阅读。

Fast.EventBus.ChannelEventSource.Payload

源码 · 目标:net8.0、net9.0、net10.0

csharp
public object Payload { get; set; }

说明继承自接口或基类,需结合对应声明阅读。

Fast.EventBus.ChannelEventSource.CreatedTime

源码 · 目标:net8.0、net9.0、net10.0

csharp
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;

说明继承自接口或基类,需结合对应声明阅读。

Fast.EventBus.ChannelEventSource.CancellationToken

源码 · 目标:net8.0、net9.0、net10.0

csharp
[JsonIgnore]
    public CancellationToken CancellationToken { get; set; }

说明继承自接口或基类,需结合对应声明阅读。

Fast.EventBus.IEventSource

源码 · 目标:net8.0、net9.0、net10.0

csharp
[SuppressSniffer]
public interface IEventSource

事件源(事件承载对象)依赖接口

Fast.EventBus.IEventSource.EventId

源码 · 目标:net8.0、net9.0、net10.0

csharp
string EventId { get; }

事件Id

Fast.EventBus.IEventSource.Payload

源码 · 目标:net8.0、net9.0、net10.0

csharp
object Payload { get; }

事件承载(携带)数据

Fast.EventBus.IEventSource.CreatedTime

源码 · 目标:net8.0、net9.0、net10.0

csharp
DateTime CreatedTime { get; }

事件创建时间

Fast.EventBus.IEventSource.CancellationToken

源码 · 目标:net8.0、net9.0、net10.0

csharp
CancellationToken CancellationToken { get; }

取消任务 Token

说明:用于取消本次消息处理