public static Task <IStartableEndpoint> Create(Settings.Settings settings, TransportCustomization transportCustomization, TransportSettings transportSettings, LoggingSettings loggingSettings, IContainer container, Action <ICriticalErrorContext> onCriticalError, EmbeddableDocumentStore documentStore, EndpointConfiguration configuration, bool isRunningAcceptanceTests)
        {
            var endpointName = settings.ServiceName;

            if (configuration == null)
            {
                configuration = new EndpointConfiguration(endpointName);
                var assemblyScanner = configuration.AssemblyScanner();
                assemblyScanner.ExcludeAssemblies("ServiceControl.Plugin");
            }

            configuration.Pipeline.Register(typeof(FullTypeNameOnlyBehavior), "Remove asm qualified name from the message type header");

            // HACK: Yes I know, I am hacking it to pass it to RavenBootstrapper!
            configuration.GetSettings().Set(documentStore);
            configuration.GetSettings().Set("ServiceControl.Settings", settings);

            configuration.SendOnly();

            transportCustomization.CustomizeSendOnlyEndpoint(configuration, transportSettings);
            //DisablePublishing API is available only on TransportExtensions for transports that implement IMessageDrivenPubSub so we need to set settings directly
            configuration.GetSettings().Set("NServiceBus.PublishSubscribe.EnablePublishing", false);

            var routing = new RoutingSettings(configuration.GetSettings());

            routing.RouteToEndpoint(typeof(RegisterNewEndpoint), settings.ServiceControlQueueAddress);
            routing.RouteToEndpoint(typeof(MarkMessageFailureResolvedByRetry), settings.ServiceControlQueueAddress);

            configuration.GetSettings().Set(loggingSettings);
            configuration.SetDiagnosticsPath(loggingSettings.LogPath);

            // sagas are not auto-disabled for send-only endpoints
            configuration.DisableFeature <Sagas>();

            configuration.UseSerialization <NewtonsoftSerializer>();

            configuration.Conventions().DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t) || IsExternalContract(t));

            if (!isRunningAcceptanceTests)
            {
                configuration.ReportCustomChecksTo(settings.ServiceControlQueueAddress);
            }

#pragma warning disable CS0618 // Type or member is obsolete
            configuration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));
#pragma warning restore CS0618 // Type or member is obsolete

            configuration.DefineCriticalErrorAction(criticalErrorContext =>
            {
                onCriticalError(criticalErrorContext);
                return(Task.FromResult(0));
            });

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                configuration.EnableInstallers();
            }

            return(Endpoint.Create(configuration));
        }
Exemplo n.º 2
0
 public static void ApplyRouting(this RoutingSettings config)
 {
     config.RouteToEndpoint(typeof(TestCommand), EndpointNames.SagaEndpoint);
     config.RouteToEndpoint(typeof(FinishSaga), EndpointNames.SagaEndpoint);
     config.RouteToEndpoint(typeof(TestMessage), EndpointNames.ExternalHandler);
     config.RouteToEndpoint(typeof(DoWorkCommand), EndpointNames.ExternalHandler);
 }
Exemplo n.º 3
0
 private static void ConfigureRouting(RoutingSettings <RabbitMQTransport> routing)
 {
     routing.RouteToEndpoint(typeof(DeviceDeleteCommand), "sdms.device-listener.host");
     routing.RouteToEndpoint(typeof(DeviceVerificationMessage), "sdms.device-listener.host");
     routing.RouteToEndpoint(typeof(DeviceAssignCommand), "sdms.device-listener.host");
     routing.RouteToEndpoint(typeof(DeviceCommandExecute), "sdms.device-enactor.host");
 }
 public void ConfigureRouting(RoutingSettings <SqlServerTransport> routingSettings)
 {
     routingSettings.RouteToEndpoint(typeof(PlaceOrder), "Order");
     routingSettings.RouteToEndpoint(typeof(PlaceOrderResult), "Client");
     routingSettings.RouteToEndpoint(typeof(PlaceReservation), "Warehouse");
     routingSettings.RouteToEndpoint(typeof(PlaceReservationResult), "Order");
 }
