// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string serviceBusHost = Configuration.GetSection("MessageBroker").GetValue <string>("ServiceBusHost"); services.AddMassTransit(x => { x.SetKebabCaseEndpointNameFormatter(); x.UsingAzureServiceBus((context, config) => { config.Host(serviceBusHost); config.ConfigureEndpoints(context); }); x.AddRequestClient <IGetDeliveriesEvent>(RequestTimeout.After(0, 1, 0, 0, 0)); }); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "FoodPal.Delivery.API", Version = "v1" }); }); }
static void Main() { var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.Host("rabbitmq://localhost", hostConfigurator => { hostConfigurator.Username("admin"); hostConfigurator.Password("admin"); }); cfg.OverrideDefaultBusEndpointQueueName("OrderRegistration-PublisherExchange"); }); bus.Start(); var orderRegisteredMessage = new OrderRegistered { OrderId = 1, OrderDate = DateTime.Now, CustomerNumber = DateTime.Now.Millisecond.ToString(), }; var requestClient = bus.CreateRequestClient <OrderRegistered>(RequestTimeout.After(s: 5)); var response = requestClient.GetResponse <OrderAccepted, OrderRejected>(orderRegisteredMessage).Result; //DO Some thing with response. Console.ReadKey(); bus.Stop(); }
public async Task Should_complete() { var orderId = NewId.NextGuid(); var orderLineId = NewId.NextGuid(); var startedAt = DateTime.UtcNow; var scope = Provider.CreateScope(); var client = scope.ServiceProvider.GetRequiredService <IRequestClient <OrderCombo> >(); Response <ComboCompleted> response = await client.GetResponse <ComboCompleted>(new { OrderId = orderId, OrderLineId = orderLineId, Number = 5 }, timeout : RequestTimeout.After(s: 5)); Assert.That(response.Message.OrderId, Is.EqualTo(orderId)); Assert.That(response.Message.OrderLineId, Is.EqualTo(orderLineId)); Assert.That(response.Message.Created, Is.GreaterThan(startedAt)); Assert.That(response.Message.Completed, Is.GreaterThan(response.Message.Created)); Assert.That(response.Message.Description, Contains.Substring("Fries")); Assert.That(response.Message.Description, Contains.Substring("Shake")); }
public async Task Should_accept_that_faults_happen() { var client = Bus.CreateRequestClient <CreateShortLink>(RequestTimeout.After(s: 30)); Assert.That(async() => await client.GetResponse <ShortLinkCreated>(new { Link = new Uri("http://www.google.com") }), Throws.TypeOf <RequestFaultException>()); }
public async Task Setup() { _clientFactory = await Host.CreateClientFactory(RequestTimeout.After(s: 8)); _requestClient = await Host.CreateRequestClient <PingMessage>(InputQueueAddress, RequestTimeout.After(s: 8)); _response = _requestClient.GetResponse <PongMessage>(new PingMessage()); }
public async Task Should_complete_the_request() { var client = Bus.CreateRequestClient <CreateShortLink>(RequestTimeout.After(s: 30)); var response = await client.GetResponse <ShortLinkCreated>(new { Link = new Uri("http://www.microsoft.com") }); Console.WriteLine("Link: {0}, Short Link: {1}", response.Message.Link, response.Message.ShortLink); }
public async Task Should_throw_a_timeout_exception() { var client = Bus.CreateRequestClient <GetValue>(InputQueueAddress, RequestTimeout.After(s: 1)); Assert.That(async() => await client.GetResponse <Value>(new GetValue { Discard = true }), Throws.TypeOf <RequestTimeoutException>()); }
public async Task Should_default_timeout_if_a_service_is_not_found() { var serviceClient = Bus.CreateServiceClient(RequestTimeout.After(s: 2)); var requestClient = serviceClient.CreateRequestClient <DeployHappiness>(); Stopwatch timer = Stopwatch.StartNew(); Assert.That(async() => await requestClient.GetResponse <PayloadDeployed>(new { Target = "Sunshine and Rainbows" }), Throws.TypeOf <RequestTimeoutException>()); Assert.That(timer.Elapsed, Is.LessThan(TimeSpan.FromSeconds(5))); }
public async Task Should_faulted() { var orderLineId = NewId.NextGuid(); var scope = Provider.CreateScope(); var client = scope.ServiceProvider.GetRequiredService <IRequestClient <CalculatePrice> >(); var exception = Assert.ThrowsAsync <RequestFaultException>(async() => await client.GetResponse <PriceCalculation>(new { OrderLineId = orderLineId, Sku = "missing" }, timeout: RequestTimeout.After(s: 5))); Assert.That(exception.Fault.Exceptions.Any(x => x.ExceptionType == TypeCache <IntentionalTestException> .ShortName)); }
public async Task Should_complete() { var orderLineId = NewId.NextGuid(); var scope = Provider.CreateScope(); var client = scope.ServiceProvider.GetRequiredService <IRequestClient <CalculatePrice> >(); Response <PriceCalculation> response = await client.GetResponse <PriceCalculation>(new { OrderLineId = orderLineId, Sku = "90210" }, timeout : RequestTimeout.After(s: 5)); Assert.That(response.Message.OrderLineId, Is.EqualTo(orderLineId)); }
public async Task Should_not_receive_the_response() { Task <ConsumeContext <PongMessage> > responseHandler = SubscribeHandler <PongMessage>(); Assert.That(async() => { var response = await Bus.Request <PingMessage, PongMessage>(InputQueueAddress, new PingMessage(), TestCancellationToken, RequestTimeout.After(s: 3)); }, Throws.TypeOf <RequestFaultException>()); await _pingReceived.Task; Console.WriteLine("Ping was received"); Assert.That( async() => await responseHandler.OrCanceled(new CancellationTokenSource(300).Token), Throws.TypeOf <OperationCanceledException>()); }
public async Task Should_complete() { var orderId = NewId.NextGuid(); var fryId = NewId.NextGuid(); var burgerId = NewId.NextGuid(); using var scope = Provider.CreateScope(); var client = scope.ServiceProvider.GetRequiredService <IRequestClient <SubmitOrder> >(); Response <OrderCompleted, OrderFaulted> response = await client.GetResponse <OrderCompleted, OrderFaulted>(new { OrderId = orderId, Fries = new[] { new { FryId = fryId, Size = Size.Large } }, Burgers = new[] { new Burger { BurgerId = burgerId, Weight = 1.0m, Cheese = true, OnionRing = true, BarbecueSauce = true } }, Shakes = default(Shake[]), FryShakes = default(FryShake[]) }, timeout : RequestTimeout.After(s: 5)); Assert.That(response.Is(out Response <OrderCompleted> completed), "Order did not complete"); Assert.That(completed.Message.OrderId, Is.EqualTo(orderId)); Assert.That(completed.Message.LinesCompleted.Count, Is.EqualTo(2)); }
public void Setup() { _requestClient = Bus.CreateRequestClient <PingMessage>(new Uri("exchange:input_queue"), RequestTimeout.After(s: 8)); _response = _requestClient.GetResponse <PongMessage>(new PingMessage()); }
public async Task Setup() { _request = Bus.Request <PingMessage, PongMessage>(new PingMessage(), TestCancellationToken, RequestTimeout.After(s: 1)); }
public async Task Should_load_the_data_from_the_repository() { IRequestClient <ProcessPayload> client = CreateRequestClient <ProcessPayload>(); var payload = new SpecialPayload { Value = "Something special" }; var streamBytes = new byte[1000]; await using var ms = new MemoryStream(streamBytes); Response <PayloadProcessed> response = await client.GetResponse <PayloadProcessed>(new { Payload = payload }, TestCancellationToken, RequestTimeout.After(s: 5)); Assert.That(response.Message.Payload, Is.Not.Null); Assert.That(response.Message.Payload.HasValue, Is.True); Assert.That(response.Message.Payload.Address, Is.EqualTo(_payloadAddress), "Should use the existing message data address"); var responsePayload = await response.Message.Payload.Value; Assert.That(responsePayload.Value, Is.EqualTo(payload.Value)); }
public async Task <TResponse> Request <TRequest, TResponse>(TRequest message, string endpoint) where TRequest : class where TResponse : class { var reqTimeout = RequestTimeout.After(0, 0, 0, _options.SendMessageTimeout); var response = await _busControl.Request <TRequest, TResponse>(BuildUri(endpoint), message, default, reqTimeout);
public void Setup() { _requestClient = Bus.CreateRequestClient <PingMessage>(InputQueueAddress, RequestTimeout.After(s: 8)); _response = _requestClient.GetResponse <PongMessage>(new PingMessage()); }
public static Task <Response <T> > GetResponseExt <TRequest, T>(this IRequestClient <TRequest> client, TRequest message, int msTimeout = 3000) where T : class where TRequest : class { return(client.GetResponse <T>(message, timeout: RequestTimeout.After(0, 0, 0, 0, msTimeout))); }