コード例 #1
0
        public async Task IsCapableOfReturningTheMessageBodyAsWell()
        {
            var someTimeInThePast = DateTime.Now.AddMinutes(-1);

            const string stringBody = "hello there!";

            await _timeoutManager.Defer(someTimeInThePast, HeadersWith("i know u"), Encoding.UTF8.GetBytes(stringBody));

            using (var result = await _timeoutManager.GetDueMessages())
            {
                var dueTimeouts = result.ToList();

                Assert.That(dueTimeouts.Count, Is.EqualTo(1));

                var bodyBytes = dueTimeouts[0].Body;

                Assert.That(Encoding.UTF8.GetString(bodyBytes), Is.EqualTo(stringBody));
            }
        }
コード例 #2
0
        async Task StoreMessageUntilDue(string deferredUntil, Dictionary <string, string> headers, TransportMessage transportMessage)
        {
            var approximateDueTime = GetTimeToBeDelivered(deferredUntil);

            _log.Info("Deferring message {0} until {1}", headers[Headers.MessageId], approximateDueTime);

            headers.Remove(Headers.DeferredUntil);

            await _timeoutManager.Defer(approximateDueTime, headers, transportMessage.Body);
        }
コード例 #3
0
        async Task StoreMessageUntilDue(string deferredUntil, Dictionary <string, string> headers, TransportMessage transportMessage)
        {
            var approximateDueTime = GetTimeToBeDelivered(deferredUntil);

            _log.Debug("Deferring message {messageLabel} until {dueTime}", transportMessage.GetMessageLabel(), approximateDueTime);

            headers.Remove(Headers.DeferredUntil);

            await _timeoutManager.Defer(approximateDueTime, headers, transportMessage.Body);
        }
コード例 #4
0
        public async Task Process(IncomingStepContext context, Func <Task> next)
        {
            var transportMessage = context.Load <TransportMessage>();

            string deferredUntil;

            var headers = transportMessage.Headers;

            if (!headers.TryGetValue(Headers.DeferredUntil, out deferredUntil))
            {
                await next();

                return;
            }

            if (!headers.ContainsKey(Headers.ReturnAddress))
            {
                throw new ApplicationException(string.Format("Received message {0} with the '{1}' header set to '{2}', but the message had no '{3}' header!",
                                                             headers[Headers.MessageId],
                                                             Headers.DeferredUntil,
                                                             headers[Headers.DeferredUntil],
                                                             Headers.ReturnAddress));
            }

            DateTimeOffset approximateDueTime;

            if (!DateTimeOffset.TryParseExact(deferredUntil, DateTimeOffsetFormat, CultureInfo.InvariantCulture,
                                              DateTimeStyles.RoundtripKind, out approximateDueTime))
            {
                throw new FormatException(string.Format("Could not parse the '{0}' header value '{1}' into a valid DateTimeOffset!",
                                                        Headers.DeferredUntil, deferredUntil));
            }

            _log.Info("Deferring message {0} until {1}", headers[Headers.MessageId], approximateDueTime);

            headers.Remove(Headers.DeferredUntil);

            await _timeoutManager.Defer(approximateDueTime, headers, transportMessage.Body);
        }