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); }
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 }
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 }
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 }
private IDictionary <string, object> GetInstances(RouterConfiguration router, CompilerResults result) { IDictionary <string, object> map = new Dictionary <string, object>(); if (router != null && router.Routes != null && router.Routes.Count > 0) { string className = string.Format("{0}.{1}", NAMESPACE_NAME, CLASS_NAME); Type type = result.CompiledAssembly.GetType(className); if (type != null) { object instance = type.GetConstructor(Type.EmptyTypes).Invoke(null); if (instance != null) { foreach (RouteConfiguration item in router.Routes) { if (item != null && !string.IsNullOrWhiteSpace(item.Name)) { FieldInfo fi = type.GetField(item.Name); object obj = fi.GetValue(instance); map[item.Name] = obj; } } } } } return(map); }
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"); }
private static async Task Main(string[] args) { var config = ConfigurationCreator.GetConfiguration(); var routerName = config["NServiceBus:EndpointName"]; Console.Title = routerName; var routerConfig = new RouterConfiguration(routerName); var staticRouting = routerConfig.UseStaticRoutingProtocol(); RouteFromAzureToAzure(config, routerConfig, staticRouting); // RouteFromLearningToAzure(routerConfig, config, staticRouting); // RouteFromAzureToLearning(routerConfig, config, staticRouting); routerConfig.AutoCreateQueues(); routerConfig.PoisonQueueName = $"{routerName}-poison"; var router = Router.Create(routerConfig); await router.Start().ConfigureAwait(false); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); await router.Stop().ConfigureAwait(false); }
private string BuildClassSource(RouterConfiguration router) { string classSource = null; if (router != null) { string property = string.Empty; if (router.Routes != null && router.Routes.Count > 0) { List <string> propertyList = new List <string>(); foreach (RouteConfiguration item in router.Routes) { property = BuildPropertyString(item); if (!string.IsNullOrWhiteSpace(property)) { propertyList.Add(property); } } property = string.Join("\r\n", propertyList.ToArray()); } classSource = ClassReflectionStringFormat.Replace("#namespace#", NAMESPACE_NAME).Replace("#className#", CLASS_NAME).Replace("#property#", property); } return(classSource); }
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() { 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); }
private string[] GetReferenceLibs(RouterConfiguration router) { string[] result = null; if (router.ReferenceLibs == null || router.ReferenceLibs.Count == 0) { result = new string[0]; } else { List <string> list = new List <string>(router.ReferenceLibs.Count * 2); string path = null; for (int i = 0; i < router.ReferenceLibs.Count; i++) { if (router.ReferenceLibs[i] == null || string.IsNullOrWhiteSpace(router.ReferenceLibs[i].Path)) { continue; } path = router.ReferenceLibs[i].Path; path = Utility.ConvertToFullPath(path, router.BaseDirectory); list.Add(path); } result = list.ToArray(); } return(result); }
/// <summary> /// 动态创建路由器的参数实例 /// </summary> /// <param name="router"></param> /// <returns>key:route name , value:parameter instance</returns> internal IDictionary <string, object> CreateRouteParametersInstance(RouterConfiguration router) { if (router == null) { throw new ArgumentNullException("router"); } string[] referenceLibs = GetReferenceLibs(router); string classSources = BuildClassSource(router); DynamicCreateDLL builder = new DynamicCreateDLL(); CompilerResults result = builder.Create(new string[] { classSources }, referenceLibs); IDictionary <string, object> map = GetInstances(router, result); ThreadPool.QueueUserWorkItem(new WaitCallback((obj) => { try { File.Delete(builder.OutputAssemblyName); } catch { } })); return(map); }
public void Configure(RouterConfiguration routerConfig) { routerConfig.AddRule(c => new ForwardPublishNativeRule(), c => EnableNativePubSub(c)); routerConfig.AddRule(c => new ForwardPublishNullRule(), c => c.Settings.HasExplicitValue("NativePubSubDisabled")); routerConfig.AddRule(c => new ForwardSubscribeNativeRule(c.Endpoint.SubscriptionManager), c => EnableNativePubSub(c) && !SendOnly(c)); routerConfig.AddRule(c => new ForwardUnsubscribeNativeRule(c.Endpoint.SubscriptionManager), c => EnableNativePubSub(c) && !SendOnly(c)); }
public void Configure(RouterConfiguration routerConfig) { routerConfig.AddRule(c => new ForwardPublishStorageDrivenRule(GetSubscriptionStorage(c), c.DistributionPolicy), c => IsEnabled(c)); routerConfig.AddRule(c => new ForwardPublishNullRule(), c => IsExplicitlyDisabled(c)); routerConfig.AddRule(c => new ForwardSubscribeMessageDrivenRule(c.Endpoint.TransportAddress, c.Endpoint.EndpointName), c => IsEnabled(c) && !SendOnly(c)); routerConfig.AddRule(c => new ForwardUnsubscribeMessageDrivenRule(c.Endpoint.TransportAddress, c.Endpoint.EndpointName), c => IsEnabled(c) && !SendOnly(c)); routerConfig.AddRule(c => new StorageDrivenSubscriptionRule(GetSubscriptionStorage(c)), c => IsEnabled(c) && !SendOnly(c)); }
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"); }
private void SetCurrentConfiguration(RouterConfiguration originalConfiguration) { CurrentConfiguration = new RouterConfiguration(OriginalConfiguration); //WpfDispatcher? //RaisePropertyChanged(nameof(IP)); //RaisePropertyChanged(nameof(Port)); //RaisePropertyChanged(nameof(Server)); //RaisePropertyChanged(nameof(Gateway)); }
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); } }
public static IScenarioWithEndpointBehavior <TContext> WithRouter <TContext>(this IScenarioWithEndpointBehavior <TContext> scenario, string name, Action <RouterConfiguration> configCallback) where TContext : ScenarioContext { return(scenario.WithComponent(new RouterComponent(s => { var cfg = new RouterConfiguration(name); configCallback(cfg); return cfg; }))); }
/// <summary> /// 用于配置Router /// </summary> /// <param name="routeConfigureElement">配置文件内容</param> public static void Configure(XmlElement routeConfigureElement) { lock (SyncObject) { m_Router = new RouterConfiguration(routeConfigureElement); //如果采用element配置,则说明用户自行监控配置文件,无需重复监测,释放文件监控 if (m_Watcher != null) { m_Watcher.Dispose(); m_Watcher = null; } } }
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 }
public async Task<RouterConfiguration> GetConfiguration(CancellationToken cancellationToken) { string clusterName = null; var result = await _conulClient.KV.Get($"requestrouter/servers/{await _conulClient.Agent.GetNodeName(cancellationToken)}/cluster".ToLower(), cancellationToken); if (result.StatusCode == HttpStatusCode.OK) { clusterName = Encoding.UTF8.GetString(result.Response.Value); } var configPathBuilder = new StringBuilder("requestrouter/"); if (!string.IsNullOrWhiteSpace(clusterName)) { configPathBuilder.Append($"cluster/{clusterName}/"); } configPathBuilder.Append("config"); QueryResult<KVPair> configResult = null; configResult = await _conulClient.KV.Get(configPathBuilder.ToString().ToLower(), cancellationToken); if (configResult.StatusCode != HttpStatusCode.OK) throw new InvalidOperationException($"Configuration not found at config path: {configPathBuilder}"); var modificationToken = configResult.Response.ModifyIndex; if (_modificationToken == modificationToken) return _configuration; lock (_lockObject) { configResult = _conulClient.KV.Get(configPathBuilder.ToString().ToLower(), cancellationToken).GetAwaiter().GetResult(); if (configResult.StatusCode != HttpStatusCode.OK) throw new InvalidOperationException( $"Configuration not found at config path: {configPathBuilder}"); modificationToken = configResult.Response.ModifyIndex; if (_modificationToken == modificationToken) return _configuration; using (var memoryStream = new MemoryStream(configResult.Response.Value)) using (var streamReader = new StreamReader(memoryStream, Encoding.UTF8)) using (var jsonReader = new JsonTextReader(streamReader)) { Logger.Info( _modificationToken != 0 ? $"Configuration seems to have changed, modification token: {_modificationToken} does not match {modificationToken}, parsing new config." : $"Reading configuration, Modification token: {modificationToken}"); var config = new RouterConfiguration(); config.Config.AddRange(_serializer.Deserialize<ConfigContainer[]>(jsonReader)); _configuration = config; _modificationToken = modificationToken; Logger.Info( $"Parsed new config with {config.Config.Count} block{(config.Config.Count == 1 ? "" : "s")}"); return config; } } }
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); }
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(); }
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 }
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 }
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"); }
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); }
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"); }