예제 #1
0
        public void registrations()
        {
            using (var runtime = JasperRuntime.For(x =>
                                                   x.Settings.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString)))
            {
                runtime.Container.Model.HasRegistrationFor <SqlConnection>().ShouldBeTrue();
                runtime.Container.Model.HasRegistrationFor <DbConnection>().ShouldBeTrue();

                runtime.Container.Model.For <SqlConnection>().Default.Lifetime.ShouldBe(ServiceLifetime.Scoped);


                runtime.Container.Model.HasRegistrationFor <IEnvelopePersistor>().ShouldBeTrue();



                runtime.Get <SqlConnection>().ConnectionString.ShouldBe(Servers.SqlServerConnectionString);
                runtime.Get <DbConnection>().ShouldBeOfType <SqlConnection>()
                .ConnectionString.ShouldBe(Servers.SqlServerConnectionString);
            }
        }
예제 #2
0
        public void registers_document_store_in_a_usable_way()
        {
            using (var runtime = JasperRuntime.For <MartenUsingApp>())
            {
                var doc = new FakeDoc {
                    Id = Guid.NewGuid()
                };

                using (var session = runtime.Get <IDocumentSession>())
                {
                    session.Store(doc);
                    session.SaveChanges();
                }

                using (var query = runtime.Get <IQuerySession>())
                {
                    query.Load <FakeDoc>(doc.Id).ShouldNotBeNull();
                }
            }
        }
예제 #3
0
        public end_to_end()
        {
            theSender = JasperRuntime.For(new JasperRegistry());

            var receiver = new JasperRegistry();

            receiver.Transports.ListenForMessagesFrom(theAddress);
            receiver.Handlers.OnException <DivideByZeroException>().Requeue();
            receiver.Handlers.OnException <TimeoutException>().RetryLater(10.Seconds());

            receiver.Handlers.DefaultMaximumAttempts = 3;

            delayedJobs = new FakeDelayedJobProcessor();

            receiver.Services.For <IDelayedJobProcessor>().Use(delayedJobs);

            receiver.Services.For <MessageTracker>().Use(theTracker);

            theReceiver = JasperRuntime.For(receiver);
        }
예제 #4
0
        public void transport_endpoints_are_enabled_and_a_chain_should_be_present_with_overridden_urls()
        {
            using (var runtime = JasperRuntime.For(_ =>
            {
                _.Settings.Alter <BusSettings>(x =>
                {
                    x.Http.EnableMessageTransport = true;
                    x.Http.RelativeUrl = "api";
                });
            }))
            {
                var routes = runtime.Get <RouteGraph>();

                routes.ChainForAction <TransportEndpoint>(x => x.put__messages(null, null, null))
                .Route.Pattern.ShouldBe("api");

                routes.ChainForAction <TransportEndpoint>(x => x.put__messages_durable(null, null, null))
                .Route.Pattern.ShouldBe("api/durable");
            }
        }
        public subscription_repository_functionality()
        {
            using (var store = DocumentStore.For(ConnectionSource.ConnectionString))
            {
                store.Advanced.Clean.CompletelyRemoveAll();
            }

            _runtime = JasperRuntime.For(_ =>
            {
                _.Settings.Alter <MartenSubscriptionSettings>(x => x.StoreOptions.Connection(ConnectionSource.ConnectionString));

                _.Include <MartenBackedSubscriptions>();

                _.ServiceName = "MartenSampleApp";
            });



            theRepository = _runtime.Get <ISubscriptionsRepository>();
        }
예제 #6
0
        public MartenCallbackTests()
        {
            theRuntime = JasperRuntime.For(_ =>
            {
                _.MartenConnectionStringIs(Servers.PostgresConnectionString);

                _.ConfigureMarten(x =>
                {
                    x.Storage.Add <PostgresqlEnvelopeStorage>();
                    x.PLV8Enabled = false;
                });
            });

            theStore = theRuntime.Get <IDocumentStore>();

            theStore.Advanced.Clean.CompletelyRemoveAll();
            theStore.Schema.ApplyAllConfiguredChangesToDatabase();

            theEnvelope        = ObjectMother.Envelope();
            theEnvelope.Status = TransportConstants.Incoming;

            var marker = new EnvelopeTables(new MessagingSettings(), new StoreOptions());

            using (var session = theStore.OpenSession())
            {
                session.StoreIncoming(marker, theEnvelope);
                session.SaveChanges();
            }


            var logger = TransportLogger.Empty();

            theRetries = new EnvelopeRetries(new MartenEnvelopePersistor(theStore, marker), logger,
                                             new MessagingSettings());


            var persistor = new MartenEnvelopePersistor(theStore, marker);

            theCallback =
                new DurableCallback(theEnvelope, Substitute.For <IWorkerQueue>(), persistor, theRetries, logger);
        }
