Пример #1
0
        /// <summary>
        /// 异步推送消息
        /// </summary>
        /// <param name="subscribeType"></param>
        /// <param name="value"></param>
        public static Task <long> PublishAsync(SubscribeType subscribeType, string value)
        {
            ISubscriber Sub        = RedisMananger.GetSubscriber();
            string      channelKey = GetChannelKey(subscribeType);

            return(Sub.PublishAsync(channelKey, value));
        }
Пример #2
0
        public MqttResponse GetValueFromPayload(string payload, SubscribeType subscribeType)
        {
            try
            {
                var body = (Body)JsonSerializer.Deserialize(payload, typeof(Body));

                if (subscribeType == SubscribeType.State)
                {
                    return(new MqttResponse()
                    {
                        State = body.state
                    });
                }
                else if (subscribeType == SubscribeType.Linkquality)
                {
                    return(new MqttResponse()
                    {
                        Linkquality = body.linkquality
                    });
                }
                else
                {
                    throw new Exception("Not known subscribeType for this payload.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception inside {GetType()} : { e.Message }");
                return(new MqttResponse());
            }
        }
Пример #3
0
        /// <summary>
        /// 发布订阅
        /// </summary>
        /// <param name="subscribeType"></param>
        /// <param name="callBack"></param>
        public static void SubscribeAsync(SubscribeType subscribeType, Action <RedisChannel, RedisValue> callBack)
        {
            ISubscriber Sub        = RedisMananger.GetSubscriber();
            string      channelKey = GetChannelKey(subscribeType);

            Sub.SubscribeAsync(channelKey, callBack);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the KubeMQ.SDK.csharp.Subscription.SubscribeRequest using a set of parameters.
 /// </summary>
 /// <param name="subscriptionType">Represents the type of Subscriber operation KubeMQ.SDK.csharp.Subscription.SubscribeType.</param>
 /// <param name="clientID">Represents an identifier that will subscribe to kubeMQ under.</param>
 /// <param name="channel">Represents the channel name that will subscribe to under kubeMQ.</param>
 /// <param name="group">Represents the group the channel is assign to , if not filled will be empty string(no group).</param>
 /// <param name="eventsStoreType"> Represents the type of subscription to persistence using KubeMQ.SDK.csharp.Subscription.EventsStoreType.</param>
 /// <param name="eventsStoreTypeValue">Represents the value of subscription to persistence queue.</param>
 public SubscribeRequest(SubscribeType subscriptionType, string clientID, string channel, EventsStoreType eventsStoreType, long eventsStoreTypeValue, string group = "")
 {
     SubscribeType        = subscriptionType;
     ClientID             = clientID;
     Channel              = channel;
     Group                = group;
     EventsStoreType      = eventsStoreType;
     EventsStoreTypeValue = eventsStoreTypeValue;
 }
Пример #5
0
 public PagedList<Subscriber> GetMembers(Guid mailingListID, int segmentID, SubscribeType status = SubscribeType.Subscribed, int page = 1, int pageSize = 500)
 {
     return _Manager.MakeRequest<SerializableMailingListMemberCollection>(HttpMethod.GET, String.Format("/lists/{0}/segments/{1}/members", mailingListID, segmentID), new
     {
         Status = status,
         Page = page,
         PageSize = pageSize
     }).PagedList;
 }
Пример #6
0
        public static void SendMessage(SubscribeType sType, int id,
                                       Message msg, bool waitingForSubscriber = false)
        {
            if (sType != SubscribeType.Broadcast && !msg.GeneratedChannelMsgType)
            {
                msg.Type = Channel.GetFullSubscribeType(sType, id, msg.Type);
                msg.GeneratedChannelMsgType = true;
            }

            msg.WaitingForSubscriber = waitingForSubscriber;
            MessageBus.Instance._queue.Push(msg);
        }
Пример #7
0
        public void Unsubscribe(SubscribeType sType, string type, object go, MethodInfo methodInfo)
        {
            var channelIds = (go as MonoBehaviour).GetComponent <Channel>().ChannelIds;

            if (channelIds.ContainsKey(sType) && sType != SubscribeType.Broadcast)
            {
                _Unsubscribe(Channel.GetFullSubscribeType(sType, channelIds[sType], type), go, methodInfo);
            }
            else
            {
                _Unsubscribe(type, go, methodInfo);
            }
        }
Пример #8
0
        public void Unsubscribe(SubscribeType sType, string type, object go, MethodInfo methodInfo)
        {
            var channelIds = (go as MonoBehaviour).GetComponent <Channel>().ChannelIds;

            if (channelIds.ContainsKey(sType) && sType != SubscribeType.Broadcast)
            {
                _Unsubscribe(sType.ToString("d") + channelIds[sType] + "_" + type, go, methodInfo);
            }
            else if (sType == SubscribeType.Broadcast)
            {
                _Unsubscribe(type, go, methodInfo);
            }
        }
        public PagedList<Subscriber> GetSubscribers(Guid mailingListID, SubscribeType status, DateTime? since = null, int page = 1, int pageSize = 500)
        {
            var result = _Manager.MakeRequest<SerializableMailingListMemberCollection>(HttpMethod.GET, String.Format("/lists/{0}/subscribers/{1}", mailingListID, status.ToString()), new
            {
                Since = since,
                Page = page,
                PageSize = pageSize
            }).PagedList;

            // populate custom fields with subscriber id, because it is not returned by the response
            result.ForEach(subscriber => subscriber.CustomFields.ToList().ForEach(cf => cf.SubscriberID = subscriber.ID));

            return result;
        }
Пример #10
0
        protected SubscribeRequest CreateSubscribeRequest(SubscribeType subscriptionType  = SubscribeType.SubscribeTypeUndefined,
                                                          EventsStoreType eventsStoreType = EventsStoreType.Undefined,
                                                          int TypeValue = 0, string group = "")
        {
            Random           random           = new Random();
            SubscribeRequest subscribeRequest = new SubscribeRequest()
            {
                Channel              = ChannelName,
                ClientID             = random.Next(9, 19999).ToString(),
                EventsStoreType      = eventsStoreType,
                EventsStoreTypeValue = TypeValue,
                Group         = group,
                SubscribeType = subscriptionType
            };

            return(subscribeRequest);
        }
Пример #11
0
 public Subscribe(params string[] args)
 {
     subscribed_types = args;
     Type             = SubscribeType.Broadcast;
 }
 /// <remarks/>
 public void SubscribeAsync(SubscribeType Subscribe1)
 {
     this.SubscribeAsync(Subscribe1, null);
 }
Пример #13
0
 public PagedList<Subscriber> GetMembers(Segment segment, SubscribeType status = SubscribeType.Subscribed, int page = 1, int pageSize = 500)
 {
     return GetMembers(segment.MailingListID, segment.ID, status, page, pageSize);
 }
Пример #14
0
 public static string GetFullSubscribeType(SubscribeType type, int id, string curType)
 {
     return(type.ToString("d") + id + "_" + curType);
 }
Пример #15
0
 public Subscribe(SubscribeType type, params byte[] args)
 {
     subscribed_types = args.Select(a => a.ToString()).ToArray();
     Type             = type;
 }
 /// <remarks/>
 public System.IAsyncResult BeginSubscribe(SubscribeType Subscribe1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("Subscribe", new object[] {
                 Subscribe1}, callback, asyncState);
 }
Пример #17
0
 /// <summary>
 /// 获取RedisKey
 /// </summary>
 /// <param name="Type"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 private static string GetChannelKey(SubscribeType Type)
 {
     return("Subscribe_" + Type.ToString());
 }
 /// <remarks/>
 public void SubscribeAsync(SubscribeType Subscribe1, object userState)
 {
     if ((this.SubscribeOperationCompleted == null))
     {
         this.SubscribeOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSubscribeOperationCompleted);
     }
     this.InvokeAsync("Subscribe", new object[] {
                 Subscribe1}, this.SubscribeOperationCompleted, userState);
 }
Пример #19
0
 public Subscribe(SubscribeType type, params string[] args)
 {
     subscribed_types = args;
     Type             = type;
 }