Exemplo n.º 5
0
        private static void RegisterPublishers(RoutingSettings routing)
        {
            var assembly = typeof(ICreateOrderEvent).Assembly;

            routing.RouteToEndpoint(assembly: assembly, destination: "MultiPull.Clients.ClientProcessor");
            routing.RouteToEndpoint(assembly: assembly, destination: "MultiPull.Clients.OrderProcessor");
        }
Exemplo n.º 6
0
        private static void RegisterPublishers(RoutingSettings <KafkaTransport> routing)
        {
            var assembly = typeof(ICreateOrderEvent).Assembly;

            routing.RouteToEndpoint(assembly: assembly, destination: "MultiPull.Clients.StoreProcessor");
            routing.RouteToEndpoint(typeof(CreateOrderCommand).Assembly, "MultiPull.MessageBusWithKafka");
        }
 private static void SetupRouting(RoutingSettings <RabbitMQTransport> routing)
 {
     routing.RouteToEndpoint(typeof(PostRequest).Assembly
                             , "Varian.Contracts.Commands.SubscriberEndpoint"
                             , "Varian.Subscriber");
     routing.RouteToEndpoint(typeof(PostRequest).Assembly
                             , "Varian.Contracts.Commands.PublisherEndpoint"
                             , "Varian.Publisher");
 }
Exemplo n.º 8
0
        public async Task AddOrUpdateElasticNews(NewsUpdateOrCreateCommand newsUpdateOrCreate)
        {
            _routing.RouteToEndpoint(typeof(NewsUpdateOrCreateCommand), _messageQueueName);
            var endpointInstance = await Endpoint.Start(_endPoint).ConfigureAwait(false);

            await endpointInstance.Send(newsUpdateOrCreate).ConfigureAwait(false);

            await endpointInstance.Stop().ConfigureAwait(false);
        }
        private static void ConfigureRouting(RoutingSettings routing)
        {
            routing.RouteToEndpoint(
                typeof(ImportLevyDeclarationsCommand).Assembly,
                typeof(ImportLevyDeclarationsCommand).Namespace,
                "SFA.DAS.EmployerFinance.MessageHandlers"
                );

            routing.RouteToEndpoint(
                typeof(SendEmailCommand).Assembly,
                typeof(SendEmailCommand).Namespace,
                "SFA.DAS.Notifications.MessageHandlers"
                );
        }
Exemplo n.º 10
0
        private static async Task MainAsync()
        {
            const string EndpointName = "Finance.Endpoint";

            Console.Title = EndpointName;
            var endpointConfiguration = new EndpointConfiguration(EndpointName);

            endpointConfiguration.UsePersistence <LearningPersistence>();
            TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>();
            RoutingSettings <LearningTransport>     routing   = transport.Routing();

            routing.RouteToEndpoint(typeof(ChargeCreditCardRequest), "ItOps.CreditCardProcessor.Gateway");
            endpointConfiguration.EnableFeature <RoutingSlips>();

            endpointConfiguration.RegisterComponents(
                configureComponents =>
            {
                configureComponents.ConfigureComponent <InMemoryOrders>(DependencyLifecycle.SingleInstance);
            });

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

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
            await endpoint.Stop().ConfigureAwait(false);
        }
Exemplo n.º 11
0
 internal virtual RoutingSettings <SqsTransport> BuildEndpointSQSRouting(
     RoutingSettings <SqsTransport> routing)
 {
     routing.RouteToEndpoint(typeof(PlaceOrder), "NSB.Server");
     routing.RegisterPublisher(typeof(OrderPlaced), "NSB.Server");
     return(routing);
 }
