public void ThreeWayRouterConfig() { #region three-way-router var routerConfig = new RouterConfiguration("MyRouter"); routerConfig.AddInterface <SqlTransport>("A", transportExtensions => {}); routerConfig.AddInterface <SqlTransport>("B", transportExtensions => {}); routerConfig.AddInterface <SqlTransport>("C", transportExtensions => {}); var staticRouting = routerConfig.UseStaticRoutingProtocol(); //Send all messages to endpoints which name starts with Sales via interface A staticRouting.AddRoute( destinationFilter: (iface, destination) => destination.Endpoint.StartsWith("Sales."), destinationFilterDescription: "To Sales", gateway: null, iface: "A"); staticRouting.AddRoute( (iface, destination) => destination.Endpoint.StartsWith("Shipping."), "To Shipping", null, "B"); staticRouting.AddRoute( (iface, destination) => destination.Endpoint.StartsWith("Billing."), "To Billing", null, "C"); #endregion }
static async Task Main() { Console.Title = "Samples.Router.MixedTransports.Router"; #region RouterConfig var routerConfig = new RouterConfiguration("Samples.Router.MixedTransports.Router"); var msmqInterface = routerConfig.AddInterface <MsmqTransport>("MSMQ", t => { }); msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); var rabbitMQInterface = routerConfig.AddInterface <RabbitMQTransport>("RabbitMQ", t => { t.ConnectionString("host=localhost"); t.UseConventionalRoutingTopology(); }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("MSMQ", "RabbitMQ"); routerConfig.AutoCreateQueues(); #endregion var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
public void SiteBasedRouting() { #region backplane var routerConfig = new RouterConfiguration("Router.WestEurope"); routerConfig.AddInterface <MsmqTransport>("Endpoints", transportExtensions => { }); routerConfig.AddInterface <AzureStorageQueuesTransport>("Backplane", transportExtensions => { }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); //Send all messages from the Backplane interface directly to the destination endpoints staticRouting.AddRoute( (iface, destination) => iface == "Backplane", "From outside", null, "Endpoints"); //Send all messages to site WestUS through the Backplane interface via Router.WestUS staticRouting.AddRoute( destinationFilter: (iface, destination) => destination.Site == "WestUS", destinationFilterDescription: "To West US", gateway: "Router.WestUS", iface: "Backplane"); //Send all messages to site EastUS through the Backplane interface via Router.EastUS staticRouting.AddRoute( (iface, destination) => destination.Site == "EastUS", "To East US", "Router.EastUS", "Backplane"); #endregion }
void ConfigureRouter(Context c, RouterConfiguration cfg) { cfg.AddInterface <TestTransport>("Left", t => t.BrokerAlpha()).EnableMessageDrivenPublishSubscribe(subscriptionStorage); var leftIface = cfg.AddInterface <AzureServiceBusTransport>("Right", t => { var connString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString"); t.ConnectionString(connString); var settings = t.GetSettings(); var builder = new ConventionsBuilder(settings); builder.DefiningEventsAs(EventConvention); settings.Set <NServiceBus.Conventions>(builder.Conventions); var topology = t.UseEndpointOrientedTopology(); topology.EnableMigrationToForwardingTopology(); topology.RegisterPublisher(typeof(MyAsbEvent), Conventions.EndpointNamingConvention(typeof(Publisher))); var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder()); settings.Set("MainSerializer", serializer); }); leftIface.LimitMessageProcessingConcurrencyTo(1); //To ensure when tracer arrives the subscribe request has already been processed.; cfg.AddRule(_ => new SuppressTransactionScopeRule()); cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right"); }
static async Task Main() { Console.Title = "Router"; #region RouterConfig var routerConfig = new RouterConfiguration("Samples.Router.UpdateAndPublish.Router"); var frontendInterface = routerConfig.AddInterface <SqlServerTransport>("SQL", t => { t.ConnectionString(ConnectionString); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); var backendInterface = routerConfig.AddInterface <LearningTransport>("Learning", t => { }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("SQL", "Learning"); staticRouting.AddForwardRoute("Learning", "SQL"); routerConfig.AutoCreateQueues(); #endregion SqlHelper.EnsureDatabaseExists(ConnectionString); var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
static async Task Main(string[] args) { Console.Title = "Samples.Azure.ServiceBus.Bridge"; 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."); } #region bridge-general-configuration var bridgeConfiguration = new RouterConfiguration("Bridge"); var azureInterface = bridgeConfiguration.AddInterface <AzureServiceBusTransport>("ASB", transport => { //Prevents ASB from using TransactionScope transport.Transactions(TransportTransactionMode.ReceiveOnly); transport.ConnectionString(connectionString); }); var msmqInterface = bridgeConfiguration.AddInterface <MsmqTransport>("MSMQ", transport => { transport.Transactions(TransportTransactionMode.ReceiveOnly); }); msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); //Configure the host of the MSMQ endpoint msmqInterface.EndpointInstances.AddOrReplaceInstances("publishers", new List <EndpointInstance> { new EndpointInstance("Samples.Azure.ServiceBus.MsmqEndpoint").AtMachine(Environment.MachineName) }); bridgeConfiguration.AutoCreateQueues(); var staticRouting = bridgeConfiguration.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute( incomingInterface: "MSMQ", outgoingInterface: "ASB"); staticRouting.AddForwardRoute( incomingInterface: "ASB", outgoingInterface: "MSMQ"); #endregion #region bridge-execution var bridge = Router.Create(bridgeConfiguration); await bridge.Start().ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await bridge.Stop().ConfigureAwait(false); #endregion }
static async Task Main() { Console.Title = "Samples.Router.Sites.RouterB"; var routerConfig = new RouterConfiguration("SiteB"); routerConfig.AddInterface <LearningTransport>("Local", t => { }); routerConfig.AddInterface <MsmqTransport>("Tunnel", t => { }).EnableMessageDrivenPublishSubscribe(new NullSubscriptionStore()); routerConfig.AutoCreateQueues(); #region ConfigureRouterB var routing = routerConfig.UseStaticRoutingProtocol(); routing.AddForwardRoute("Tunnel", "Local"); #endregion var router = Router.Create(routerConfig); await router.Start() .ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop() .ConfigureAwait(false); }
private static void RouteFromLearningToAzure(RouterConfiguration routerConfig, IConfiguration config, RouteTable staticRouting) { routerConfig.AddInterface <LearningTransport>("LearningTransportA", t => { }); var connectionStringB = config.GetConnectionString("NServiceBus:AzureServiceBusA"); var azureServiceBusBInterface = routerConfig.AddInterface <AzureServiceBusTransport>("AzureServiceBusA", t => { t.ConnectionString(connectionStringB); }); staticRouting.AddForwardRoute("LearningTransportA", "AzureServiceBusA"); }
public async Task Start() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); var routerConfig = new RouterConfiguration(EndpointName); // if we want to change to something other than "poison" // routerConfig.PoisonQueueName = "..." #region Configure WebApi interface var webApiConnectionString = config.GetConnectionString("WebApi"); var webApiInterface = routerConfig.AddInterface <SqlServerTransport>(WebApiInterface, t => { t.ConnectionString(webApiConnectionString); t.DefaultSchema("nsb"); // two connection strings, would be escalated to distributed otherwise t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); #endregion #region Configure backend interface var backendConnectionString = config.GetConnectionString("Nsb"); var backendInterface = routerConfig.AddInterface <SqlServerTransport>(BackendInterface, t => { t.ConnectionString(backendConnectionString); t.DefaultSchema("nsb"); // two connection strings, would be escalated to distributed otherwise t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); #endregion #region Routing var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute(WebApiInterface, BackendInterface); staticRouting.AddForwardRoute(BackendInterface, WebApiInterface); #endregion // TODO comment out routerConfig.AutoCreateQueues(); try { _endpoint = NServiceBus.Router.Router.Create(routerConfig); await _endpoint.Start(); } catch (Exception ex) { FailFast("Failed to start.", ex); } }
static async Task Main(string[] args) { Console.Title = "Samples.Azure.ServiceBus.Bridge"; 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."); } #region bridge-general-configuration var bridgeConfiguration = new RouterConfiguration("Bridge"); var azureInterface = bridgeConfiguration.AddInterface <AzureServiceBusTransport>("ASB", transport => { //Prevents ASB from using TransactionScope transport.Transactions(TransportTransactionMode.ReceiveOnly); transport.ConnectionString(connectionString); // TODO: ASB requires serializer to be registered. // Currently, there's no way to specify serialization for the bridged endpoints // endpointConfiguration.UseSerialization<T>(); var settings = transport.GetSettings(); var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder()); settings.Set("MainSerializer", serializer); var topology = transport.UseEndpointOrientedTopology().EnableMigrationToForwardingTopology(); topology.RegisterPublisher(typeof(OtherEvent), "Samples.Azure.ServiceBus.AsbEndpoint"); }); var msmqInterface = bridgeConfiguration.AddInterface <MsmqTransport>("MSQM", transport => { }); msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); bridgeConfiguration.AutoCreateQueues(); #endregion #region bridge-execution var bridge = Router.Create(bridgeConfiguration); await bridge.Start().ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await bridge.Stop().ConfigureAwait(false); #endregion }
static async Task Main() { Console.Title = "Switch"; SqlHelper.EnsureDatabaseExists(SwitchConnectionString); SqlHelper.EnsureDatabaseExists(ConnectionStrings.Blue); SqlHelper.EnsureDatabaseExists(ConnectionStrings.Red); SqlHelper.EnsureDatabaseExists(ConnectionStrings.Green); #region SwitchConfig var routerConfig = new RouterConfiguration("Switch"); routerConfig.AddInterface <SqlServerTransport>("Blue", t => { t.ConnectionString(ConnectionStrings.Blue); }); routerConfig.AddInterface <SqlServerTransport>("Red", t => { t.ConnectionString(ConnectionStrings.Red); }); routerConfig.AddInterface <SqlServerTransport>("Green", t => { t.ConnectionString(ConnectionStrings.Green); }); routerConfig.AutoCreateQueues(); #endregion #region SwitchForwarding var staticRouting = routerConfig.UseStaticRoutingProtocol(); //Send all messages to endpoints which name starts with Sales via interface A staticRouting.AddRoute( destinationFilter: (iface, destination) => destination.Endpoint.StartsWith("Red."), destinationFilterDescription: "To Red", gateway: null, iface: "Red"); staticRouting.AddRoute( (iface, destination) => destination.Endpoint.StartsWith("Blue."), "To Blue", null, "Blue"); staticRouting.AddRoute( (iface, destination) => destination.Endpoint.StartsWith("Green."), "To Green", null, "Green"); #endregion var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
public void RouterSide() { #region wormhole-to-router-router var routerConfig = new RouterConfiguration("SiteA"); routerConfig.AddInterface <MsmqTransport>("Endpoints", tx => { }); routerConfig.AddInterface <AzureStorageQueuesTransport>("Tunnel", tx => { }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddRoute((iface, dest) => iface == "Endpoints", "From the local site", "SiteB", "Tunnel"); staticRouting.AddRoute((iface, dest) => iface == "Tunnel", "From the remote site", null, "Endpoints"); var router = Router.Create(routerConfig); #endregion }
static async Task Main() { Console.Title = "Router"; #region RouterConfig var routerConfig = new RouterConfiguration("DomainA-B-Router"); var domainAInterface = routerConfig.AddInterface <SqlServerTransport>("DomainA", t => { t.ConnectionString(ConnectionStrings.DomainA); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); var domainASqlSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(ConnectionStrings.Router), "DomainA-", new SqlDialect.MsSqlServer(), null); domainAInterface.EnableMessageDrivenPublishSubscribe(domainASqlSubscriptionStorage); var domainBInterface = routerConfig.AddInterface <SqlServerTransport>("DomainB", t => { t.ConnectionString(ConnectionStrings.DomainB); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); var domainBSqlSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(ConnectionStrings.Router), "DomainB-", new SqlDialect.MsSqlServer(), null); domainBInterface.EnableMessageDrivenPublishSubscribe(domainBSqlSubscriptionStorage); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("DomainA", "DomainB"); staticRouting.AddForwardRoute("DomainB", "DomainA"); routerConfig.AutoCreateQueues(); #endregion SqlHelper.EnsureDatabaseExists(ConnectionStrings.DomainA); SqlHelper.EnsureDatabaseExists(ConnectionStrings.DomainB); SqlHelper.EnsureDatabaseExists(ConnectionStrings.Router); domainASqlSubscriptionStorage.Install().GetAwaiter().GetResult(); domainBSqlSubscriptionStorage.Install().GetAwaiter().GetResult(); var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
void ConfigureRouter(Context c, RouterConfiguration cfg) { cfg.AddInterface <TestTransport>("Left", t => t.BrokerAlpha()).EnableMessageDrivenPublishSubscribe(subscriptionStorage); var leftIface = cfg.AddInterface <AzureServiceBusTransport>("Right", t => { var connString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString"); t.ConnectionString(connString); var topology = t.UseEndpointOrientedTopology(); topology.EnableMigrationToForwardingTopology(); topology.RegisterPublisher(typeof(MyAsbEvent), Conventions.EndpointNamingConvention(typeof(Publisher))); }); leftIface.LimitMessageProcessingConcurrencyTo(1); //To ensure when tracer arrives the subscribe request has already been processed.; cfg.AddRule(_ => new SuppressTransactionScopeRule()); cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right"); }
public void SimpleRouter() { #region bridge-to-router-simple-router var routerConfig = new RouterConfiguration("MyRouter"); routerConfig.AddInterface <MsmqTransport>("Left", extensions => { }); routerConfig.AddInterface <RabbitMQTransport>("Right", extensions => extensions.ConnectionString("host=localhost")); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("Left", "Right"); staticRouting.AddForwardRoute("Right", "Left"); var router = Router.Create(routerConfig); #endregion }
public void ThreeWayRouter() { #region bridge-to-router-three-way-router var routerConfig = new RouterConfiguration("MyRouter"); routerConfig.AddInterface <RabbitMQTransport>("A", tx => tx.ConnectionString("host=a")); routerConfig.AddInterface <RabbitMQTransport>("B", tx => tx.ConnectionString("host=b")); routerConfig.AddInterface <RabbitMQTransport>("C", tx => tx.ConnectionString("host=c")); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddRoute((iface, dest) => dest.Endpoint == "MyEndpoint", "To MyEndpoint", null, "A"); staticRouting.AddRoute((iface, dest) => dest.Endpoint == "OtherEndpoint", "To OtherEndpoint", null, "C"); var router = Router.Create(routerConfig); #endregion }
RouterConfiguration PrepareRouterConfiguration(string routerEndpointName, string mainEndpointName, string mainEndpointAddress, Action <TransportExtensions <TOld> > customizeOldTransport, Action <TransportExtensions <TNew> > customizeNewTransport) { var cfg = new RouterConfiguration(routerEndpointName); var newInterface = cfg.AddInterface("New", customizeNewTransport); newInterface.DisableNativePubSub(); //Forward unmodified subscribe messages from migrated subscriber newInterface.AddRule(c => new ForwardSubscribeRule()); //Forward published events from shadow interface to migrated subscriber newInterface.AddRule(c => new ForwardPublishRule(mainEndpointAddress)); var shadowInterface = cfg.AddInterface("Shadow", customizeOldTransport); shadowInterface.DisableMessageDrivenPublishSubscribe(); //Hook up to old Publisher's queue shadowInterface.OverrideEndpointName(mainEndpointName); //Forward subscribe messages shadowInterface.AddRule(c => new ShadowForwardSubscribeRule(c.Endpoint.TransportAddress, c.Endpoint.EndpointName)); //Forward events published by migrated publisher shadowInterface.AddRule(c => new ForwardPublishByDestinationAddressRule()); //Forward subscribes messages from shadow interface to migrated publisher shadowInterface.AddRule(c => new ShadowSubscribeDestinationRule(mainEndpointName)); //Forward sends from shadow interface to migrated receiver shadowInterface.AddRule(c => new ShadowSendDestinationRule(mainEndpointName)); //Removes the destination header shadowInterface.AddRule(_ => new ForwardSendRule()); var staticRouting = cfg.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("New", "Shadow"); staticRouting.AddForwardRoute("Shadow", "New"); cfg.AutoCreateQueues(null); return(cfg); }
static async Task Start() { var sqlConnectionString = SettingsReader <string> .Read("SqlConnectionString", "data source=(local); initial catalog=loadtest; integrated security=true"); var rabbitConnectionString = SettingsReader <string> .Read("RabbitConnectionString", "host=localhost"); var epochSize = SettingsReader <int> .Read("EpochSize", 10000); var routerConfig = new RouterConfiguration("Sender.Router"); routerConfig.AutoCreateQueues(); var deduplicationConfig = routerConfig.ConfigureDeduplication(); #pragma warning disable 618 deduplicationConfig.EnableInstaller(true); #pragma warning restore 618 var linkInterface = routerConfig.AddInterface <RabbitMQTransport>("Rabbit", t => { t.ConnectionString(rabbitConnectionString); t.UseConventionalRoutingTopology(); }); var sqlInterface = routerConfig.AddInterface <SqlServerTransport>("SQL", t => { t.ConnectionString(sqlConnectionString); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); sqlInterface.EnableMessageDrivenPublishSubscribe(new SqlSubscriptionStorage(() => new SqlConnection(sqlConnectionString), "SenderRouter", new SqlDialect.MsSqlServer(), null)); sqlInterface.EnableDeduplication(linkInterface.Name, "Receiver.Router", () => new SqlConnection(sqlConnectionString), epochSize); var routingProtocol = routerConfig.UseStaticRoutingProtocol(); routingProtocol.AddForwardRoute("SQL", "Rabbit", "Receiver.Router"); routerConfig.AddRule(_ => new RandomDuplicator()); var router = Router.Create(routerConfig); await router.Start(); Console.WriteLine("Press <enter> to exit."); Console.ReadLine(); await router.Stop(); }
private static void RouteFromAzureToAzure(IConfiguration config, RouterConfiguration routerConfig, RouteTable staticRouting) { var connectionStringA = config.GetConnectionString("NServiceBus:AzureServiceBusA"); var azureServiceBusAInterface = routerConfig.AddInterface <AzureServiceBusTransport>("AzureServiceBusA", t => { t.ConnectionString(connectionStringA); t.Transactions(TransportTransactionMode.ReceiveOnly); }); var connectionStringB = config.GetConnectionString("NServiceBus:AzureServiceBusB"); var azureServiceBusBInterface = routerConfig.AddInterface <AzureServiceBusTransport>("AzureServiceBusB", t => { t.ConnectionString(connectionStringB); t.Transactions(TransportTransactionMode.ReceiveOnly); }); staticRouting.AddForwardRoute("AzureServiceBusA", "AzureServiceBusB"); staticRouting.AddForwardRoute("AzureServiceBusB", "AzureServiceBusA"); }
static async Task Main() { Console.Title = "Samples.SqlServer.MultiInstanceBridge"; SqlHelper.EnsureDatabaseExists(SenderConnectionString); SqlHelper.EnsureDatabaseExists(ReceiverConnectionString); SqlHelper.EnsureDatabaseExists(BridgeConnectionString); #region BridgeConfiguration var storage = new SqlSubscriptionStorage( connectionBuilder: () => new SqlConnection(BridgeConnectionString), tablePrefix: "", sqlDialect: new SqlDialect.MsSqlServer(), cacheFor: null); //Ensures all required schema objects are created await storage.Install().ConfigureAwait(false); var bridgeConfig = new RouterConfiguration("Bridge"); var senderInterface = bridgeConfig.AddInterface <SqlServerTransport>("Bridge-Sender", t => t.ConnectionString(SenderConnectionString)); var receiverInterface = bridgeConfig.AddInterface <SqlServerTransport>("Bridge-Receiver", t => t.ConnectionString(ReceiverConnectionString)); senderInterface.UseSubscriptionPersistence(storage); receiverInterface.UseSubscriptionPersistence(storage); bridgeConfig.AutoCreateQueues(); var routeTable = bridgeConfig.UseStaticRoutingProtocol(); routeTable.AddForwardRoute("Bridge-Sender", "Bridge-Receiver"); routeTable.AddForwardRoute("Bridge-Receiver", "Bridge-Sender"); #endregion var bridge = Router.Create(bridgeConfig); await bridge.Start().ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await bridge.Stop().ConfigureAwait(false); }
public async Task TwoWayRouterConfig() { #region two-way-router var routerConfig = new RouterConfiguration("MyRouter"); routerConfig.AddInterface <MsmqTransport>("Msmq", customization: transportExtensions => { }); routerConfig.AddInterface <MsmqTransport>("Rabbit", customization: transportExtensions => { transportExtensions.ConnectionString("host=localhost"); }); #endregion #region simple-routing var staticRouting = routerConfig.UseStaticRoutingProtocol(); //Forward all messages from MSMQ to RabbitMQ staticRouting.AddForwardRoute( incomingInterface: "Msmq", outgoingInterface: "Rabbit"); //Forward all messages from RabbitMQ to MSMQ staticRouting.AddForwardRoute( incomingInterface: "Rabbit", outgoingInterface: "Msmq"); #endregion #region lifecycle var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); await router.Stop().ConfigureAwait(false); #endregion }
public void RouterSide() { #region upgrade-router-config var routerConfig = new RouterConfiguration("Gateway.SiteA"); routerConfig.AddInterface <MsmqTransport>("Local", tx => { }); routerConfig.AddInterface <AzureStorageQueuesTransport>("Tunnel", tx => { }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddRoute((iface, dest) => iface == "Local", "From the local site", "Gateway.SiteB", "Tunnel"); staticRouting.AddRoute((iface, dest) => iface == "Tunnel", "From the remote site", null, "Local"); var router = Router.Create(routerConfig); #endregion }
static async Task Main() { Console.Title = "Samples.Router.MixedTransports.Router"; #region RouterConfig var routerConfig = new RouterConfiguration("Samples.Router.MixedTransports.Router"); var msmqInterface = routerConfig.AddInterface <SqlServerTransport>("MSMQ", t => { t.ConnectionString("Data Source=(localdb)\\MSSQLLocalDB;Integrated Security=True;Initial Catalog=NserviceBusStorage;Application Name=NServiceBus;"); }); msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); var rabbitMQInterface = routerConfig.AddInterface <RabbitMQTransport>("RabbitMQ", t => { t.ConnectionString("host=localhost"); t.UseConventionalRoutingTopology(); }); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("MSMQ", "RabbitMQ"); staticRouting.AddForwardRoute("RabbitMQ", "MSMQ"); routerConfig.AutoCreateQueues(); #endregion var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
static async Task Main() { Console.Title = "MSMQ_SQL_Router"; var routerConfig = new RouterConfiguration("MSMQ_SQL_Router"); var msmqInterface = routerConfig.AddInterface <MsmqTransport>("MSMQ", t => { }); msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); var cs = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=NSB_MSMQ_SQL_Router;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; var sqlServerInterface = routerConfig.AddInterface <SqlServerTransport>("SqlServer", t => { t.ConnectionString(cs); }); sqlServerInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage()); var staticRouting = routerConfig.UseStaticRoutingProtocol(); staticRouting.AddForwardRoute("MSMQ", "SqlServer"); staticRouting.AddForwardRoute("SqlServer", "MSMQ"); routerConfig.AutoCreateQueues(); var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
static async Task Start() { Metric.Config.WithReporting(r => { r.WithCSVReports(".", TimeSpan.FromSeconds(5)); }); var senderConfig = new EndpointConfiguration("Sender"); senderConfig.UseSerialization <NewtonsoftSerializer>(); senderConfig.SendFailedMessagesTo("error"); senderConfig.EnableInstallers(); senderConfig.UsePersistence <InMemoryPersistence>(); senderConfig.RegisterComponents(c => c.RegisterSingleton(new LoadGenerator(GenerateMessages, 5000, 10000))); var senderTransport = senderConfig.UseTransport <SqlServerTransport>(); senderTransport.ConnectionString(ConnectionString); senderTransport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); var senderRouterConnector = senderTransport.Routing().ConnectToRouter("Router"); senderRouterConnector.RouteToEndpoint(typeof(MyMessage), "Receiver"); senderTransport.Routing().RouteToEndpoint(typeof(MyMessage), "Receiver"); var routerConfig = new RouterConfiguration("Router"); routerConfig.AutoCreateQueues(); routerConfig.AddInterface <SqlServerTransport>("SQL", t => { t.ConnectionString(ConnectionString); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); routerConfig.AddInterface <RabbitMQTransport>("Rabbit", t => { t.ConnectionString("host=localhost"); t.UseConventionalRoutingTopology(); }); var routingProtocol = routerConfig.UseStaticRoutingProtocol(); routingProtocol.AddForwardRoute("SQL", "Rabbit"); routingProtocol.AddForwardRoute("Rabbit", "SQL"); routerConfig.ConfigureDeduplication(d => { d.EpochSize(1000); d.ConnectionFactory(() => new SqlConnection(ConnectionString)); d.AddOutgoingLink("Rabbit", "Receiver"); }); var receiverConfig = new EndpointConfiguration("Receiver"); receiverConfig.UseSerialization <NewtonsoftSerializer>(); receiverConfig.SendFailedMessagesTo("error"); receiverConfig.EnableInstallers(); receiverConfig.UsePersistence <InMemoryPersistence>(); receiverConfig.EnableFeature <ReporterFeature>(); //var receiverTransport = receiverConfig.UseTransport<RabbitMQTransport>(); //receiverTransport.ConnectionString("host=localhost"); //receiverTransport.UseConventionalRoutingTopology(); var receiverTransport = receiverConfig.UseTransport <SqlServerTransport>(); receiverTransport.ConnectionString(ConnectionString); receiverTransport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); //var receiverRouterConnector = receiverTransport.Routing().ConnectToRouter("Router"); //receiverRouterConnector.RouteToEndpoint(typeof(ProcessingReport), "Sender"); receiverTransport.Routing().RouteToEndpoint(typeof(ProcessingReport), "Sender"); //var router = Router.Create(routerConfig); //await router.Start(); sender = await Endpoint.Start(senderConfig); var receiver = await Endpoint.Start(receiverConfig); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await sender.Stop(); await receiver.Stop(); //await router.Stop(); }
public static async Task <RouterConfiguration> Prepare(string sqlConnectionString, string routerName) { var otherRouters = allRouters.Except(new[] { routerName }).ToArray(); var sqlSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(sqlConnectionString), $"{routerName}-SQL", new SqlDialect.MsSqlServer(), null); var backplaneSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(sqlConnectionString), $"{routerName}-Backplane", new SqlDialect.MsSqlServer(), null); #region RouterConfig var routerConfig = new RouterConfiguration(routerName); var sqlInterface = routerConfig.AddInterface <SqlServerTransport>("SQL", t => { t.ConnectionString(sqlConnectionString); t.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }); sqlInterface.EnableMessageDrivenPublishSubscribe(sqlSubscriptionStorage); var backplaneInterface = routerConfig.AddInterface <RabbitMQTransport>("Backplane", t => { t.ConnectionString("host=localhost"); t.UseConventionalRoutingTopology(); }); backplaneInterface.EnableMessageDrivenPublishSubscribe(backplaneSubscriptionStorage); backplaneInterface.DisableNativePubSub(); routerConfig.AutoCreateQueues(); #pragma warning disable 618 routerConfig.ConfigureDeduplication().EnableInstaller(true); #pragma warning restore 618 #endregion if (enableRandomDuplication) { //Randomly duplicate messages sent to the backplane routerConfig.AddRule(c => new RandomDuplicator(c.Endpoint), c => c.InterfaceName == "Backplane"); } if (enableDeduplication) { #region Deduplication foreach (var router in otherRouters) { sqlInterface.EnableDeduplication("Backplane", router, () => new SqlConnection(sqlConnectionString), 10); } #endregion } #region RoutingTopology var staticRouting = routerConfig.UseStaticRoutingProtocol(); //Forward messages coming from local SQL based on the endpoint name prefix foreach (var router in otherRouters) { staticRouting.AddRoute( destinationFilter: (@interface, dest) => { return(@interface == "SQL" && dest.Endpoint != null && dest.Endpoint.StartsWith(router)); }, destinationFilterDescription: $"To {router}", gateway: router, iface: "Backplane"); } //Forward messages coming from backplane to local SQL staticRouting.AddRoute((@interface, dest) => @interface == "Backplane", "To local", null, "SQL"); #endregion await sqlSubscriptionStorage.Install().ConfigureAwait(false); await backplaneSubscriptionStorage.Install().ConfigureAwait(false); return(routerConfig); }