https://github.com/dotnetcore/CAP

安装命令

PM> Install-Package DotNetCore.CAP

CAP supports most popular message queue as transport, following packages are available to install:

CAP 支持最流行的消息队列作为传输方式,可以安装以下软件包:

PM> Install-Package DotNetCore.CAP.Kafka
PM> Install-Package DotNetCore.CAP.RabbitMQ
PM> Install-Package DotNetCore.CAP.AzureServiceBus
PM> Install-Package DotNetCore.CAP.AmazonSQS
PM> Install-Package DotNetCore.CAP.NATS
PM> Install-Package DotNetCore.CAP.RedisStreams
PM> Install-Package DotNetCore.CAP.Pulsar

CAP 支持最流行的数据库作为事件存储,可以安装以下软件包:

PM> Install-Package DotNetCore.CAP.SqlServer
PM> Install-Package DotNetCore.CAP.MySql
PM> Install-Package DotNetCore.CAP.PostgreSql
PM> Install-Package DotNetCore.CAP.MongoDB     //need MongoDB 4.0+ cluster

业务应用

using System;
using RG3.PF.Abstractions.Entity;
using RG3.PF.Abstractions.Interfaces;
using RG3.BO.Abstractions.Entity;
using RG3.BO.Popedom.Repository;
using RG3.DO.Abstractions.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using DotNetCore.CAP;
using RG3.PF.Web.StartUsed.Interfaces;

namespace RG3.PF.Web.StartUsed.Providers
{
    /// <summary>
    /// 订阅和发布事件总线
    /// </summary>
    public partial class PushPullEvntBusProvider : IPushPullEvntBusProvider,ICapSubscribe
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="datetime"></param>
        [CapSubscribe("xxx.services.show.time")]
        public void CheckReceivedMessage(DateTime datetime)
        {
            Console.WriteLine($"事件总线:{datetime}");
        }
    }
}
  /// <summary>
        /// 事件总线
        /// </summary>
        private readonly ICapPublisher _capBus;

        /// <summary>
        /// 注入服务 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="config"></param>
        public DefaultController(ICapPublisher capPublisher)
        {
            _capBus = capPublisher;

        }

        /// <summary>
        /// 测试接口是否正式启动
        /// </summary>
        /// <returns></returns>
        [HttpGet()]
        public ResultDetail<string> TestSuccess()
        {

            _capBus.Publish("xxx.services.show.time", DateTime.Now);

        }
文档更新时间: 2022-04-14 05:41   作者:admin