private async Task getReady() { theSender = await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.AddSingleton(theTracker); }); var receiver = new JasperRegistry(); receiver.Handlers.DisableConventionalDiscovery(); receiver.Transports.ListenForMessagesFrom(theAddress); receiver.Handlers.OnException <DivideByZeroException>().Requeue(); receiver.Handlers.OnException <TimeoutException>().RetryLater(10.Seconds()); receiver.Handlers.DefaultMaximumAttempts = 3; receiver.Handlers.IncludeType <MessageConsumer>(); scheduledJobs = new FakeScheduledJobProcessor(); receiver.Services.For <IScheduledJobProcessor>().Use(scheduledJobs); receiver.Services.For <MessageTracker>().Use(theTracker); theReceiver = await JasperRuntime.ForAsync(receiver); }
public async Task send_message_to_and_receive_through_rabbitmq() { var runtime = await JasperRuntime.ForAsync <RabbitMqUsingApp>(); try { var tracker = runtime.Get <MessageTracker>(); var watch = tracker.WaitFor <ColorChosen>(); await runtime.Messaging.Send(new ColorChosen { Name = "Red" }); await watch; var colors = runtime.Get <ColorHistory>(); colors.Name.ShouldBe("Red"); // TODO -- let's look at the envelope too } finally { await runtime.Shutdown(); } }
public async Task WithApp() { if (_runtime == null) { _runtime = await JasperRuntime.ForAsync <T>(); } }
public async Task can_alter_and_registry_still_gets_defaults() { var app = new MyApp(); app.Configuration.AddJsonFile("appsettings.json") .AddJsonFile("colors.json"); app.Settings.Require <Colors>(); app.Settings.Alter <MyFakeSettings>(_ => { _.SomeSetting = 29; }); var runtime = await JasperRuntime.ForAsync(app); try { var mySettings = runtime.Get <MyFakeSettings>(); var colors = runtime.Get <Colors>(); mySettings.SomeSetting.ShouldBe(29); colors.Red.ShouldBe("#ff0000"); } finally { await runtime.Shutdown(); } }
public async Task can_configure_builder() { theRegistry.Configuration .AddJsonFile("appsettings.json") .AddJsonFile("colors.json"); theRegistry.Settings.Require <Colors>(); theRegistry.Settings.Require <MyFakeSettings>(); var runtime = await JasperRuntime.ForAsync(theRegistry); try { var colors = runtime.Get <Colors>(); var settings = runtime.Get <MyFakeSettings>(); colors.Red.ShouldBe("#ff0000"); settings.SomeSetting.ShouldBe(1); } finally { await runtime.Shutdown(); } }
public async Task history_can_still_do_the_watch() { var runtime = await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery().IncludeType <MessageThatFailsHandler>(); _.Include <MessageTrackingExtension>(); _.Publish.AllMessagesTo(TransportConstants.LoopbackUri); }); try { var history = runtime.Get <MessageHistory>(); await history.WatchAsync(() => runtime.Messaging.Send(new MessageThatFails())); var aggregate = Exception <AggregateException> .ShouldBeThrownBy(() => history.AssertNoExceptions()); aggregate .InnerExceptions.Single().ShouldBeOfType <DivideByZeroException>(); } finally { await runtime.Shutdown(); } }
public async Task ping_happy_path_with_http_protocol() { var sender = new BatchedSender("http://localhost:5005/messages".ToUri(), new HttpSenderProtocol(new MessagingSettings()), CancellationToken.None, TransportLogger.Empty()); var runtime = await JasperRuntime.ForAsync <JasperRegistry>(_ => { _.Transports.Http.EnableListening(true); _.Hosting.UseUrls("http://localhost:5005"); _.Hosting.UseKestrel(); _.Services.AddLogging(); _.Hosting.Configure(app => { app.UseJasper(); app.Run(c => c.Response.WriteAsync("Hello")); }); }); try { await sender.Ping(); } finally { await runtime.Shutdown(); } }
public async Task customize_with_fluent_interface_against_a_specific_type() { var runtime = await JasperRuntime.ForAsync(_ => { _.Publish.Message <MySpecialMessage>().Customize(e => e.Headers.Add("rule", "true")); }); try { var context = runtime.Get <IMessageContext>(); // Just to force the message context to pool up the envelope instead // of sending it out await context.EnlistInTransaction(new InMemoryEnvelopeTransaction()); var mySpecialMessage = new MySpecialMessage(); await context.Send("tcp://localhost:2001".ToUri(), mySpecialMessage); var outgoing = context.As <MessageContext>().Outstanding.Single(); outgoing.Headers["rule"].ShouldBe("true"); } finally { await runtime.Shutdown(); } }
public async Task can_read_from_configuration_by_default() { var runtime = await JasperRuntime.ForAsync(_ => { // There is subscription data in this file _.Configuration.AddJsonFile("subscriptions.json"); }); try { var config = runtime.Get <IConfiguration>(); var all = config.AsEnumerable(); var stuff = config[nameof(SubscriptionSettings)]; var repository = runtime.Get <ISubscriptionsRepository>(); var subscriptions = await repository.GetSubscriptions(); subscriptions.Select(x => x.MessageType) .ShouldHaveTheSameElementsAs( typeof(Message1).ToMessageAlias(), typeof(Message2).ToMessageAlias(), typeof(Message3).ToMessageAlias() ); } finally { await runtime.Shutdown(); } }
public async Task can_discard_an_envelope_if_expired() { var logger = Substitute.For <IMessageLogger>(); var runtime = await JasperRuntime.ForAsync(x => { x.Handlers.DisableConventionalDiscovery(); x.Services.AddSingleton(logger); }); try { var pipeline = runtime.Get <IHandlerPipeline>(); var envelope = ObjectMother.Envelope(); envelope.DeliverBy = DateTime.UtcNow.Subtract(1.Minutes()); envelope.Callback = Substitute.For <IMessageCallback>(); await pipeline.Invoke(envelope); // Log the discard logger.Received().DiscardedEnvelope(envelope); #pragma warning disable 4014 envelope.Callback.Received().MarkComplete(); #pragma warning restore 4014 } finally { await runtime.Shutdown(); } }
public async Task can_handle_an_http_request_through_Kestrel() { var theRuntime = await JasperRuntime.ForAsync <JasperServerApp>(); var options = theRuntime.Container.GetInstance <DbContextOptions <ApplicationDbContext> >(); theRuntime.Container.GetInstance <DbContextOptions <ApplicationDbContext> >("options").ShouldNotBeNull(); try { // has the message context registered ShouldBeNullExtensions.ShouldNotBeNull(theRuntime.Get <IMessageContext>()); // has the registrations from Jasper theRuntime.Get <IFoo>().ShouldBeOfType <Foo>(); using (var client = new HttpClient()) { var text = await client.GetStringAsync("http://localhost:5200"); text.ShouldContain("Hello from a hybrid Jasper application"); } } finally { await theRuntime.Shutdown(); } }
public async Task can_stop_and_start() { var runtime = await JasperRuntime.ForAsync <RabbitMqUsingApp>(); var root = runtime.Get <IMessagingRoot>(); root.ListeningStatus = ListeningStatus.TooBusy; root.ListeningStatus = ListeningStatus.Accepting; try { var tracker = runtime.Get <MessageTracker>(); var watch = tracker.WaitFor <ColorChosen>(); await runtime.Messaging.Send(new ColorChosen { Name = "Red" }); await watch; var colors = runtime.Get <ColorHistory>(); colors.Name.ShouldBe("Red"); // TODO -- let's look at the envelope too } finally { await runtime.Shutdown(); } }
public async Task transport_endpoints_are_enabled_and_a_chain_should_be_present_with_overridden_urls() { var runtime = await JasperRuntime.ForAsync <JasperRegistry>(_ => { _.Handlers.DisableConventionalDiscovery(); _.Handlers.IncludeType <TransportEndpoint>(); _.Transports.Http.EnableListening(true).RelativeUrl("api"); }); try { var routes = runtime.Get <RouteGraph>(); routes.ChainForAction <TransportEndpoint>(nameof(TransportEndpoint.put__messages)) .Route.Pattern.ShouldBe("api"); routes.ChainForAction <TransportEndpoint>(nameof(TransportEndpoint.put__messages_durable)) .Route.Pattern.ShouldBe("api/durable"); } finally { await runtime.Shutdown(); } }
public async Task enqueue_locally_with_designated_worker_queue() { var registry = new JasperRegistry(); registry.Handlers.DisableConventionalDiscovery(false); registry.Services.Scan(x => { x.TheCallingAssembly(); x.WithDefaultConventions(); }); registry.Handlers.IncludeType <RecordCallHandler>(); registry.Services.ForSingletonOf <IFakeStore>().Use <FakeStore>(); registry.Handlers.Worker("foo").MaximumParallelization(3); var tracker = new MessageTracker(); registry.Services.AddSingleton(tracker); using (var runtime = await JasperRuntime.ForAsync(registry)) { var waiter = tracker.WaitFor <Message1>(); var message = new Message1 { Id = Guid.NewGuid() }; await runtime.Get <IMessageContext>().Enqueue(message, "foo"); var received = await waiter; received.Message.As <Message1>().Id.ShouldBe(message.Id); } }
public async Task enqueue_locally_lightweight() { var registry = new JasperRegistry(); registry.Handlers.IncludeType <RecordCallHandler>(); registry.Services.ForSingletonOf <IFakeStore>().Use <FakeStore>(); registry.Services.AddTransient <IMyService, MyService>(); registry.Services.AddTransient <IPongWriter, PongWriter>(); var tracker = new MessageTracker(); registry.Services.AddSingleton(tracker); using (var runtime = await JasperRuntime.ForAsync(registry)) { var waiter = tracker.WaitFor <Message1>(); var message = new Message1 { Id = Guid.NewGuid() }; await runtime.Get <IMessageContext>().EnqueueLightweight(message); waiter.Wait(5.Seconds()); var received = waiter.Result; received.Message.As <Message1>().Id.ShouldBe(message.Id); } }
private async Task withApp() { var registry = new ScheduledMessageApp(); theReceiver = registry.Receiver; theRuntime = await JasperRuntime.ForAsync(registry); }
private async Task withApp() { _runtime = await JasperRuntime.ForAsync <JasperRegistry>(_ => { _.Handlers.DisableConventionalDiscovery(); _.HttpRoutes.IncludeType <RouteEndpoints>(); }); }
public async Task use_fan_out_exchange() { var uri = "rabbitmq://localhost:5672/fanout/north/messages"; var publisher = await JasperRuntime.ForAsync(_ => { _.Publish.AllMessagesTo(uri); _.Hosting.ConfigureLogging(x => x.AddConsole()); }); var receiver1 = await JasperRuntime.ForAsync(_ => { _.Transports.ListenForMessagesFrom(uri); _.Services.AddSingleton <ColorHistory>(); _.Services.AddSingleton <MessageTracker>(); _.Hosting.ConfigureLogging(x => x.AddConsole()); }); var receiver2 = await JasperRuntime.ForAsync(_ => { _.Transports.ListenForMessagesFrom(uri); _.Services.AddSingleton <ColorHistory>(); _.Services.AddSingleton <MessageTracker>(); _.Hosting.ConfigureLogging(x => x.AddConsole()); }); var receiver3 = await JasperRuntime.ForAsync(_ => { _.Transports.ListenForMessagesFrom(uri); _.Services.AddSingleton <ColorHistory>(); _.Services.AddSingleton <MessageTracker>(); _.Hosting.ConfigureLogging(x => x.AddConsole()); }); var wait1 = receiver1.Get <MessageTracker>().WaitFor <ColorChosen>(); var wait2 = receiver2.Get <MessageTracker>().WaitFor <ColorChosen>(); var wait3 = receiver3.Get <MessageTracker>().WaitFor <ColorChosen>(); try { await publisher.Messaging.Send(new ColorChosen { Name = "Purple" }); await wait1; //await wait2; //await wait3; receiver1.Get <ColorHistory>().Name.ShouldBe("Purple"); //receiver2.Get<ColorHistory>().Name.ShouldBe("Purple"); //receiver3.Get<ColorHistory>().Name.ShouldBe("Purple"); } finally { publisher.Dispose(); receiver1.Dispose(); receiver2.Dispose(); receiver3.Dispose(); } }
public async Task <JasperRuntime> theRuntime() { if (_runtime == null) { _runtime = await JasperRuntime.ForAsync(theRegistry); } return(_runtime); }
public async Task succeed_with_lambda_check_using_service() { var runtime = await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.EnvironmentCheck <Thing>("Bazinga!", t => t.AllGood()); }); }
public async Task hosting_environment_app_name_is_application_assembly_name() { var runtime = await JasperRuntime.ForAsync <MySpecialRegistry>(); // This is important for the MVC and ASP.Net Core integration to work correctly runtime.Get <IHostingEnvironment>().ApplicationName.ShouldBe(Assembly.GetExecutingAssembly().FullName); await runtime.Shutdown(); }
public async Task succeed_with_lambda_check() { await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.EnvironmentCheck("Bazinga!", () => { }); }); }
protected async Task with(JasperRegistry registry) { registry.Services.Scan(_ => { _.TheCallingAssembly(); _.WithDefaultConventions(); }); Runtime = await JasperRuntime.ForAsync(registry); }
public static async Task <IScenarioResult> Scenario(Action <Scenario> configure) { if (_runtime == null) { // Okay if it's rebuilt here. Better than locking issues _runtime = await JasperRuntime.ForAsync <HttpTestingApp>(); } return(await _runtime.Scenario(configure)); }
public async Task <MessageHandler> HandlerFor <TMessage>() { if (_runtime == null) { _runtime = await JasperRuntime.ForAsync(theRegistry); } return(_runtime.Get <HandlerGraph>().HandlerFor(typeof(TMessage))); }
public async Task do_not_fail_if_advanced_says_not_to_blow_up() { var runtime = await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.EnvironmentCheck <NegativeCheck>(); _.Advanced.ThrowOnValidationErrors = false; }); await runtime.Shutdown(); }
private async Task <IScenarioResult> scenario(Action <Scenario> configure) { _runtime = await JasperRuntime.ForAsync <JasperRegistry>(_ => { _.Handlers.DisableConventionalDiscovery(true); _.HttpRoutes.IncludeType <CustomReaderWriterEndpoint>(); _.Services.For <IMessageDeserializer>().Add <XmlReader <SpecialInput> >(); _.Services.For <IMessageSerializer>().Add <XmlWriter <SpecialOutput> >(); }); return(await _runtime.Scenario(configure)); }
private async Task <IScenarioResult> scenario(Action <Scenario> configure) { theRegistry.Handlers.DisableConventionalDiscovery(true); if (_runtime == null) { _runtime = await JasperRuntime.ForAsync(theRegistry); } return(await _runtime.Scenario(configure)); }
public async Task fail_with_lambda_check_with_service() { var aggregate = await Exception <AggregateException> .ShouldBeThrownByAsync(async() => { await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.EnvironmentCheck <Thing>("Bazinga!", t => t.ThrowUp()); }); }); }
public async Task timeout_on_task() { var aggregate = await Exception <AggregateException> .ShouldBeThrownByAsync(async() => { var runtime = await JasperRuntime.ForAsync(_ => { _.Handlers.DisableConventionalDiscovery(); _.Services.EnvironmentCheck <Thing>("Bazinga!", t => t.TooLong(), 50.Milliseconds()); }); }); }