예제 #7
0
        public override void SetUp()
        {
            _transport = new StubTransport();
            _tracker   = new AttemptTracker();

            var registry = new JasperBusRegistry();

            registry.ListenForMessagesFrom("stub://1".ToUri());
            registry.Services.AddService <ITransport>(_transport);
            registry.Services.AddService(_tracker);
            registry.SendMessage <ErrorCausingMessage>()
            .To("stub://1".ToUri());

            _runtime = JasperRuntime.For(registry);

            _graph = _runtime.Container.GetInstance <HandlerGraph>();
            _chain = _graph.ChainFor <ErrorCausingMessage>();


            _bus = _runtime.Container.GetInstance <IServiceBus>();
        }
        public void can_write_then_read()
        {
            ServiceCapabilities services;

            using (var runtime = JasperRuntime.For(_ =>
            {
                _.Handlers.DisableConventionalDiscovery(true);

                _.ServiceName = "AppWithSubscriptions";


                _.Subscribe.To <Message1>();
                _.Subscribe.To <Message2>();

                _.Publish.Message <Message3>();
                _.Publish.Message <Message4>();
                _.Publish.Message <Message5>();

                _.Settings.Alter <BusSettings>(x => x.ThrowOnValidationErrors = false);
            }))
            {
                services = runtime.Capabilities;

                services.Errors.Length.ShouldBeGreaterThan(0);
                services.Subscriptions.Length.ShouldBeGreaterThan(0);
                services.Published.Length.ShouldBeGreaterThan(0);
            }

            services.WriteToFile("services.json");

            var services2 = ServiceCapabilities.ReadFromFile("services.json");

            services2.ShouldNotBeNull();
            services2.ServiceName.ShouldBe(services.ServiceName);

            services2.Subscriptions.Length.ShouldBe(2);
            services2.Published.Length.ShouldBe(services.Published.Length);
            services2.Errors.Length.ShouldBe(services.Errors.Length);
        }
예제 #9
0
        public void 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;
            });

            using (var runtime = JasperRuntime.For(app))
            {
                var mySettings = runtime.Get <MyFakeSettings>();
                var colors     = runtime.Get <Colors>();

                mySettings.SomeSetting.ShouldBe(29);
                colors.Red.ShouldBe("#ff0000");
            }
        }
예제 #10
0
        public async Task can_configure_builder()
        {
            theRegistry.Hosting.ConfigureAppConfiguration((_, config) =>
            {
                config
                .AddJsonFile("appsettings.json")
                .AddJsonFile("colors.json");
            });


            theRegistry.Settings.Require <Colors>();
            theRegistry.Settings.Require <MyFakeSettings>();

            using (var runtime = JasperRuntime.For(theRegistry))
            {
                var colors   = runtime.Get <Colors>();
                var settings = runtime.Get <MyFakeSettings>();

                colors.Red.ShouldBe("#ff0000");
                settings.SomeSetting.ShouldBe(1);
            }
        }
예제 #11
0
        public override void SetUp()
        {
            _envelopes.Clear();
            _nodeLockers.Clear();

            _workers        = new RecordingWorkerQueue();
            _schedulerAgent = new RecordingSchedulingAgent();

            _runtime = JasperRuntime.For(_ =>
            {
                _.MartenConnectionStringIs(ConnectionSource.ConnectionString);
                _.Services.AddSingleton <ITransport, StubTransport>();

                _.Services.AddSingleton <IWorkerQueue>(_workers);
                _.Services.AddSingleton <ISchedulingAgent>(_schedulerAgent);

                _.Include <MartenBackedPersistence>();

                _.Settings.Alter <MessagingSettings>(x =>
                {
                    x.FirstNodeReassignmentExecution = 30.Minutes();
                    x.FirstScheduledJobExecution     = 30.Minutes();
                    x.FirstNodeReassignmentExecution = 30.Minutes();
                    x.NodeReassignmentPollingTime    = 30.Minutes();
                });
            });

            _runtime.Get <MartenBackedDurableMessagingFactory>().ClearAllStoredMessages();

            _marker      = _runtime.Get <EnvelopeTables>();
            _serializers = _runtime.Get <MessagingSerializationGraph>();

            theStore = _runtime.Get <IDocumentStore>();
            theStore.Advanced.Clean.DeleteAllDocuments();

            _currentNodeId = _runtime.Get <MessagingSettings>().UniqueNodeId;

            _owners["This Node"] = _currentNodeId;
        }
