• 关于ABP通知功能的使用心得


    1.如果想使用ABP的通知功能,首先需要在你的业务类中注入 INotificationPublisher 接口。

    比如: private readonly INotificationPublisher _notiticationPublisher; ,然后再通过构造方法注入。它的作用就是发布通知。

    2.注入 INotificationPublisher 之后,调用它的 Publish 方法,比如:

    _notiticationPublisher.Publish("SentFrendshipRequest",
        new SentFrendshipRequestNotificationData("admin", "test_xxxxx"),
        userIds: new[] { new UserIdentifier(AbpSession.TenantId, AbpSession.UserId.To<long>()) }
    );

    它还有另外一个方法: PublishAsnyc 用于异步发布。

    这两个方法的第2个参数是一个自定义的类,继承了NotificationData,你可以随便定义你想要的类,只要继承NotificationData就行了。

    3.新建一个 RabbitMqNotifier 类,实现 IRealTimeNotifier 接口,比如:

        /// <summary>
        /// 
        /// </summary>
        public class RabbitMqNotifier : IRealTimeNotifier, ITransientDependency
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="userNotifications"></param>
            public void SendNotifications(UserNotification[] userNotifications)
            {
                throw new NotImplementedException();
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="userNotifications"></param>
            /// <returns></returns>
            public Task SendNotificationsAsync(UserNotification[] userNotifications)
            {
                throw new NotImplementedException();
            }
        }

    3.1.如果发布时使用的同步方法,那么 SendNotifications 方法会起作用;如果发布时用的是异步方法,那么 SendNotificationsAsync 方法会起作用。
    3.2.需要在你的Module类里面配置你定义的这个Notifier: Configuration.Notifications.Notifiers.Add<RabbitMqNotifier>(); 网上很多资料都没说明要加这个。
    3.3. _notiticationPublisher 调用发布方法时,通过看其源码,里面有调用 IRealTimeNotifier 的实现类, IRealTimeNotifier 是通过构造方法注入的。

    此处订阅省略。。。

    特此记录下来,以防忘记。

  • 相关阅读:
    成员对象和封闭类
    静态成员
    this指针
    类型构造构造函数
    拷贝构造函数
    C++
    矩阵快速幂求递推式
    对浅拷贝和深拷贝的基本理解
    传引用作为形参和返回值_节省参数拷贝的时间
    namespace的基本知识
  • 原文地址:https://www.cnblogs.com/subendong/p/16019792.html
Copyright © 2020-2023  润新知