Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            var endpointConfiguration = new NServiceBus.EndpointConfiguration("demo");
            var transport             = endpointConfiguration.UseTransport <RabbitMQTransport>();

            transport.ConnectionString(@"host=localhost;username=guest;password=guest");
            transport.UseConventionalRoutingTopology();
            transport.Routing().RouteToEndpoint(typeof(HelloWorldMessage), "consumer1");
            endpointConfiguration.SendOnly();
            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.EnableInstallers();
            var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            services.AddSingleton <IMessageSession>(endpointInstance);
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info {
                    Title = "My API", Version = "v1"
                });
            });
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }
Esempio n. 2
0
        public static void ApplyCommonConfiguration(this EndpointConfiguration config, bool asSendOnly = false)
        {
            config.UseSerialization <NewtonsoftSerializer>();
            config.UseTransport <LearningTransport>();
            config.UsePersistence <LearningPersistence>();

            config.AuditProcessedMessagesTo("audit");
            config.SendFailedMessagesTo("error");

            config.SendHeartbeatTo(
                serviceControlQueue: "Particular.ServiceControl",
                frequency: TimeSpan.FromSeconds(10),
                timeToLive: TimeSpan.FromSeconds(5));

            var messageConventions = config.Conventions();

            messageConventions.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages"));
            messageConventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages.Events"));
            messageConventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages.Commands"));

            if (asSendOnly)
            {
                config.SendOnly();
            }
            else
            {
                var metrics = config.EnableMetrics();
                metrics.SendMetricDataToServiceControl(
                    serviceControlMetricsAddress: "Particular.Monitoring",
                    interval: TimeSpan.FromSeconds(5));
            }
        }