Пример #1
0
        /// <summary>
        /// Request for a timeout to occur at the given <see cref="DateTime" />.
        /// </summary>
        /// <param name="context">The context which is used to send the timeout.</param>
        /// <param name="at"><see cref="DateTime" /> to send timeout <paramref name="timeoutMessage" />.</param>
        /// <param name="timeoutMessage">The message to send after <paramref name="at" /> is reached.</param>
        protected Task RequestTimeout <TTimeoutMessageType>(IMessageHandlerContext context, DateTime at, TTimeoutMessageType timeoutMessage)
        {
            if (at.Kind == DateTimeKind.Unspecified)
            {
                throw new InvalidOperationException("Kind property of DateTime 'at' must be specified.");
            }

            VerifySagaCanHandleTimeout(timeoutMessage);

            var options = new SendOptions();

            options.DoNotDeliverBefore(at);
            options.RouteToThisEndpoint();

            SetTimeoutHeaders(options);

            return(context.Send(timeoutMessage, options));
        }
        private async Task SendMessages(int batchSize, DateTimeOffset visibleTime, string endpointName = null)
        {
            var stopwatch = Stopwatch.StartNew();
            var options   = new NServiceBus.SendOptions();

            Console.WriteLine($"Messages visible at {visibleTime:G}");
            options.DoNotDeliverBefore(visibleTime);
            if (!string.IsNullOrEmpty(endpointName))
            {
                options.SetDestination(endpointName);
            }
            var messages = CreateMessages(batchSize);

            foreach (var message in messages)
            {
                await endpointInstance.Send(message, options).ConfigureAwait(false);
            }
            Console.WriteLine($"Sent {batchSize} messages at {DateTime.Now:G}.  Took: {stopwatch.ElapsedMilliseconds}ms");
        }