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");
        }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 5
0
 public Task Send <T>(IBehaviorContext context, Action <T> messageConstructor, SendOptions options)
 {
     return(SendMessage(context, typeof(T), messageMapper.CreateInstance(messageConstructor), options));
 }
Esempio n. 6
0
        public Task Send(IBehaviorContext context, object message, SendOptions options)
        {
            var messageType = messageMapper.GetMappedTypeFor(message.GetType());

            return(SendMessage(context, messageType, message, options));
        }
 public Task Send <T>(Action <T> messageConstructor, SendOptions options)
 {
     return(messageSession.Send(messageConstructor, options));
 }
 public Task Send(object message, SendOptions options)
 {
     return(messageSession.Send(message, options));
 }
Esempio n. 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));
        }
Esempio n. 10
0
 public static void SetCorrelationId(this SendOptions options, string correlationId)
 {
     throw new NotImplementedException();
 }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 16
0
 public static string GetCorrelationId(this SendOptions options)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
 public static Task Send(IBehaviorContext context, object message, SendOptions options)
 {
     return(SendMessage(context, message.GetType(), message, options));
 }