public void application_service_registrations_win() { using (var runtime = JasperHost.For <AppWithOverrides>()) { runtime.Get <IContainer>().DefaultRegistrationIs <IModuleService, AppsModuleService>(); } }
public MartenBackedMessagePersistenceTests() { theHost = JasperHost.For(_ => { _.Extensions.UseMarten(x => { x.Connection(Servers.PostgresConnectionString); x.PLV8Enabled = false; }); }); theEnvelope = ObjectMother.Envelope(); theEnvelope.Message = new Message1(); theEnvelope.ExecutionTime = DateTime.Today.ToUniversalTime().AddDays(1); theEnvelope.Status = EnvelopeStatus.Scheduled; var persistence = theHost.Get <IEnvelopePersistence>(); persistence.Admin.RebuildSchemaObjects(); persistence.ScheduleJob(theEnvelope).Wait(3.Seconds()); persisted = persistence.Admin .AllIncomingEnvelopes() .GetAwaiter() .GetResult() .FirstOrDefault(x => x.Id == theEnvelope.Id); }
public async Task enqueue_locally_with_designated_worker_queue() { var registry = new JasperRegistry(); registry.Handlers.DisableConventionalDiscovery(); registry.Services.Scan(x => { x.TheCallingAssembly(); x.WithDefaultConventions(); }); registry.Handlers.IncludeType <MessageConsumer>(); registry.Handlers.Worker("foo").MaximumParallelization(3); var tracker = new MessageTracker(); registry.Services.AddSingleton(tracker); using (var runtime = JasperHost.For(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 MartenBackedMessagePersistenceTests() { theHost = JasperHost.For(_ => { _.MartenConnectionStringIs(Servers.PostgresConnectionString); _.Include <MartenBackedPersistence>(); _.ConfigureMarten(x => { x.PLV8Enabled = false; }); _.HttpRoutes.DisableConventionalDiscovery(); }); theEnvelope = ObjectMother.Envelope(); theEnvelope.Message = new Message1(); theEnvelope.ExecutionTime = DateTime.Today.ToUniversalTime().AddDays(1); theEnvelope.Status = TransportConstants.Scheduled; var persistence = theHost.Get <IEnvelopePersistence>(); persistence.Admin.RebuildSchemaObjects(); persistence.ScheduleJob(theEnvelope).Wait(3.Seconds()); persisted = persistence.Admin .AllIncomingEnvelopes() .GetAwaiter() .GetResult() .FirstOrDefault(x => x.Id == theEnvelope.Id); }
public async Task enqueue_locally_lightweight() { var registry = new JasperRegistry(); registry.Handlers.IncludeType <RecordCallHandler>(); registry.Services.ForSingletonOf <IFakeStore>().Use <FakeStore>(); var tracker = new MessageTracker(); registry.Services.AddSingleton(tracker); using (var runtime = JasperHost.For(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); } }
public static void Go(string[] args) { // SAMPLE: Bootstrapping-Basic using (var host = JasperHost.Basic()) { // do stuff } // ENDSAMPLE // SAMPLE: Bootstrapping-Basic2 using (var host = Host.CreateDefaultBuilder() .UseJasper() .Start()) { // do stuff } // ENDSAMPLE // SAMPLE: Bootstrapping-Basic3 using (var runtime = JasperHost.For(_ => { _.Endpoints.ListenAtPort(2001); })) { // do stuff } // ENDSAMPLE }
public void RecycleIfNecessary() { if (Host == null) { Host = JasperHost.Basic(); } }
protected void AllHandlersCompileSuccessfully() { using (var runtime = JasperHost.For(theRegistry)) { runtime.Get <HandlerGraph>().Chains.Length.ShouldBeGreaterThan(0); } }
public async Task send_message_to_and_receive_through_asb_with_named_topic() { var publisher = JasperHost.For(_ => { _.Endpoints.ConfigureAzureServiceBus(ConnectionString); _.Endpoints.PublishAllMessages().ToAzureServiceBusTopic("special").Durably(); _.Extensions.UseMarten(opts => { opts.Connection(Servers.PostgresConnectionString); opts.AutoCreateSchemaObjects = AutoCreate.All; opts.DatabaseSchemaName = "sender"; }); _.Extensions.UseMessageTrackingTestingSupport(); }); publisher.RebuildMessageStorage(); var receiver = JasperHost.For(_ => { _.Endpoints.ConfigureAzureServiceBus(ConnectionString); _.Endpoints.ListenToAzureServiceBusTopic("special", "receiver"); _.Services.AddSingleton <ColorHistory>(); _.Extensions.UseMessageTrackingTestingSupport(); _.Extensions.UseMarten(opts => { opts.Connection(Servers.PostgresConnectionString); opts.AutoCreateSchemaObjects = AutoCreate.All; opts.DatabaseSchemaName = "receiver"; }); _.Handlers.IncludeType <ColorHandler>(); }); receiver.RebuildMessageStorage(); try { await publisher .TrackActivity() .AlsoTrack(receiver) .SendMessageAndWait(new ColorChosen { Name = "Orange" }); receiver.Get <ColorHistory>().Name.ShouldBe("Orange"); } finally { publisher.Dispose(); receiver.Dispose(); } }
public async Task send_message_to_and_receive_through_asb_with_wildcard_topics() { var publisher = JasperHost.For(_ => { _.Settings.AddAzureServiceBusConnection("jasper", ConnectionString); _.Publish.AllMessagesTo("azureservicebus://jasper/topic/*"); _.Handlers.DisableConventionalDiscovery(); }); var receiver1 = JasperHost.For(_ => { _.Settings.AddAzureServiceBusConnection("jasper", ConnectionString); _.Transports.ListenForMessagesFrom("azureservicebus://jasper/subscription/receiver1/topic/*"); _.Services.AddSingleton <MessageTracker>(); _.Handlers.DisableConventionalDiscovery() .IncludeType <TracksMessage <TopicA> >() .IncludeType <TracksMessage <TopicB> >(); }); var receiver2 = JasperHost.For(_ => { _.Settings.AddAzureServiceBusConnection("jasper", ConnectionString); _.Transports.ListenForMessagesFrom("azureservicebus://jasper/subscription/receiver2/topic/*"); _.Services.AddSingleton <MessageTracker>(); _.Handlers.DisableConventionalDiscovery() .IncludeType <TracksMessage <TopicC> >(); }); var waitForA = receiver1.Get <MessageTracker>().WaitFor <TopicA>(); var waitForB = receiver1.Get <MessageTracker>().WaitFor <TopicB>(); var waitForC = receiver2.Get <MessageTracker>().WaitFor <TopicC>(); try { var topicA = new TopicA(); var topicB = new TopicB(); var topicC = new TopicC(); await publisher.Messaging.Send(topicA); await publisher.Messaging.Send(topicB); await publisher.Messaging.Send(topicC); var receivedA = (await waitForA).Message.ShouldBeOfType <TopicA>(); var receivedB = (await waitForB).Message.ShouldBeOfType <TopicB>(); var receivedC = (await waitForC).Message.ShouldBeOfType <TopicC>(); } finally { publisher.Dispose(); receiver1.Dispose(); receiver2.Dispose(); } }
public override void SetUp() { var registry = new ScheduledMessageApp(); theReceiver = registry.Receiver; theHost = JasperHost.For(registry); }
private void with <T>(Action <T> action) { using (var runtime = JasperHost.For(theRegistry)) { var service = runtime.Get <T>(); action(service); } }
public override void TearDown() { var runtime = JasperHost.For(_options); var graph = runtime.Get <HandlerGraph>(); Context.State.Store(runtime); }
static int Main(string[] args) { return(JasperHost.Run(args, _ => { _.Publish.AllMessagesTo("durable://localhost:8567"); _.Transports.LightweightListenerAt(8568); })); }
public DefaultApp() { Host = JasperHost.For(x => { x.Extensions.UseMessageTrackingTestingSupport(); x.Handlers.IncludeType <MessageConsumer>(); }); }
public override void SetUp() { var receiverPort = PortFinder.FindPort(3340); var senderPort = PortFinder.FindPort(3370); var publishingUri = $"tcp://localhost:{receiverPort}/durable"; var senderRegistry = new JasperOptions(); senderRegistry.Handlers .DisableConventionalDiscovery() .IncludeType <CascadeReceiver>() .IncludeType <ScheduledMessageHandler>(); senderRegistry.Extensions.UseMessageTrackingTestingSupport(); senderRegistry.Endpoints.Publish(x => { x.Message <TriggerMessage>(); x.Message <ItemCreated>(); x.Message <Question>(); x.Message <ScheduledMessage>(); x.ToPort(receiverPort).Durably(); }); senderRegistry.Endpoints.ListenAtPort(senderPort).Durable(); configureSender(senderRegistry); theSender = JasperHost.For(senderRegistry); theSender.RebuildMessageStorage(); var receiverRegistry = new JasperOptions(); receiverRegistry.Extensions.UseMessageTrackingTestingSupport(); receiverRegistry.Handlers.DisableConventionalDiscovery() .IncludeType <TTriggerHandler>() .IncludeType <TItemCreatedHandler>() .IncludeType <QuestionHandler>() .IncludeType <ScheduledMessageHandler>(); receiverRegistry.Endpoints.ListenAtPort(receiverPort).Durable(); receiverRegistry.Extensions.UseMessageTrackingTestingSupport(); configureReceiver(receiverRegistry); theReceiver = JasperHost.For(receiverRegistry); theReceiver.RebuildMessageStorage(); initializeStorage(theSender, theReceiver); }
public void throw_descriptive_description_with_no_topic_routers() { using (var host = JasperHost.Basic()) { var router = host.Get <IEnvelopeRouter>(); Should.Throw <InvalidOperationException>(() => router.RouteToTopic("one", new Envelope(new Topic1()))); } }
public IHost theHost() { if (_host == null) { _host = JasperHost.For(theOptions); } return(_host); }
public override void SetUp() { _messageLogger = new StorytellerMessageLogger(new LoggerFactory(), new NulloMetrics(), new JasperOptions()); _messageLogger.Start(Context); _senderWatcher = new SenderLatchDetected(new LoggerFactory()); new SqlServerEnvelopeStorageAdmin(new SqlServerSettings { ConnectionString = Servers.SqlServerConnectionString, SchemaName = "receiver" }).RecreateAll(); new SqlServerEnvelopeStorageAdmin(new SqlServerSettings { ConnectionString = Servers.SqlServerConnectionString, SchemaName = "sender" }).RecreateAll(); using (var conn = new SqlConnection(Servers.SqlServerConnectionString)) { conn.Open(); conn.CreateCommand(@" IF OBJECT_ID('receiver.trace_doc', 'U') IS NOT NULL drop table receiver.trace_doc; ").ExecuteNonQuery(); conn.CreateCommand(@" create table receiver.trace_doc ( id uniqueidentifier not null primary key, name varchar(100) not null ); ").ExecuteNonQuery(); } _receivers = new LightweightCache <string, IHost>(key => { var registry = new ReceiverApp(); registry.Services.AddSingleton <IMessageLogger>(_messageLogger); return(JasperHost.For(registry)); }); _senders = new LightweightCache <string, IHost>(key => { var registry = new SenderApp(); registry.Services.AddSingleton <IMessageLogger>(_messageLogger); registry.Services.For <ITransportLogger>().Use(_senderWatcher); return(JasperHost.For(registry)); }); }
public IJasperHost theHost() { if (_host == null) { _host = JasperHost.For(theRegistry); } return(_host); }
public end_to_end_with_persistence(ITestOutputHelper output) { _output = output; theSender = JasperHost.For <ItemSender>(); theReceiver = JasperHost.For <ItemReceiver>(); theSender.RebuildMessageStorage(); theReceiver.RebuildMessageStorage(); }
public void should_be_auto_request_filter_present_in_fully_compliant_mode() { using (var runtime = JasperHost.For(x => x.HttpRoutes.AspNetCoreCompliance = ComplianceMode.FullyCompliant)) { runtime.Container.Model.For <IStartupFilter>().Instances .Any(x => x.ImplementationType == typeof(AutoRequestServicesStartupFilter)) .ShouldBeTrue(); } }
public override void TearDown() { var runtime = JasperHost.For(_options); // Goofy, but gets things hooked up here runtime.Get <IMessageLogger>().As <StorytellerMessageLogger>().Start(Context); Context.State.Store(runtime); }
public void should_not_be_any_auto_request_filter() { using (var runtime = JasperHost.For(x => x.HttpRoutes.AspNetCoreCompliance = ComplianceMode.GoFaster)) { runtime.Container.Model.For <IStartupFilter>().Instances .Any(x => x.ImplementationType == typeof(AutoRequestServicesStartupFilter)) .ShouldBeFalse(); } }
public override void SetUp() { theTracker = new Jasper.Messaging.Tracking.MessageTracker(); var receiverPort = PortFinder.FindPort(3340); var senderPort = PortFinder.FindPort(3370); var publishingUri = $"tcp://localhost:{receiverPort}/durable"; var senderRegistry = new JasperRegistry(); senderRegistry.Handlers .DisableConventionalDiscovery() .IncludeType <CascadeReceiver>() .IncludeType <ScheduledMessageHandler>(); senderRegistry.Services.AddSingleton(theTracker); senderRegistry.Publish.Message <TriggerMessage>().To(publishingUri); senderRegistry.Publish.Message <ItemCreated>().To(publishingUri); senderRegistry.Publish.Message <Question>().To(publishingUri); senderRegistry.Publish.Message <ScheduledMessage>().To(publishingUri); senderRegistry.Transports.DurableListenerAt(senderPort); configureSender(senderRegistry); theSender = JasperHost.For(senderRegistry); theSender.RebuildMessageStorage(); var receiverRegistry = new JasperRegistry(); receiverRegistry.Handlers.DisableConventionalDiscovery() .IncludeType <TTriggerHandler>() .IncludeType <TItemCreatedHandler>() .IncludeType <QuestionHandler>() .IncludeType <ScheduledMessageHandler>(); receiverRegistry.Transports.DurableListenerAt(receiverPort); receiverRegistry.Handlers.Worker("items").IsDurable() .HandlesMessage <ItemCreated>(); receiverRegistry.Services.AddSingleton(theTracker); configureReceiver(receiverRegistry); theReceiver = JasperHost.For(receiverRegistry); theReceiver.RebuildMessageStorage(); initializeStorage(theSender, theReceiver); }
public void bootstrap_with_connection_string() { using (var runtime = JasperHost.For(x => x.Extensions.PersistMessagesWithPostgresql(Servers.PostgresConnectionString))) { runtime.Get <PostgresqlSettings>() .ConnectionString.ShouldBe(Servers.PostgresConnectionString); } }
public void hosting_environment_app_name_is_application_assembly_name() { using (var runtime = JasperHost.For <MySpecialRegistry>()) { // This is important for the MVC and ASP.Net Core integration to work correctly runtime.Get <IHostingEnvironment>().ApplicationName.ShouldBe(Assembly.GetExecutingAssembly().FullName); } }
/// <summary> /// Helper to quickly attach Alba scenario tests to a Jasper application /// </summary> /// <param name="registry"></param> /// <returns></returns> public static SystemUnderTest For(JasperRegistry registry) { var builder = JasperHost.CreateDefaultBuilder().UseJasper(registry); var system = new SystemUnderTest(builder, registry.ApplicationAssembly); system.As <ISystemUnderTest>().Urls = new JasperUrlLookup(system.Services.GetRequiredService <IUrlRegistry>()); return(system); }
public async Task schedule_send_message_to_and_receive_through_asb_with_durable_transport_option() { var publisher = JasperHost.For(_ => { _.Endpoints.ConfigureAzureServiceBus(ConnectionString); _.Endpoints.PublishAllMessages().ToAzureServiceBusQueue("messages").Durably(); _.Extensions.UseMarten(opts => { opts.Connection(Servers.PostgresConnectionString); opts.AutoCreateSchemaObjects = AutoCreate.All; opts.DatabaseSchemaName = "sender"; }); _.Extensions.UseMessageTrackingTestingSupport(); }); publisher.RebuildMessageStorage(); var receiver = JasperHost.For(_ => { _.Endpoints.ConfigureAzureServiceBus(ConnectionString); _.Endpoints.ListenToAzureServiceBusQueue("messages"); _.Extensions.UseMessageTrackingTestingSupport(); _.Services.AddSingleton <ColorHistory>(); _.Extensions.UseMarten(opts => { opts.Connection(Servers.PostgresConnectionString); opts.AutoCreateSchemaObjects = AutoCreate.All; opts.DatabaseSchemaName = "receiver"; }); }); receiver.RebuildMessageStorage(); try { await publisher .TrackActivity() .AlsoTrack(receiver) .Timeout(15.Seconds()) .ExecuteAndWait(c => c.ScheduleSend(new ColorChosen { Name = "Orange" }, 5.Seconds())); receiver.Get <ColorHistory>().Name.ShouldBe("Orange"); } finally { publisher.Dispose(); receiver.Dispose(); } }
public async Task schedule_send_message_to_and_receive_through_asb_with_durable_transport_option() { var uri = "azureservicebus://jasper/durable/queue/messages"; var publisher = JasperHost.For(_ => { _.Settings.AddAzureServiceBusConnection("jasper", ConnectionString); _.HttpRoutes.DisableConventionalDiscovery(); _.Publish.AllMessagesTo(uri); _.Include <MartenBackedPersistence>(); _.Settings.ConfigureMarten(x => { x.Connection(Servers.PostgresConnectionString); x.AutoCreateSchemaObjects = AutoCreate.All; }); }); publisher.RebuildMessageStorage(); var receiver = JasperHost.For(_ => { _.Settings.AddAzureServiceBusConnection("jasper", ConnectionString); _.HttpRoutes.DisableConventionalDiscovery(); _.Transports.ListenForMessagesFrom(uri); _.Services.AddSingleton <ColorHistory>(); _.Services.AddSingleton <MessageTracker>(); _.Include <MartenBackedPersistence>(); _.Settings.MartenConnectionStringIs(Servers.PostgresConnectionString); }); receiver.RebuildMessageStorage(); var wait = receiver.Get <MessageTracker>().WaitFor <ColorChosen>(); try { await publisher.Messaging.ScheduleSend(new ColorChosen { Name = "Orange" }, 5.Seconds()); await wait; receiver.Get <ColorHistory>().Name.ShouldBe("Orange"); } finally { publisher.Dispose(); receiver.Dispose(); } }