Exemplo n.º 12
0
        public void WhenPassingTransportAddressForSenderInsteadOfEndpointName_ShouldThrowException()
        {
            var routingSettings          = new RoutingSettings(new SettingsHolder());
            var expectedExceptionMessage = expectedExceptionMessageForWrongEndpointName;

            var exception = Assert.Throws <ArgumentException>(() => routingSettings.RouteToEndpoint(typeof(MessageWithoutNamespace), "EndpointName@MyHost"));

            Assert.AreEqual(expectedExceptionMessage, exception.Message);
        }
Exemplo n.º 13
0
 public SenderWithInvalidMappingFile()
 {
     EndpointSetup <DefaultServer>(c =>
     {
         var routingSettings = new RoutingSettings <MsmqTransport>(c.GetSettings());
         routingSettings.RouteToEndpoint(typeof(Message), "someReceiver");
         routingSettings.InstanceMappingFile().FilePath(mappingFilePath);
     });
 }
Exemplo n.º 14
0
 public SenderWithEmptyMappingFile()
 {
     EndpointSetup <DefaultServer>(c =>
     {
         var routingSettings = new RoutingSettings <MsmqTransport>(c.GetSettings());
         routingSettings.RouteToEndpoint(typeof(Message), logicalEndpointName);
         routingSettings.InstanceMappingFile().FilePath(mappingFilePath);
     });
 }
        public void WhenPassingTransportAddressForSenderInsteadOfEndpointName_UsingAssemblyAndNamespace_ShouldThrowException()
        {
            var routingSettings          = new RoutingSettings(settings);
            var expectedExceptionMessage = expectedExceptionMessageForWrongEndpointName;

            var exception = Assert.Throws <ArgumentException>(() => routingSettings.RouteToEndpoint(Assembly.GetExecutingAssembly(), nameof(MessageNamespaceA), "EndpointName@MyHost"));

            Assert.AreEqual(expectedExceptionMessage, exception.Message);
        }
Exemplo n.º 16
0
            public SendingEndpointUsingRoutingApi()
            {
                EndpointSetup <DefaultServer>(c =>
                {
                    c.Conventions().DefiningCommandsAs(t => t == typeof(SomeCommand));

                    var routing = new RoutingSettings(c.GetSettings());
                    routing.RouteToEndpoint(typeof(SomeCommand).Assembly, Conventions.EndpointNamingConvention(typeof(ReceivingEndpoint)));
                }).ExcludeType <SomeCommand>(); //exclude type to simulate an unobtrusive message assembly which isn't automatically loaded.
            }
Exemplo n.º 17
0
        private static void RouteSampleCommands(RoutingSettings <AzureServiceBusTransport> routing)
        {
            var endpointName = "prospaworkernsb";

            if (ProspaConstants.Environments.IsDevelopment)
            {
                endpointName += $".{Environment.MachineName.ToLower()}";
            }

            routing.RouteToEndpoint(typeof(SampleCommand), endpointName);
        }
            public Sender()
            {
                EndpointSetup <DefaultServer>(c =>
                {
                    var routing = new RoutingSettings <MsmqTransport>(c.GetSettings());

                    // only configure logical endpoint in routing
                    routing.RouteToEndpoint(typeof(Message), ReceiverEndpointName);
                    routing.InstanceMappingFile().FilePath(mappingFilePath);
                });
            }