예제 #12
0
        public override void SetUp()
        {
            _tracker = new AttemptTracker();

            var registry = new JasperRegistry();

            registry.Transports.ListenForMessagesFrom("stub://1".ToUri());
            registry.Services.AddSingleton <ITransport, StubTransport>();
            registry.Services.AddSingleton(_tracker);
            registry.Publish.Message <ErrorCausingMessage>()
            .To("stub://1".ToUri());

            _runtime = JasperRuntime.For(registry);

            _transport = _runtime.Container.GetAllInstances <ITransport>().OfType <StubTransport>().Single();

            _graph = _runtime.Get <HandlerGraph>();
            _chain = _graph.ChainFor <ErrorCausingMessage>();


            _bus = _runtime.Get <IMessageContext>();
        }
예제 #13
0
        public void bootstrap_with_configuration()
        {
            var registry = new JasperRegistry();

            registry.Configuration.AddInMemoryCollection(new Dictionary <string, string> {
                { "connection", ConnectionSource.ConnectionString }
            });

            registry.Settings.PersistMessagesWithSqlServer((c, s) =>
            {
                s.ConnectionString = c.Configuration["connection"];
            });

            using (var runtime = JasperRuntime.For(registry))
            {
                runtime.Container.Model.DefaultTypeFor <IDurableMessagingFactory>()
                .ShouldBe(typeof(SqlServerBackedDurableMessagingFactory));

                runtime.Get <SqlServerSettings>()
                .ConnectionString.ShouldBe(ConnectionSource.ConnectionString);
            }
        }
예제 #14
0
        public JasperRuntime BuildRuntime()
        {
            // SAMPLE: what-the-cli-is-doing

            // The --log-level flag value overrides your application's
            // LogLevel
            if (LogLevelFlag.HasValue)
            {
                Registry.ConfigureLogging(x => x.SetMinimumLevel(LogLevelFlag.Value));
            }

            if (VerboseFlag)
            {
                Console.WriteLine("Verbose flag is on.");

                // The --verbose flag adds console and
                // debug logging, as well as setting
                // the minimum logging level down to debug
                Registry.ConfigureLogging(x =>
                {
                    x.SetMinimumLevel(LogLevel.Debug);

                    x.AddConsole();
                    x.AddDebug();
                });
            }

            // The --environment flag is used to set the environment
            // property on the IHostedEnvironment within your system
            if (EnvironmentFlag.IsNotEmpty())
            {
                Registry.UseEnvironment(EnvironmentFlag);
            }
            // ENDSAMPLE

            return(JasperRuntime.For(Registry));
        }
        public async Task use_custom_reader_writer()
        {
            Reply1Reader.WasUsed = false;
            Reply1Writer.WasUsed = false;

            var requestorRegistry = new JasperRegistry();

            requestorRegistry.Publish.Message <Request1>().To("tcp://localhost:2457/incoming");
            requestorRegistry.Transports.ListenForMessagesFrom("tcp://localhost:1555");
            var requestor = JasperRuntime.For(requestorRegistry);

            var replierRegistry = new JasperRegistry();

            replierRegistry.Transports.ListenForMessagesFrom("tcp://localhost:2457/incoming");
            var replier = JasperRuntime.For(replierRegistry);


            try
            {
                var reply = await requestor.Get <IServiceBus>()
                            .Request <Reply1>(new Request1 {
                    One = 3, Two = 4
                }, new RequestOptions {
                    Timeout = 60.Seconds()
                });

                reply.Sum.ShouldBe(7);

                Reply1Reader.WasUsed.ShouldBeTrue();
                Reply1Writer.WasUsed.ShouldBeTrue();
            }
            finally
            {
                replier?.Dispose();
                requestor?.Dispose();
            }
        }
예제 #16
0
        public void can_alter_and_registry_still_gets_defaults()
        {
            var app = new MyApp();

            app.Settings.Build(_ =>
            {
                _.AddJsonFile("appsettings.json");
                _.AddJsonFile("colors.json");
            });

            app.Settings.Configure <Colors>();
            app.Settings.Alter <MySettings>(_ =>
            {
                _.SomeSetting = 29;
            });

            var runtime    = JasperRuntime.For(app);
            var container  = new Container(runtime.Registry.Services);
            var mySettings = container.GetInstance <MySettings>();
            var colors     = container.GetInstance <Colors>();

            mySettings.SomeSetting.ShouldBe(29);
            colors.Red.ShouldBe("#ff0000");
        }
예제 #17
0
        public override void SetUp()
        {
            _envelopes.Clear();
            _nodeLockers.Clear();

            _workers        = new RecordingWorkerQueue();
            _schedulerAgent = new RecordingSchedulingAgent();

            _runtime = JasperRuntime.For(_ =>
            {
                _.Settings.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString);
                _.Services.AddSingleton <ITransport, StubTransport>();

                _.Services.AddSingleton <IWorkerQueue>(_workers);
                _.Services.AddSingleton <ISchedulingAgent>(_schedulerAgent);


                _.Settings.Alter <JasperOptions>(x =>
                {
                    x.Retries.FirstNodeReassignmentExecution = 30.Minutes();
                    x.ScheduledJobs.FirstExecution           = 30.Minutes();
                    x.Retries.FirstNodeReassignmentExecution = 30.Minutes();
                    x.Retries.NodeReassignmentPollingTime    = 30.Minutes();
                });
            });

            _runtime.Get <SqlServerBackedDurableMessagingFactory>().ClearAllStoredMessages();

            _serializers = _runtime.Get <MessagingSerializationGraph>();

            _runtime.RebuildMessageStorage();

            _currentNodeId = _runtime.Get <JasperOptions>().UniqueNodeId;

            _owners["This Node"] = _currentNodeId;
        }
