コード例 #1
0
        public static async Task DomainCommand(this IMessageSession ctx, ICommand command)
        {
            var options = new NServiceBus.SendOptions();

            options.RouteToThisEndpoint();
            options.SetHeader(Aggregates.Defaults.RequestResponse, "1");

            var response = await ctx.Request <IMessage>(command, options).ConfigureAwait(false);

            response.CommandResponse();
        }
        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");
        }
コード例 #3
0
 /// <summary>
 /// Returns the delivery date configured by using <see cref="DoNotDeliverBefore" />.
 /// </summary>
 /// <param name="options">The options being extended.</param>
 /// <returns>The configured <see cref="DateTimeOffset" /> or <c>null</c>.</returns>
 public static DateTimeOffset?GetDeliveryDate(this SendOptions options)
 {
     Guard.AgainstNull(nameof(options), options);
     options.GetExtensions().TryGetDeliveryConstraint(out DoNotDeliverBefore deliveryDate);
     return(deliveryDate?.At);
 }
コード例 #4
0
 /// <summary>
 /// Returns the configured delivery delay by using <see cref="DelayDeliveryWith" />.
 /// </summary>
 /// <param name="options">The options being extended.</param>
 /// <returns>The configured <see cref="TimeSpan" /> or <c>null</c>.</returns>
 public static TimeSpan?GetDeliveryDelay(this SendOptions options)
 {
     Guard.AgainstNull(nameof(options), options);
     options.GetExtensions().TryGetDeliveryConstraint(out DelayDeliveryWith delay);
     return(delay?.Delay);
 }
コード例 #5
0
 public Task Send <T>(IBehaviorContext context, Action <T> messageConstructor, SendOptions options)
 {
     return(SendMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options));
 }
コード例 #6
0
        public Task Send(IBehaviorContext context, object message, SendOptions options)
        {
            var messageType = messageMapper.GetMappedTypeFor(message.GetType());

            return(SendMessage(context, messageType, message, options));
        }
コード例 #7
0
 public Task Send <T>(Action <T> messageConstructor, SendOptions options)
 {
     return(messageSession.Send(messageConstructor, options));
 }
コード例 #8
0
 public Task Send(object message, SendOptions options)
 {
     return(messageSession.Send(message, options));
 }
コード例 #9
0
        static Task SendMessage(this IBehaviorContext context, Type messageType, object message, SendOptions options)
        {
            var cache    = context.Extensions.Get <IPipelineCache>();
            var pipeline = cache.Pipeline <IOutgoingSendContext>();

            var outgoingContext = new OutgoingSendContext(
                new OutgoingLogicalMessage(messageType, message),
                options,
                context);

            return(pipeline.Invoke(outgoingContext));
        }
コード例 #10
0
ファイル: obsoletes.cs プロジェクト: pangfd/NServiceBus
 public static void SetCorrelationId(this SendOptions options, string correlationId)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
        /// <inheritdoc />
        public async Task Send <T>(Action <T> messageConstructor, SendOptions options, ExecutionContext executionContext, ILogger functionsLogger = null)
        {
            await InitializeEndpointUsedOutsideHandlerIfNecessary(executionContext, functionsLogger).ConfigureAwait(false);

            await endpoint.Send(messageConstructor, options).ConfigureAwait(false);
        }
コード例 #12
0
        static Task SendMessage(this IBehaviorContext context, Type messageType, object message, SendOptions options)
        {
            var cache    = context.Extensions.Get <IPipelineCache>();
            var pipeline = cache.Pipeline <IOutgoingSendContext>();

            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var outgoingContext = new OutgoingSendContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            if (options.DelayedDeliveryConstraint != null)
            {
                // we can't add the constraints directly to the SendOptions ContextBag as the options can be reused
                // and the delivery constraints might be removed by the TimeoutManager logic.
                outgoingContext.AddDeliveryConstraint(options.DelayedDeliveryConstraint);
            }

            return(pipeline.Invoke(outgoingContext));
        }
コード例 #13
0
        public static Task Send <T>(IBehaviorContext context, Action <T> messageConstructor, SendOptions options)
        {
            var mapper = context.Extensions.Get <IMessageMapper>();

            return(SendMessage(context, typeof(T), mapper.CreateInstance(messageConstructor), options));
        }
コード例 #14
0
        /// <summary>
        /// Returns the delivery date configured by using <see cref="DoNotDeliverBefore" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="DateTimeOffset" /> or <c>null</c>.</returns>
        public static DateTimeOffset?GetDeliveryDate(this SendOptions options)
        {
            Guard.AgainstNull(nameof(options), options);

            return((options.DelayedDeliveryConstraint as DoNotDeliverBefore)?.At);
        }
コード例 #15
0
        /// <summary>
        /// Returns the configured delivery delay by using <see cref="DelayDeliveryWith" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="TimeSpan" /> or <c>null</c>.</returns>
        public static TimeSpan?GetDeliveryDelay(this SendOptions options)
        {
            Guard.AgainstNull(nameof(options), options);

            return((options.DelayedDeliveryConstraint as DelayDeliveryWith)?.Delay);
        }
コード例 #16
0
ファイル: obsoletes.cs プロジェクト: pangfd/NServiceBus
 public static string GetCorrelationId(this SendOptions options)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public static Task Send(IBehaviorContext context, object message, SendOptions options)
 {
     return(SendMessage(context, message.GetType(), message, options));
 }