public async Task <IDeduplicationSession> CheckForDuplicate(string messageId, ContextBag context)
        {
            var session     = documentStore.OpenAsyncSession();
            var isDuplicate = await session.LoadAsync <GatewayMessage>(MessageIdHelper.EscapeMessageId(messageId)).ConfigureAwait(false) != null;

            return(new RavenDeduplicationSession(session, isDuplicate, messageId, deduplicationDataTimeToLive));
        }
Esempio n. 2
0
        public async Task MarkAsDispatched()
        {
            if (!IsDuplicate)
            {
                var timeReceived = DateTime.UtcNow;
                var expiry       = timeReceived + deduplicationDataTimeToLive;

                var gatewayMessage = new GatewayMessage()
                {
                    Id           = MessageIdHelper.EscapeMessageId(messageId),
                    TimeReceived = timeReceived
                };

                await session.StoreAsync(gatewayMessage).ConfigureAwait(false);

                session.Advanced.GetMetadataFor(gatewayMessage)[Constants.Documents.Metadata.Expires] = expiry;
                await session.SaveChangesAsync().ConfigureAwait(false);
            }
        }