示例#1
0
        public void Go()
        {
            // SAMPLE: using-configuration-with-jasperoptions
            var host = WebHost.CreateDefaultBuilder()
                       .UseStartup <Startup>()
                       .UseJasper(configure: (context, options) =>
            {
                // I'm not using it here, but you have access to
                // the ASP.Net Core HostingEnvironment
                var hosting = context.HostingEnvironment;

                // And the IConfiguration for your system
                var config = context.Configuration;

                // Add a transport listener at the Uri in
                // your configuration
                options.ListenForMessagesFrom(config["listener"]);

                // Add a subscription for a specific message type
                options.AddSubscription(Subscription.ForType <Message1>(config["outgoing"]));

                // Or add a subscription for all messages
                options.AddSubscription(Subscription.All(config["outgoing"]));
            })
                       .Start();

            // ENDSAMPLE
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, JasperOptions messaging)
        {
            // This is optional, but it's awfully helpful
            // to configure the message bus part of Jasper directly
            // from configuration
            messaging.ListenForMessagesFrom(Configuration["ListeningEndpoint"]);
            messaging.AddSubscription(Subscription.All(Configuration["OtherServiceUri"]));


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            // The ordering here is meaningful, but we think that
            // Jasper's routing is more efficient, so let it try
            // first
            app.UseJasper();

            app.UseMvc();
        }
 /// <summary>
 /// Send all messages published through this application to the Uri
 /// value in configuration with the designated key
 /// </summary>
 /// <param name="configKey">The value of IConfiguration[configKey] to find the Uri</param>
 public void AllMessagesToUriValueInConfig(string configKey)
 {
     _settings.Alter <JasperOptions>((c, options) =>
     {
         var uri = c.Configuration.TryGetUri(configKey);
         options.AddSubscription(Subscription.All(uri));
     });
 }
示例#4
0
        public void read_settings_from_json()
        {
            using (var runtime = JasperRuntime.For(x =>
            {
                x.Hosting.ConfigureAppConfiguration((context, config) => config.AddJsonFile("messaging.json"));
            }))
            {
                var settings = runtime.Get <JasperOptions>();

                // See the messaging.json file
                settings.DisableAllTransports.ShouldBeTrue();
                settings.ScheduledJobs.PollingTime.ShouldBe(10.Seconds());
                settings.Listeners.Contains("tcp://localhost:2000".ToUri()).ShouldBeTrue();
                settings.Subscriptions.Contains(Subscription.All("tcp://localhost:2002".ToUri())).ShouldBeTrue();
            }
        }
示例#5
0
        public void try_stuff()
        {
            var settings = new JasperOptions
            {
                ThrowOnValidationErrors = false,
                Listeners     = new[] { "tcp://localhost:2000".ToUri(), "tcp://localhost:2001".ToUri() },
                Subscriptions = new[]
                {
                    Subscription.All("tcp://localhost:2002".ToUri()),
                    Subscription.ForType <Message1>("tcp://localhost:2004".ToUri())
                }
            };

            var json = JsonConvert.SerializeObject(settings, Formatting.Indented);

            _output.WriteLine(json);
        }
示例#6
0
        public async Task read_settings_from_json()
        {
            var runtime = await JasperRuntime.ForAsync(x => { x.Configuration.AddJsonFile("messaging.json"); });

            try
            {
                var settings = runtime.Get <MessagingSettings>();

                // See the messaging.json file
                settings.DisableAllTransports.ShouldBeTrue();
                settings.ScheduledJobs.PollingTime.ShouldBe(10.Seconds());
                settings.Listeners.Contains("tcp://localhost:2000".ToUri()).ShouldBeTrue();
                settings.Subscriptions.Contains(Subscription.All("tcp://localhost:2002".ToUri())).ShouldBeTrue();
            }
            finally
            {
                await runtime.Shutdown();
            }
        }
示例#7
0
            public ConfigUsingApp()
            {
                Settings.Messaging((context, options) =>
                {
                    // I'm not using it here, but you have access to
                    // the ASP.Net Core HostingEnvironment
                    var hosting = context.HostingEnvironment;

                    // And the IConfiguration for your system
                    var config = context.Configuration;

                    // Add a transport listener at the Uri in
                    // your configuration
                    options.ListenForMessagesFrom(config["listener"]);

                    // Add a subscription for a specific message type
                    options.AddSubscription(Subscription.ForType <Message1>(config["outgoing"]));

                    // Or add a subscription for all messages
                    options.AddSubscription(Subscription.All(config["outgoing"]));
                });
            }
        /// <summary>
        ///     Directs Jasper to try to publish all messages locally even if there are other
        ///     subscribers for the message type
        /// </summary>
        public void AllMessagesLocally()
        {
            var rule = Subscription.All();

            _settings.Messaging(x => x.LocalPublishing.Add(rule));
        }
示例#9
0
        public void TestSubscriptionFetchAllRecords()
        {
            var list = Subscription.All();

            Assert.AreNotEqual(list.Count, 0);
        }
示例#10
0
 internal void AddSubscriptionForAllMessages()
 {
     _subscriptions.Add(Subscription.All());
 }