public T GetConfiguration <T>() where T : class, new() { var mappingByType = new MessageEndpointMapping { Endpoint = "Type", TypeFullName = "NServiceBus.Unicast.Tests.Messages.MessageA", AssemblyName = "NServiceBus.Core.Tests" }; var mappingByNamespace = new MessageEndpointMapping { Endpoint = "Namespace", Namespace = "NServiceBus.Unicast.Tests.Messages", AssemblyName = "NServiceBus.Core.Tests" }; var mappingByAssembly = new MessageEndpointMapping { Endpoint = "Assembly", AssemblyName = "NServiceBus.Core.Tests" }; var mappingByMessagesWithType = new MessageEndpointMapping { Endpoint = "MessagesWithType", Messages = "NServiceBus.Unicast.Tests.Messages.MessageE, NServiceBus.Core.Tests" }; var mappings = new MessageEndpointMappingCollection { mappingByNamespace, mappingByType, mappingByAssembly, mappingByMessagesWithType }; var type = typeof(T); if (type == typeof(MessageForwardingInCaseOfFaultConfig)) { return new MessageForwardingInCaseOfFaultConfig { ErrorQueue = "error" } }
public UnicastBusConfig GetConfiguration() { var mappingByType = new MessageEndpointMapping { Endpoint = "Type", TypeFullName = "NServiceBus.Unicast.Tests.Messages.MessageA", AssemblyName = "NServiceBus.Unicast.Tests.Messages" }; var mappingByNamespace = new MessageEndpointMapping { Endpoint = "Namespace", Namespace = "NServiceBus.Unicast.Tests.Messages", AssemblyName = "NServiceBus.Unicast.Tests.Messages" }; var mappingByAssembly = new MessageEndpointMapping { Endpoint = "Assembly", AssemblyName = "NServiceBus.Unicast.Tests.Messages" }; var mappingByMessagesWithType = new MessageEndpointMapping { Endpoint = "MessagesWithType", Messages = "NServiceBus.Unicast.Tests.Messages.MessageE, NServiceBus.Unicast.Tests" }; var mappingByMessagesWithAssemblyName = new MessageEndpointMapping { Endpoint = "MessagesWithAssembly", Messages = "NServiceBus.Unicast.Tests" }; var mappings = new MessageEndpointMappingCollection { mappingByNamespace, mappingByMessagesWithAssemblyName, mappingByType, mappingByAssembly, mappingByMessagesWithType }; return(new UnicastBusConfig { MessageEndpointMappings = mappings }); }
static UnicastRoutingTable ApplyMappings(MessageEndpointMappingCollection mappings) { var routeTable = new UnicastRoutingTable(); mappings.Apply(new Publishers(), routeTable, x => x, new Conventions()); return(routeTable); }
public void WhenMultipleRoutesExist_ShouldUseMostSpecificOnes() { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, TypeFullName = typeof(SomeMessageType).FullName, Endpoint = "type_destination" }, new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, Namespace = nameof(MessageNamespaceA), Endpoint = "namespace_destination" }, new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, Endpoint = "assembly_destination" } }; var routingTable = ApplyMappings(mappings); var someMessageRoute = routingTable.GetRouteFor(typeof(SomeMessageType)); var yetAnotherRoute = routingTable.GetRouteFor(typeof(YetAnotherMessageType)); var otherMessageRoute = routingTable.GetRouteFor(typeof(OtherMessageType)); Assert.AreEqual("type_destination", someMessageRoute.PhysicalAddress); Assert.AreEqual("namespace_destination", yetAnotherRoute.PhysicalAddress); Assert.AreEqual("assembly_destination", otherMessageRoute.PhysicalAddress); }
public T GetConfiguration <T>() where T : class, new() { if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig)) { return(new MessageForwardingInCaseOfFaultConfig { ErrorQueue = "error" } as T); } if (typeof(T) == typeof(UnicastBusConfig)) { var endpointMappingsCollection = new MessageEndpointMappingCollection(); foreach (var em in messageMappings) { endpointMappingsCollection.Add(em); } return(new UnicastBusConfig { MessageEndpointMappings = endpointMappingsCollection, } as T); } if (typeof(T) == typeof(TransportConfig)) { return(new TransportConfig { MaxRetries = 0, } as T); } if (typeof(T) == typeof(AuditConfig)) { return(new AuditConfig { QueueName = "audit" } as T); } if (typeof(T) == typeof(SecondLevelRetriesConfig)) { return(new SecondLevelRetriesConfig { NumberOfRetries = 0 } as T); } // leaving the rest of the configuration as is: return(ConfigurationManager.GetSection(typeof(T).Name) as T); }
public UnicastBusConfig GetConfiguration() { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(ProduceChocolateBar).FullName, Endpoint = "Chocolate.Facility" }, }; return(new UnicastBusConfig { MessageEndpointMappings = mappings }); }
public void WhenRoutingMessageTypeToEndpoint_ShouldConfigureMessageTypeInRoutingTable() { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, TypeFullName = typeof(SomeMessageType).FullName, Endpoint = "destination" } }; var routingTable = ApplyMappings(mappings); var route = routingTable.GetRouteFor(typeof(SomeMessageType)); Assert.That(route, Is.Not.Null); }
public UnicastBusConfig GetConfiguration() { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(RoastBeans).FullName, Endpoint = "Chocolate.Roasting" }, new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(BeansRoasted).FullName, Endpoint = "Chocolate.Roasting" }, new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(GrindBeans).FullName, Endpoint = "Chocolate.Grinding" }, new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(BeansGround).FullName, Endpoint = "Chocolate.Grinding" }, new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(BlendChocolate).FullName, Endpoint = "Chocolate.Blending" }, new MessageEndpointMapping { AssemblyName = "Messages", TypeFullName = typeof(ChocolateBlended).FullName, Endpoint = "Chocolate.Blending" } }; return(new UnicastBusConfig { MessageEndpointMappings = mappings }); }
MessageEndpointMappingCollection GenerateMappings() { var mappings = new MessageEndpointMappingCollection(); foreach (var templateMapping in configuration.EndpointMappings) { var messageType = templateMapping.Key; var endpoint = templateMapping.Value; mappings.Add(new MessageEndpointMapping { AssemblyName = messageType.Assembly.FullName, TypeFullName = messageType.FullName, Endpoint = routingTable[endpoint] }); } return(mappings); }
public UnicastBusConfig GetConfiguration() { var messageEndpointMappingCollection = new MessageEndpointMappingCollection(); foreach (var endpointName in EndpointNames.All) { var assemblyName = endpointName.Replace("WireCompat", ""); var mapping = new MessageEndpointMapping { Messages = $"{assemblyName}.Messages", TypeFullName = $"{assemblyName}.Messages.MyEvent", Endpoint = endpointName }; messageEndpointMappingCollection.Add(mapping); } return(new UnicastBusConfig { MessageEndpointMappings = messageEndpointMappingCollection }); }
public void WhenRoutingAssemblyWithNamespaceToEndpoint_ShouldOnlyConfigureMessagesWithinThatNamespace() { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, Namespace = nameof(MessageNamespaceA), Endpoint = "destination" }, }; var routingTable = ApplyMappings(mappings); 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 mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { AssemblyName = Assembly.GetExecutingAssembly().FullName, Endpoint = "destination" } }; var routingTable = ApplyMappings(mappings); 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 T GetConfiguration <T>() where T : class, new() { // the part you are overriding if (typeof(T) == typeof(UnicastBusConfig)) { var endpointMappint = new MessageEndpointMappingCollection(); ICommandRoutingConfigurationRepository rep = new CommandRoutingConfigurationRepository(); var routingInfo = rep.GetRoutingInfo(); var messagesAlreadyInConfiguration = new List <string>(); foreach (var ep in routingInfo) { if (messagesAlreadyInConfiguration.Contains(ep.MessageType)) { continue; } endpointMappint.Add(new MessageEndpointMapping() { AssemblyName = ep.MessageAssembly, TypeFullName = ep.MessageType, Endpoint = ep.DestinationEndpoint + "@" + ep.DestinationMachine }); messagesAlreadyInConfiguration.Add(ep.MessageType); } return(new UnicastBusConfig { MessageEndpointMappings = endpointMappint } as T); } // leaving the rest of the configuration as is: return(ConfigurationManager.GetSection(typeof(T).Name) as T); }
public T GetConfiguration <T>() where T : class { { if (typeof(T) == typeof(MsmqTransportConfig)) { return(new MsmqTransportConfig { ErrorQueue = "Tp.Error", InputQueue = ObjectFactory.GetInstance <IPluginSettings>().PluginInputQueue, MaxRetries = 1, NumberOfWorkerThreads = 1 } as T); } if (typeof(T) == typeof(UnicastBusConfig)) { var mappings = new MessageEndpointMappingCollection { new MessageEndpointMapping { Messages = "Tp.Integration.Messages", Endpoint = TargetProcessInputQueue } }; foreach (var mapping in GetExtraMappings()) { mappings.Add(mapping); } return(new UnicastBusConfig { MessageEndpointMappings = mappings } as T); } return(null); } }