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 AddNsb(this IServiceCollection services)
        {
            var licensePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NSB_License.xml");

            var config = new EndpointConfiguration("SignalRTest");

            if (File.Exists(licensePath))
            {
                config.LicensePath(licensePath);
            }

            config.UseTransport <LearningTransport>();

            config.RegisterComponents(
                configComp =>
            {
                configComp.ConfigureComponent(() =>
                                              GetHubContext(services),
                                              DependencyLifecycle.InstancePerCall);
            });

            var session = Endpoint.Start(config).Result;

            services.AddSingleton <IMessageSession>(session);
        }
Esempio n. 3
0
        //create messaging endpoint
        private static async Task Main()
        {
            Console.Title = "ClientUI";

            //EndpointConfiguration class defintes all settings which determines how endpoint operates
            //string ClientUI is endpoint name
            var endpointConfiguration = new EndpointConfiguration("ClientUI");

            //            //transport is a setting which NServiceBus uses to send and receives messages
            //            var transport = endpointConfiguration.UseTransport<LearningTransport>();

            //MSMQ does not support natively Publish/Subscribe
            var transport = endpointConfiguration.UseTransport <MsmqTransport>();

            //message subscription info stored in memory instead
            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            //error queue specified
            endpointConfiguration.SendFailedMessagesTo("error");

            //creates message queues required by endpoints
            endpointConfiguration.EnableInstallers();

            //establises commands of type PlaceOrder should be sent to the Sales endpoint
            var routing = transport.Routing();

            routing.RouteToEndpoint(typeof(PlaceOrder), "Sales");

            endpointConfiguration.UseSerialization <JsonSerializer>();

            //starts endpoint
            var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                   .ConfigureAwait(false);

            await RunLoop(endpointInstance)
            .ConfigureAwait(false);

            //endpoint runs until user presses enter and then stops
            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
Esempio n. 4
0
    public static async Task <IEndpointInstance> Configure(string endpointName)
    {
        var endpointConfiguration = new NServiceBus.EndpointConfiguration(endpointName);

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();

        var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>();

        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read the 'AzureServiceBus_ConnectionString' environment variable. Check the sample prerequisites.");
        }

        transport.ConnectionString(connectionString);

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        return(endpointInstance);
    }