Exemplo n.º 19
0
        private static void RouteSampleCommands(RoutingSettings <AzureServiceBusTransport> routing)
        {
            var endpointName = "TODO: Endpoint Name";

            if (Constants.Environments.IsDevelopment)
            {
                endpointName += $".{Environment.MachineName}";
            }

            routing.RouteToEndpoint(typeof(SampleCommand), endpointName);
        }
        public void WhenRoutingMessageTypeToEndpoint_ShouldConfigureMessageTypeInRoutingTable()
        {
            var routingSettings = new RoutingSettings(settings);

            routingSettings.RouteToEndpoint(typeof(SomeMessageType), "destination");

            var routingTable = ApplyConfiguredRoutes(routingSettings);
            var route        = routingTable.GetRouteFor(typeof(SomeMessageType));

            Assert.That(route, Is.Not.Null);
            Assert.That(route.Endpoint, Is.EqualTo("destination"));
        }
 public static void AddRouting(this RoutingSettings routingSettings)
 {
     routingSettings.RouteToEndpoint(typeof(RunHealthCheckCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(ProviderApproveCohortCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(ProviderSendCohortCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(SendEmailToEmployerCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(ApproveTransferRequestCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(RejectTransferRequestCommand), CommitmentsV2MessageHandler);
     routingSettings.RouteToEndpoint(typeof(SendEmailCommand), NotificationsMessageHandler);
 }
Exemplo n.º 22
0
        public virtual RoutingSettings <LearningTransport> BuildEndpointRouting(
            RoutingSettings <LearningTransport> routing)
        {
            var routes = typeScanner.GetAllTypesWithPublishingEndpoints();

            foreach (var route in routes)
            {
                var assemblyType = route.Item1;
                var endpoint     = GetEndpointNameWithPrefixedEnvironment(GetEnvironmentName(), route.Item2);
                routing.RouteToEndpoint(assemblyType, endpoint);
            }

            return(routing);
        }
 public static void AddRouting(this RoutingSettings routingSettings)
 {
     routingSettings.RouteToEndpoint(typeof(CreateIncentiveCommand), QueueNames.ApprenticeshipIncentivesCreate);
     routingSettings.RouteToEndpoint(typeof(CalculateEarningsCommand), QueueNames.ApprenticeshipIncentivesCalculateEarnings);
     routingSettings.RouteToEndpoint(typeof(CompleteEarningsCalculationCommand), QueueNames.CompleteEarningsCalculation);
     routingSettings.RouteToEndpoint(typeof(AddEmployerVendorIdCommand), QueueNames.AddEmployerVendorId);
     routingSettings.RouteToEndpoint(typeof(WithdrawCommand), QueueNames.ApprenticeshipIncentivesWithdraw);
     routingSettings.RouteToEndpoint(typeof(UpdateVendorRegistrationCaseStatusForAccountCommand), QueueNames.UpdateVendorRegistrationCaseStatus);
 }
        public void WhenRoutingAssemblyWithNamespaceToEndpoint_ShouldOnlyConfigureMessagesWithinThatNamespace()
        {
            var routingSettings = new RoutingSettings(settings);

            routingSettings.RouteToEndpoint(Assembly.GetExecutingAssembly(), nameof(MessageNamespaceA), "destination");

            var routingTable = ApplyConfiguredRoutes(routingSettings);

            var someMessageRoute             = routingTable.GetRouteFor(typeof(SomeMessageType));
            var otherMessageRoute            = routingTable.GetRouteFor(typeof(OtherMessageType));
            var messageWithoutNamespaceRoute = routingTable.GetRouteFor(typeof(MessageWithoutNamespace));

            Assert.That(someMessageRoute, Is.Not.Null, "because SomeMessageType is in the given namespace");
            Assert.That(otherMessageRoute, Is.Null, "because OtherMessageType is not in the given namespace");
            Assert.That(messageWithoutNamespaceRoute, Is.Null, "because MessageWithoutNamespace is not in the given namespace");
        }
        public void WhenRoutingAssemblyToEndpoint_ShouldConfigureAllContainedMessagesInRoutingTable()
        {
            var routingSettings = new RoutingSettings(settings);

            routingSettings.RouteToEndpoint(Assembly.GetExecutingAssembly(), "destination");

            var routingTable = ApplyConfiguredRoutes(routingSettings);

            var someMessageRoute             = routingTable.GetRouteFor(typeof(SomeMessageType));
            var otherMessageRoute            = routingTable.GetRouteFor(typeof(OtherMessageType));
            var messageWithoutNamespaceRoute = routingTable.GetRouteFor(typeof(MessageWithoutNamespace));

            Assert.That(someMessageRoute, Is.Not.Null);
            Assert.That(otherMessageRoute, Is.Not.Null);
            Assert.That(messageWithoutNamespaceRoute, Is.Not.Null);
        }
        public void WhenRoutingAssemblyWithNamespaceToEndpointAndSpecifyingEmptyNamespace_ShouldOnlyConfigureMessagesWithinEmptyNamespace(string emptyNamespace)
        {
            var routingSettings = new RoutingSettings(settings);

            routingSettings.RouteToEndpoint(Assembly.GetExecutingAssembly(), emptyNamespace, "destination");

            var routingTable = ApplyConfiguredRoutes(routingSettings);

            var someMessageRoute             = routingTable.GetRouteFor(typeof(SomeMessageType));
            var otherMessageRoute            = routingTable.GetRouteFor(typeof(OtherMessageType));
            var messageWithoutNamespaceRoute = routingTable.GetRouteFor(typeof(MessageWithoutNamespace));

            Assert.That(someMessageRoute, Is.Null);
            Assert.That(otherMessageRoute, Is.Null);
            Assert.That(messageWithoutNamespaceRoute, Is.Not.Null);
        }
Exemplo n.º 27
0
        private static async Task Main(string[] args)
        {
            Console.Title = "ClientUI";
            var endpointConfiguration = new EndpointConfiguration("ClientUI");
            TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>();

            RoutingSettings <LearningTransport> routing = transport.Routing();

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

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

            await RunLoop(endpointInstance).ConfigureAwait(false);

            await endpointInstance.Stop().ConfigureAwait(false);
        }
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services
            .AddMvcCore()
            .AddCors()
            .AddJsonFormatters()
            .AddApiExplorer()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services
            .AddSignalR();
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            services.AddSingleton <IEquipmentRepository, EquipmentRepository>();
            services.AddScoped <EquipmentFilter>();
            services.AddSingleton(serviceProvider => _endpoint);

            var endpointConfiguration = new EndpointConfiguration("Bondora.ConstructionEquipmentRental.Service");

            // It's used for development, for real case we should use any real transport (RabbitMQ and so on).
            TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>();

            UpdateableServiceProvider container = null;

            endpointConfiguration.UseContainer <ServicesBuilder>(customizations =>
            {
                customizations.ExistingServices(services);
                customizations.ServiceProviderFactory(serviceCollection =>
                {
                    container = new UpdateableServiceProvider(serviceCollection);
                    return(container);
                });
            });

            RoutingSettings <LearningTransport> routing = transport.Routing();

            routing.RouteToEndpoint(
                assembly: typeof(GetInvoiceCommand).Assembly,
                destination: "Bondora.ConstructionEquipmentRental.Billing");

            _endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            return(container);
        }
Exemplo n.º 29
0
        public virtual RoutingSettings <SqlServerTransport> BuildEndpointRouting(
            RoutingSettings <SqlServerTransport> routing)
        {
            var routes = typeScanner.GetAllTypesWithPublishingEndpoints();

            foreach (var route in routes)
            {
                var assemblyType = route.Item1;
                var endpoint     = GetEndpointNameWithPrefixedEnvironment(GetEnvironmentName(), route.Item2);

                if (assemblyType.IsInterface)
                {
                    routing.RegisterPublisher(assemblyType, endpoint);
                }
                else if (assemblyType.IsClass && !assemblyType.IsAbstract)
                {
                    routing.RouteToEndpoint(assemblyType, endpoint);
                }
            }

            return(routing);
        }
Exemplo n.º 30
0
 public static void AddRouting(this RoutingSettings routingSettings)
 {
     routingSettings.RouteToEndpoint(typeof(SendEmailCommand), NotificationsMessageHandler);
 }