/// <summary> /// Instantiates a message of type T and sends it to the given destination. /// </summary> /// <typeparam name="T">The type of message, usually an interface.</typeparam> /// <param name="session">The instance of <see cref="IMessageSession" /> to use for the action.</param> /// <param name="destination">The destination to which the message will be sent.</param> /// <param name="messageConstructor">An action which initializes properties of the message.</param> public static Task Send <T>(this IMessageSession session, string destination, Action <T> messageConstructor) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNullAndEmpty(nameof(destination), destination); Guard.AgainstNull(nameof(messageConstructor), messageConstructor); var options = new SendOptions(); options.SetDestination(destination); return(session.Send(messageConstructor, options)); }
/// <summary> /// Sends the message. /// </summary> /// <param name="session">The instance of <see cref="IMessageSession" /> to use for the action.</param> /// <param name="destination">The address of the destination to which the message will be sent.</param> /// <param name="message">The message to send.</param> public static Task Send(this IMessageSession session, string destination, object message) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNullAndEmpty(nameof(destination), destination); Guard.AgainstNull(nameof(message), message); var options = new SendOptions(); options.SetDestination(destination); return(session.Send(message, options)); }
/// <summary> /// Instantiates a message of type T and sends it to the given destination. /// </summary> /// <typeparam name="T">The type of message, usually an interface.</typeparam> /// <param name="context">The instance of <see cref="IPipelineContext" /> to use for the action.</param> /// <param name="destination">The destination to which the message will be sent.</param> /// <param name="messageConstructor">An action which initializes properties of the message.</param> public static Task Send <T>(this IPipelineContext context, string destination, Action <T> messageConstructor) { Guard.AgainstNull(nameof(context), context); Guard.AgainstNullAndEmpty(nameof(destination), destination); Guard.AgainstNull(nameof(messageConstructor), messageConstructor); var options = new SendOptions(); options.SetDestination(destination); return(context.Send(messageConstructor, options)); }
/// <summary> /// Sends the message. /// </summary> /// <param name="context">The instance of <see cref="IPipelineContext" /> to use for the action.</param> /// <param name="destination">The address of the destination to which the message will be sent.</param> /// <param name="message">The message to send.</param> public static Task Send(this IPipelineContext context, string destination, object message) { Guard.AgainstNull(nameof(context), context); Guard.AgainstNullAndEmpty(nameof(destination), destination); Guard.AgainstNull(nameof(message), message); var options = new SendOptions(); options.SetDestination(destination); return context.Send(message, 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"); }