public static async Task InvokeRest(this IMessageHandlerContext context, string urlTemplate, HttpContent requestBody, object followUpMessage) { var client = context.Extensions.Get <HttpClient>(); var uniqueId = Guid.NewGuid().ToString(); var url = urlTemplate.Replace("{uniqueId}", uniqueId); var transactionContext = context.Extensions.Get <ITransactionContext>(); await transactionContext.AddSideEffect(new HttpRequestRecord { AttemptId = transactionContext.AttemptId, Id = uniqueId, Url = url }).ConfigureAwait(false); var putResponse = await client.PutAsync(url, requestBody).ConfigureAwait(false); if (!putResponse.IsSuccessStatusCode) { throw new Exception($"Error while issuing PUT against URL {url}: {putResponse.StatusCode} {putResponse.ReasonPhrase}"); } var sendOptions = new SendOptions(); sendOptions.SetHeader("ExactlyOnce.HttpRequestUrl", url); await context.Send(followUpMessage, sendOptions).ConfigureAwait(false); }
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(); }
/// <summary> /// Route the message through the Gateway to the specified sites. /// </summary> public static void RouteToSites(this SendOptions options, params string[] siteKeys) { options.SetHeader(Headers.DestinationSites, string.Join(",", siteKeys)); options.GetExtensions().Set(new RouteThroughGateway()); options.RouteToThisEndpoint(); }
/// <summary> /// Uses the non-persistent delivery mode to send the message. /// </summary> public static void UseNonPersistentDeliveryMode(this SendOptions options) { Guard.AgainstNull(nameof(options), options); options.SetHeader(BasicPropertiesExtensions.UseNonPersistentDeliveryHeader, bool.TrueString); }