예제 #18
0
        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.Hosting.ConfigureLogging(x =>
            {
                x.AddConsole();
                x.AddDebug();
            });


            senderRegistry.Transports.DurableListenerAt(senderPort);

            configureSender(senderRegistry);

            theSender = JasperRuntime.For(senderRegistry);


            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);

            receiverRegistry.Hosting.ConfigureLogging(x =>
            {
                x.AddConsole();
                x.AddDebug();
            });

            configureReceiver(receiverRegistry);

            theReceiver = JasperRuntime.For(receiverRegistry);


            initializeStorage(theSender, theReceiver);
        }
예제 #19
0
 public discovering_and_using_extensions()
 {
     theRuntime = JasperRuntime.For <AppWithOverrides>();
 }
예제 #20
0
 public InvokeBenchmark()
 {
     _runtime = JasperRuntime.For <Sender1>();
 }
예제 #21
0
        public end_to_end_with_in_memory()
        {
            DelayedMessageHandler.Reset();

            theRuntime = JasperRuntime.For <DelayedMessageApp>();
        }
예제 #22
0
 public void Start()
 {
     _runtime = JasperRuntime.For <BusRegistry>();
 }
 public cascading_message_with_outbox()
 {
     theSender   = JasperRuntime.For(new OutboxSender(theTracker));
     theReceiver = JasperRuntime.For <OutboxReceiver>();
 }
예제 #24
0
        public MessageInvocationTests()
        {
            theRuntime = JasperRuntime.For <SampleApp>();

            theRuntime.Get <IDocumentStore>().Advanced.Clean.CompletelyRemoveAll();
        }
 public composing_request_delegate_order()
 {
     theRegistry.Handlers.DisableConventionalDiscovery(true);
     _runtime = new Lazy <JasperRuntime>(() => JasperRuntime.For(theRegistry));
 }
예제 #26
0
 public code_generation()
 {
     runtime = JasperRuntime.For <MartenUsingApp>();
 }
예제 #27
0
 public PingPongBenchmark()
 {
     _receiving = JasperRuntime.For <Receiver1>();
     _sender    = JasperRuntime.For <Sender1>();
 }
예제 #28
0
        public SubscriptionComplianceSpecs()
        {
            using (var runtime = JasperRuntime.For(x =>
            {
                x.Handlers.DisableConventionalDiscovery();
                configure(x);
            }))
            {
                var displayTimings = runtime.Bootstrapping.DisplayTimings();
                //throw new Exception(displayTimings.ToString());

                beforeEach(runtime);
            }



            _coolColors1 = app("Cool", _ =>
            {
                _.Handles <BlueMessage>();
                _.Handles <GreenMessage>();
                //_.Handles<PurpleMessage>();

                _.Publish.Message <CyanMessage>();

                _.Transports.LightweightListenerAt(2000);
            });

            //var displayTimings = _coolColors1.Bootstrapping.DisplayTimings();
            //throw new Exception(displayTimings.ToString());

            _coolColors2 = app("Cool", _ =>
            {
                _.Handles <BlueMessage>();
                _.Handles <GreenMessage>();
                _.Handles <PurpleMessage>();

                _.Publish.Message <ChartreuseMessage>();

                _.Transports.LightweightListenerAt(2001);
            });

            _warmColors = app("Warm", _ =>
            {
                _.Handles <RedMessage>();
                _.Handles <YellowMessage>();
                _.Handles <OrangeMessage>();

                _.Publish.Message <MagentaMessage>();

                _.Transports.LightweightListenerAt(2002);
            });

            _primaryColors = app("Primary", _ =>
            {
                _.Publish.Message <BlueMessage>();
                _.Publish.Message <RedMessage>();
                _.Publish.Message <YellowMessage>();

                _.Transports.LightweightListenerAt(2003);
            });


            _otherWarm = app("OtherWarm", _ =>
            {
                _.Handles <RedMessage>();
            });
        }
예제 #29
0
 internal void Bootstrap(IMessageLogger logger)
 {
     _registry.Services.AddSingleton(logger);
     Runtime = JasperRuntime.For(_registry);
 }
예제 #30
0
 public end_to_end()
 {
     theRuntime = JasperRuntime.For <WebSocketPingPongApp>();
 }