Ejemplo n.º 1
0
        public async Task <bool> SubscribeAsync(string message)
        {
            //validate message
            Message msg = JsonConvert.DeserializeObject <Message>(message);

            if (!msg.IsValidate || msg.SubscriberId.IsNullOrEmpty() || msg.TargetId.IsNullOrEmpty())
            {
                _logger.Error(AlterKeys.Error.MESSAGE_INVALID, new string[] { msg.Id });
                return(false);
            }

            var topicObj = await _topicService.GetTopicAsync(msg.Topic, msg.ServiceId);

            if (topicObj.IsNull())
            {
                return(false);
            }

            msg.Id          = Guid.NewGuid().ToString();
            msg.TopicId     = topicObj.Id;
            msg.TypeId      = StaticKeys.MessageTypeId_Subscribe;
            msg.ReceiveTime = DateTime.UtcNow;
            if (!MessageDb.Insert(msg))
            {
                return(false);
            }

            // handle message logic
            var subscribe = new Subscribe(Guid.NewGuid().ToString(), msg.ServiceId, msg.TopicId, msg.SubscriberId, msg.TargetId);

            return(await _subscribeService.SubscribeAsync(subscribe));
        }
Ejemplo n.º 2
0
        public async Task <bool> AnnounceAsync(Message message)
        {
            if (!message.IsValidate)
            {
                return(false);
            }

            var topicObj = await _topicService.GetTopicAsync(message.TopicId);

            if (topicObj.IsNull())
            {
                return(false);
            }

            message.Id          = Guid.NewGuid().ToString();
            message.TopicId     = topicObj.Id;
            message.TypeId      = StaticKeys.MessageTypeId_Announce;
            message.SendTime    = DateTime.UtcNow;
            message.ReceiveTime = DateTime.UtcNow;

            return(MessageDb.Insert(message));
        }
Ejemplo n.º 3
0
        public async Task <bool> NotifyAsync(string message)
        {
            Message msg = JsonConvert.DeserializeObject <Message>(message);

            if (!msg.IsValidate)
            {
                return(false);
            }

            var topicObj = await _topicService.GetTopicAsync(msg.TopicId);

            if (topicObj.IsNull())
            {
                return(false);
            }

            msg.Id      = msg.Id ?? Guid.NewGuid().ToString();
            msg.TopicId = topicObj.Id;
            msg.TypeId  = StaticKeys.MessageTypeId_Notify;
            //msg.ReceiveTime = DateTime.UtcNow;

            return(MessageDb.Insert(msg));
        }