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
 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
 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));
 }