コード例 #1
0
        public bool DeduplicateMessage(string clientId, DateTime timeReceived)
        {
            try
            {
                using (var redisClient = RedisClientsManager.GetClient())
                {
                    var gatewayMessage = redisClient.As <GatewayMessage>().GetValue(EndpointName + clientId);

                    if (gatewayMessage != null)
                    {
                        Logger.InfoFormat("DeduplicatedMessage found gatewayMessage {0}", gatewayMessage.Id);
                        return(false);
                    }

                    gatewayMessage = new GatewayMessage
                    {
                        Id           = clientId.EscapeClientId(),
                        TimeReceived = timeReceived
                    };

                    redisClient.As <GatewayMessage>().SetValue(EndpointName + gatewayMessage.Id, gatewayMessage, TimeSpan.FromMinutes(DefaultEntityTtl));
                    Logger.InfoFormat("DeduplicatedMessage added gatewayMessage {0} with ttl {1}", gatewayMessage.Id, DefaultEntityTtl);
                }
                return(true);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("ERROR DeduplicateMessage {0}", clientId), e);
                throw;
            }
        }
コード例 #2
0
        public bool InsertMessage(string clientId, DateTime timeReceived, Stream messageStream, IDictionary <string, string> headers)
        {
            try
            {
                var gatewayMessage = new GatewayMessage
                {
                    Id              = clientId.EscapeClientId(),
                    TimeReceived    = timeReceived,
                    Headers         = headers,
                    OriginalMessage = new byte[messageStream.Length],
                    Acknowledged    = false
                };

                messageStream.Read(gatewayMessage.OriginalMessage, 0, (int)messageStream.Length);
                using (var redisClient = RedisClientsManager.GetClient())
                {
                    redisClient.As <GatewayMessage>().SetValue(EndpointName + gatewayMessage.Id, gatewayMessage, TimeSpan.FromMinutes(DefaultEntityTtl));
                    Logger.InfoFormat("Added gatewayMessage {0} with ttl {1}", gatewayMessage.Id, DefaultEntityTtl);
                }
                return(true);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("ERROR InsertMessage {0}", clientId), e);
                throw;
            }
        }