コード例 #1
0
        /// <summary>
        /// 在 Rabbit 服务器中添加一个订阅方法。
        /// </summary>
        /// <param name="subjectType">主题的类型。</param>
        /// <param name="subscriber">读取主题的方法。</param>
        public void AddSubscriber(Type subjectType, Delegate subscriber)
        {
            var channelName = ChannelHelper.GetChannelName(subjectType);
            var list        = subscribers.GetOrAdd(channelName, () => new RabbitChannelCollection());

            list.Add(new RabbitChannel(subscriber, StartQueue(channelName)));
        }
コード例 #2
0
ファイル: SubscribeManager.cs プロジェクト: wushian/fireasy2
        /// <summary>
        /// 在 Redis 服务器中添加一个订阅方法。
        /// </summary>
        /// <param name="subjectType">主题的类型。</param>
        /// <param name="subscriber">读取主题的方法。</param>
        public void AddSubscriber(Type subjectType, Delegate subscriber)
        {
            var client      = GetConnection();
            var channelName = ChannelHelper.GetChannelName(subjectType);

#if NETSTANDARD
            client.Subscribe((channelName, msg =>
            {
                var subject = Deserialize(subjectType, msg.Body);
                if (subject != null)
                {
                    subscriber.DynamicInvoke(subject);
                }
            }
                              ));
#else
            client.GetSubscriber().Subscribe(channelName, (channel, value) =>
            {
                var subject = Deserialize(subjectType, Encoding.UTF8.GetString(value));
                if (subject != null)
                {
                    subscriber.DynamicInvoke(subject);
                }
            });
#endif
        }
コード例 #3
0
        /// <summary>
        /// 向 Rabbit 服务器发送消息主题。
        /// </summary>
        /// <typeparam name="TSubject"></typeparam>
        /// <param name="subject">主题内容。</param>
        public void Publish <TSubject>(TSubject subject) where TSubject : class
        {
            var channelName = ChannelHelper.GetChannelName(typeof(TSubject));
            var data        = Serialize(subject);

            Publish(channelName, data);
        }
コード例 #4
0
        /// <summary>
        /// 移除相关的订阅方法。
        /// </summary>
        /// <param name="subjectType">主题的类型。</param>
        public void RemoveSubscriber(Type subjectType)
        {
            var client      = GetConnection();
            var channelName = ChannelHelper.GetChannelName(subjectType);

            RemoveSubscriber(channelName);
        }
コード例 #5
0
ファイル: SubscribeManager.cs プロジェクト: wushian/fireasy2
        /// <summary>
        /// 移除相关的订阅方法。
        /// </summary>
        /// <param name="subjectType">主题的类型。</param>
        public void RemoveSubscriber(Type subjectType)
        {
            var client      = GetConnection();
            var channelName = ChannelHelper.GetChannelName(subjectType);

#if NETSTANDARD
#else
            client.GetSubscriber().Unsubscribe(channelName);
#endif
        }
コード例 #6
0
        /// <summary>
        /// 在 Rabbit 服务器中添加一个订阅方法。
        /// </summary>
        /// <param name="subjectType">主题的类型。</param>
        /// <param name="subscriber">读取主题的方法。</param>
        public void AddSubscriber(Type subjectType, Delegate subscriber)
        {
            var channelName = ChannelHelper.GetChannelName(subjectType);
            var list        = subscribers.GetOrAdd(channelName, k =>
            {
                StartQueue(channelName);
                return(new List <Delegate>());
            });

            list.Add(subscriber);
        }
コード例 #7
0
ファイル: SubscribeManager.cs プロジェクト: wushian/fireasy2
        /// <summary>
        /// 向 Redis 服务器发送消息主题。
        /// </summary>
        /// <typeparam name="TSubject"></typeparam>
        /// <param name="subject">主题内容。</param>
        public void Publish <TSubject>(TSubject subject) where TSubject : class
        {
#if NETSTANDARD
            var client      = GetConnection();
            var channelName = ChannelHelper.GetChannelName(typeof(TSubject));
            client.Publish(channelName, Serialize(subject));
#else
            var data        = Encoding.UTF8.GetBytes(Serialize(subject));
            var channelName = ChannelHelper.GetChannelName(typeof(TSubject));
            Publish(channelName, data);
#endif
        }
コード例 #8
0
ファイル: SubscribeManager.cs プロジェクト: wushian/fireasy2
        /// <summary>
        /// 在 Redis 服务器中添加一个订阅方法。
        /// </summary>
        /// <typeparam name="TSubject"></typeparam>
        /// <param name="subscriber">读取主题的方法。</param>
        public void AddSubscriber <TSubject>(Action <TSubject> subscriber) where TSubject : class
        {
            var client      = GetConnection();
            var channelName = ChannelHelper.GetChannelName(typeof(TSubject));

#if NETSTANDARD
            client.Subscribe((channelName, msg =>
            {
                var subject = Deserialize <TSubject>(msg.Body);
                subscriber(subject);
            }
                              ));
#else
            client.GetSubscriber().Subscribe(channelName, (channel, value) =>
            {
                var subject = Deserialize <TSubject>(Encoding.UTF8.GetString(value));
                subscriber(subject);
            });
#endif
        }
コード例 #9
0
 public string GetChannelText(string id)
 {
     return(ChannelHelper.GetChannelName(ArticleHelper.GetArticle(id).OwnerID));
 }