Jaina 4.4.0

dotnet add package Jaina --version 4.4.0                
NuGet\Install-Package Jaina -Version 4.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jaina" Version="4.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jaina --version 4.4.0                
#r "nuget: Jaina, 4.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jaina as a Cake Addin
#addin nuget:?package=Jaina&version=4.4.0

// Install Jaina as a Cake Tool
#tool nuget:?package=Jaina&version=4.4.0                

Jaina

license nuget dotNET China

.NET 事件总线,简化项目、类库、线程、服务等之间的通信,代码更少,质量更好。‎

Jaina.drawio

源码解析

特性

  • 简化组件之间通信
    • 支持事件监视器
    • 支持动作执行器
    • 支持自定义消息存储组件
    • 支持自定义策略执行
    • 支持单消费、多消费消息
    • 支持消息幂等性处理
  • 高内聚,低耦合,使代码更简单
  • 非常快速,每秒可处理 30000 + 消息
  • 很小,仅 10KB
  • 无第三方依赖
  • 可在 Windows/Linux/MacOS 守护进程部署
  • 支持分布式、集群
  • 高质量代码和良好单元测试

安装

Install-Package Jaina
dotnet add package Jaina

快速入门

我们在主页上有不少例子,这是让您入门的第一个:

  1. 定义事件订阅者 ToDoEventSubscriber
// 实现 IEventSubscriber 接口
public class ToDoEventSubscriber : IEventSubscriber
{
    private readonly ILogger<ToDoEventSubscriber> _logger;
    public ToDoEventSubscriber(ILogger<ToDoEventSubscriber> logger)
    {
        _logger = logger;
    }

    [EventSubscribe("ToDo:Create")] // 支持多个
    [EventSubscribe(YourEnum.Message)]   // 支持枚举
    public async Task CreateToDo(EventHandlerExecutingContext context)
    {
        var todo = context.Source;
        _logger.LogInformation("创建一个 ToDo:{Name}", todo.Payload);
        await Task.CompletedTask;
    }

    // 支持枚举类型
    [EventSubscribe(YourEnum.Some)]
    public async Task EnumHandler(EventHandlerExecutingContext context)
    {
        var eventEnum = context.Source.EventId.ParseToEnum(); // 将事件 Id 转换成枚举对象
        await Task.CompletedTask;
    }

    // 支持正则表达式匹配
    [EventSubscribe("(^1[3456789][0-9]{9}$)|((^[0-9]{3,4}\\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\\([0-9]{3,4}\\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$))", FuzzyMatch = true)]
    public async Task RegexHandler(EventHandlerExecutingContext context)
    {
        var eventId = context.Source.EventId;
        await Task.CompletedTask;
    }

    // 支持多种异常重试配置
    [EventSubscribe("test:error", NumRetries = 3)]
    [EventSubscribe("test:error", NumRetries = 3, RetryTimeout = 1000)] // 重试间隔时间
    [EventSubscribe("test:error", NumRetries = 3, ExceptionTypes = new[] { typeof(ArgumentException) })]    // 特定类型异常才重试
    public async Task ExceptionHandler(EventHandlerExecutingContext context)
    {
        var eventId = context.Source.EventId;
        await Task.CompletedTask;
    }
}
  1. 创建控制器 ToDoController,依赖注入 IEventPublisher 服务:
public class ToDoController : ControllerBase
{
    // 依赖注入事件发布者 IEventPublisher
    private readonly IEventPublisher _eventPublisher;
    public ToDoController(IEventPublisher eventPublisher)
    {
        _eventPublisher = eventPublisher;
    }

    // 发布 ToDo:Create 消息
    public async Task CreateDoTo(string name)
    {
        await _eventPublisher.PublishAsync(new ChannelEventSource("ToDo:Create", name));
        // 简化版本
        await _eventPublisher.PublishAsync("ToDo:Create", name);
    }
}
  1. Startup.cs 注册 EventBus 服务:
// 注册 EventBus 服务
services.AddEventBus(builder =>
{
    // 注册 ToDo 事件订阅者
    builder.AddSubscriber<ToDoEventSubscriber>();

    // 通过类型注册
    builder.AddSubscriber(typeof(ToDoEventSubscriber));

    // 批量注册事件订阅者
    builder.AddSubscribers(ass1, ass2, ....);
});
  1. 运行项目:
info: Jaina.Samples.ToDoEventSubscriber[0]
      创建一个 ToDo:Jaina

更多文档

文档

您可以在主页找到 Jaina 文档。

贡献

该存储库的主要目的是继续发展 Jaina 核心,使其更快、更易于使用。Jaina 的开发在 Gitee 上公开进行,我们感谢社区贡献错误修复和改进。

许可证

Jaina 采用 MIT 开源许可证。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Jaina:

Package Downloads
Mk.FrameworkCore

Private development class library.

GM-W-04.Service

Package Description

DqCloud.Service

Package Description

HZPOST.Infrastructure

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.4.0 273 11/13/2024
4.3.0 4,695 3/18/2024 4.3.0 is deprecated because it is no longer maintained and has critical bugs.
4.2.0 217 2/3/2024 4.2.0 is deprecated because it is no longer maintained and has critical bugs.
4.1.2 8,143 4/13/2023 4.1.2 is deprecated because it is no longer maintained and has critical bugs.
4.1.1 2,845 3/6/2023 4.1.1 is deprecated because it is no longer maintained and has critical bugs.
4.1.0 256 2/22/2023 4.1.0 is deprecated because it is no longer maintained and has critical bugs.
4.0.0 2,487 11/23/2022 4.0.0 is deprecated because it is no longer maintained and has critical bugs.
3.2.0 348 10/31/2022 3.2.0 is deprecated because it is no longer maintained and has critical bugs.
3.1.3 1,887 8/30/2022 3.1.3 is deprecated because it is no longer maintained and has critical bugs.
3.1.2 178 8/30/2022 3.1.2 is deprecated because it is no longer maintained and has critical bugs.
3.1.1 351 8/24/2022 3.1.1 is deprecated because it is no longer maintained and has critical bugs.
3.1.0 188 8/24/2022 3.1.0 is deprecated because it is no longer maintained and has critical bugs.
3.0.1 848 8/17/2022 3.0.1 is deprecated because it is no longer maintained and has critical bugs.
3.0.0 5,789 8/1/2022 3.0.0 is deprecated because it is no longer maintained and has critical bugs.
2.0.1 8,358 6/9/2022 2.0.1 is deprecated because it is no longer maintained and has critical bugs.
2.0.0 2,420 11/11/2021 2.0.0 is deprecated because it is no longer maintained and has critical bugs.
1.0.9 1,269 11/1/2021 1.0.9 is deprecated because it is no longer maintained and has critical bugs.
1.0.8 432 11/1/2021 1.0.8 is deprecated because it is no longer maintained and has critical bugs.
1.0.7 467 10/29/2021 1.0.7 is deprecated because it is no longer maintained and has critical bugs.
1.0.6 459 10/29/2021 1.0.6 is deprecated because it is no longer maintained and has critical bugs.
1.0.5 561 10/27/2021 1.0.5 is deprecated because it is no longer maintained and has critical bugs.