public void When_multiple_dynamic_instances_for_logical_endpoints_should_round_robin()
        {
            var sales        = "Sales";
            var routingTable = new UnicastRoutingTable();

            routingTable.AddOrReplaceRoutes("A", new List <RouteTableEntry>
            {
                new RouteTableEntry(typeof(MyMessage), UnicastRoute.CreateFromEndpointName(sales))
            });

            var endpointInstances = new EndpointInstances();

            endpointInstances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance(sales, "1"),
                new EndpointInstance(sales, "2"),
            });

            var context = CreateContext(new SendOptions(), new MyMessage());

            var router = CreateRouter(routingTable: routingTable, instances: endpointInstances);
            var route1 = router.Route(context);
            var route2 = router.Route(context);
            var route3 = router.Route(context);

            Assert.AreEqual("Sales-1", ExtractDestination(route1));
            Assert.AreEqual("Sales-2", ExtractDestination(route2));
            Assert.AreEqual("Sales-1", ExtractDestination(route3));
        }
        public void When_multiple_dynamic_instances_for_local_endpoint_should_round_robin()
        {
            var endpointInstances = new EndpointInstances();

            endpointInstances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance("Endpoint", "1"),
                new EndpointInstance("Endpoint", "2"),
            });

            var options = new SendOptions();

            options.RouteToThisEndpoint();

            var context = CreateContext(options, new MyMessage());

            var router = CreateRouter(instances: endpointInstances);

            var route1 = router.Route(context);
            var route2 = router.Route(context);
            var route3 = router.Route(context);

            Assert.AreEqual("Endpoint-1", ExtractDestination(route1));
            Assert.AreEqual("Endpoint-2", ExtractDestination(route2));
            Assert.AreEqual("Endpoint-1", ExtractDestination(route3));
        }
        public void When_routing_to_specific_instance_should_select_appropriate_instance()
        {
            var table     = new UnicastRoutingTable();
            var instances = new EndpointInstances();

            table.AddOrReplaceRoutes("A", new List <RouteTableEntry>
            {
                new RouteTableEntry(typeof(MyMessage), UnicastRoute.CreateFromEndpointName("Endpoint"))
            });
            instances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance("Endpoint", "1"),
                new EndpointInstance("Endpoint", "2"),
                new EndpointInstance("Endpoint", "3")
            });
            var router  = CreateRouter(routingTable: table, instances: instances);
            var options = new SendOptions();

            options.RouteToSpecificInstance("2");

            var context = CreateContext(options);

            var route = router.Route(context);

            Assert.AreEqual("Endpoint-2", ExtractDestination(route));
        }
Beispiel #4
0
 public TopicExchangeAddressManager(string topicExchangeName, EndpointInstances endpointInstances, Func <EndpointInstance, string> transportAddressTranslation, IDistributionPolicy distributionPolicy)
 {
     this.topicExchangeName           = topicExchangeName;
     this.endpointInstances           = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
     this.distributionPolicy          = distributionPolicy;
 }
Beispiel #5
0
 public PublishRoutingConnector(UnicastSubscriberTable routingTable, EndpointInstances endpointInstances, IDistributionPolicy distributionPolicy, Func <EndpointInstance, string> resolveTransportAddress)
 {
     this.routingTable            = routingTable;
     this.endpointInstances       = endpointInstances;
     this.distributionPolicy      = distributionPolicy;
     this.resolveTransportAddress = resolveTransportAddress;
 }
 public RoutingConfiguration(RuntimeTypeGenerator typeGenerator, EndpointInstances endpointInstances, ISubscriptionStorage subscriptionPersistence, RawDistributionPolicy distributionPolicy)
 {
     this.typeGenerator           = typeGenerator;
     this.endpointInstances       = endpointInstances;
     this.subscriptionPersistence = subscriptionPersistence;
     this.distributionPolicy      = distributionPolicy;
 }
 public UnicastRouter(BlueprintBasedRouteGenerator routeGenerator, EndpointInstances endpointInstances, IDistributionPolicy distributionPolicy, Func <EndpointInstance, string> resolveTransportAddress)
 {
     this.routeGenerator          = routeGenerator;
     this.endpointInstances       = endpointInstances;
     this.distributionPolicy      = distributionPolicy;
     this.resolveTransportAddress = resolveTransportAddress;
 }
Beispiel #8
0
    public Bridge(string leftName, string rightName, bool autoCreateQueues, string autoCreateQueuesIdentity, EndpointInstances endpointInstances, ISubscriptionStorage subscriptionStorage, IDistributionPolicy distributionPolicy, string poisonQueue, Action <TransportExtensions <TLeft> > leftCustomization, Action <TransportExtensions <TRight> > rightCustomization, int?maximumConcurrency)
    {
        this.endpointInstances   = endpointInstances;
        this.subscriptionStorage = subscriptionStorage;
        publishRouter            = new PublishRouter(subscriptionStorage, distributionPolicy);
        sendRouter  = new SendRouter(endpointInstances, distributionPolicy);
        replyRouter = new ReplyRouter();

        leftConfig = RawEndpointConfiguration.Create(leftName, (context, _) => Forward(context, rightStartable, rightSubscribeRouter), poisonQueue);
        var leftTransport = leftConfig.UseTransport <TLeft>();

        leftTransport.GetSettings().Set("errorQueue", poisonQueue);
        leftCustomization?.Invoke(leftTransport);
        if (autoCreateQueues)
        {
            leftConfig.AutoCreateQueue(autoCreateQueuesIdentity);
        }

        rightConfig = RawEndpointConfiguration.Create(rightName, (context, _) => Forward(context, leftStartable, leftSubscribeRouter), poisonQueue);
        var rightTransport = rightConfig.UseTransport <TRight>();

        rightTransport.GetSettings().Set("errorQueue", poisonQueue);
        rightCustomization?.Invoke(rightTransport);
        if (autoCreateQueues)
        {
            rightConfig.AutoCreateQueue(autoCreateQueuesIdentity);
        }

        if (maximumConcurrency.HasValue)
        {
            leftConfig.LimitMessageProcessingConcurrencyTo(1);
            rightConfig.LimitMessageProcessingConcurrencyTo(1);
        }
    }
        public void When_multiple_dynamic_instances_for_local_endpoint_and_instance_selected_should_not_round_robin()
        {
            var routingTable = new UnicastRoutingTable();

            routingTable.AddOrReplaceRoutes("A", new List <RouteTableEntry>
            {
                new RouteTableEntry(typeof(MyMessage), UnicastRoute.CreateFromEndpointName("Endpoint"))
            });

            var endpointInstances = new EndpointInstances();

            endpointInstances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance("Endpoint", "1"),
                new EndpointInstance("Endpoint", "2"),
            });

            var options = new SendOptions();

            options.RouteToSpecificInstance("2");

            var context = CreateContext(options, new MyMessage());

            var router = CreateRouter(routingTable: routingTable, instances: endpointInstances);
            var route1 = router.Route(context);
            var route2 = router.Route(context);
            var route3 = router.Route(context);

            Assert.AreEqual("Endpoint-2", ExtractDestination(route1));
            Assert.AreEqual("Endpoint-2", ExtractDestination(route2));
            Assert.AreEqual("Endpoint-2", ExtractDestination(route3));
        }
Beispiel #10
0
 public RoutingComponent(UnicastRoutingTable unicastRoutingTable, DistributionPolicy distributionPolicy, EndpointInstances endpointInstances, Publishers publishers)
 {
     UnicastRoutingTable = unicastRoutingTable;
     DistributionPolicy  = distributionPolicy;
     EndpointInstances   = endpointInstances;
     Publishers          = publishers;
 }
 public InstanceMappingFileMonitor(string filePath, TimeSpan checkInterval, IAsyncTimer timer, IInstanceMappingFileAccess fileAccess, EndpointInstances endpointInstances)
 {
     this.filePath = filePath;
     this.checkInterval = checkInterval;
     this.timer = timer;
     this.fileAccess = fileAccess;
     this.endpointInstances = endpointInstances;
 }
 public void Setup()
 {
     routingTable      = new UnicastRoutingTable();
     endpointInstances = new EndpointInstances();
     router            = new UnicastSendRouter(
         routingTable,
         endpointInstances,
         i => i.ToString());
 }
Beispiel #13
0
 public void Setup()
 {
     metadataRegistry    = new MessageMetadataRegistry(new Conventions());
     endpointInstances   = new EndpointInstances();
     subscriptionStorage = new FakeSubscriptionStorage();
     router = new UnicastPublishRouter(
         metadataRegistry,
         subscriptionStorage);
 }
 public RoutingInfoSubscriber(UnicastRoutingTable routingTable, EndpointInstances endpointInstances, IReadOnlyCollection <Type> messageTypesHandledByThisEndpoint, Publishers publishers, TimeSpan sweepPeriod, TimeSpan heartbeatTimeout)
 {
     this.routingTable      = routingTable;
     this.endpointInstances = endpointInstances;
     this.messageTypesHandledByThisEndpoint = messageTypesHandledByThisEndpoint;
     this.publishers       = publishers;
     this.sweepPeriod      = sweepPeriod;
     this.heartbeatTimeout = heartbeatTimeout;
 }
Beispiel #15
0
 public RuleCreationContext(string interfaceName, EndpointInstances endpointInstances, RawDistributionPolicy distributionPolicy, IRawEndpoint endpoint, RuntimeTypeGenerator typeGenerator, ReadOnlySettings settings)
 {
     InterfaceName      = interfaceName;
     EndpointInstances  = endpointInstances;
     DistributionPolicy = distributionPolicy;
     Endpoint           = endpoint;
     TypeGenerator      = typeGenerator;
     Settings           = settings;
 }
        public void Should_default_to_single_instance_when_not_configured()
        {
            var instances      = new EndpointInstances();
            var salesInstances = instances.FindInstances("Sales");

            var singleInstance = salesInstances.Single();

            Assert.IsNull(singleInstance.Discriminator);
            Assert.IsEmpty(singleInstance.Properties);
        }
 public void Setup()
 {
     metadataRegistry    = new MessageMetadataRegistry(_ => true);
     endpointInstances   = new EndpointInstances();
     subscriptionStorage = new FakeSubscriptionStorage();
     router = new UnicastPublishRouter(
         metadataRegistry,
         i => string.Empty,
         subscriptionStorage);
 }
        public void Should_return_instances_configured_by_static_route()
        {
            var instances = new EndpointInstances();
            var sales     = "Sales";

            instances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance(sales, "1"),
                new EndpointInstance(sales, "2")
            });

            var salesInstances = instances.FindInstances(sales);

            Assert.AreEqual(2, salesInstances.Count());
        }
        public void Should_filter_out_duplicate_instances()
        {
            var instances = new EndpointInstances();
            var sales     = "Sales";

            instances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance(sales, "dup"),
                new EndpointInstance(sales, "dup")
            });

            var salesInstances = instances.FindInstances(sales);

            Assert.AreEqual(1, salesInstances.Count());
        }
 RoutingComponent(UnicastRoutingTable unicastRoutingTable,
                  DistributionPolicy distributionPolicy,
                  EndpointInstances endpointInstances,
                  Publishers publishers,
                  UnicastSendRouter unicastSendRouter,
                  bool enforceBestPractices,
                  Validations messageValidator)
 {
     UnicastRoutingTable  = unicastRoutingTable;
     DistributionPolicy   = distributionPolicy;
     EndpointInstances    = endpointInstances;
     Publishers           = publishers;
     EnforceBestPractices = enforceBestPractices;
     MessageValidator     = messageValidator;
     UnicastSendRouter    = unicastSendRouter;
 }
 public UnicastSendRouter(
     bool isSendOnly,
     string receiveQueueName,
     string instanceSpecificQueue,
     IDistributionPolicy defaultDistributionPolicy,
     UnicastRoutingTable unicastRoutingTable,
     EndpointInstances endpointInstances,
     Func <EndpointInstance, string> transportAddressTranslation)
 {
     this.isSendOnly                  = isSendOnly;
     this.receiveQueueName            = receiveQueueName;
     this.instanceSpecificQueue       = instanceSpecificQueue;
     this.defaultDistributionPolicy   = defaultDistributionPolicy;
     this.unicastRoutingTable         = unicastRoutingTable;
     this.endpointInstances           = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
 public UnicastSendRouter(
     string baseInputQueueName,
     string endpointName,
     string instanceSpecificQueue,
     string distributorAddress,
     IDistributionPolicy defaultDistributionPolicy,
     UnicastRoutingTable unicastRoutingTable,
     EndpointInstances endpointInstances,
     Func <EndpointInstance, string> transportAddressTranslation)
 {
     this.endpointName                = baseInputQueueName ?? endpointName;
     this.instanceSpecificQueue       = instanceSpecificQueue;
     this.distributorAddress          = distributorAddress;
     this.defaultDistributionPolicy   = defaultDistributionPolicy;
     this.unicastRoutingTable         = unicastRoutingTable;
     this.endpointInstances           = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
        private void PopulateInstances(EndpointInstances instances, KeyValuePair <string, string> address)
        {
            var partitionedEndpoints = new List <EndpointInstance>();

            var serviceName = new Uri(address.Value);

            using (var client = new FabricClient())
            {
                var partitions = client.QueryManager.GetPartitionListAsync(serviceName).GetAwaiter().GetResult();

                foreach (var partition in partitions)
                {
                    partitionedEndpoints.Add(new EndpointInstance(address.Key, partition.PartitionInformation.Id.ToString()));
                }
            }

            instances.AddOrReplaceInstances(address.Value, partitionedEndpoints);
        }
 public Configuration(
     UnicastRoutingTable unicastRoutingTable,
     Publishers publishers,
     DistributionPolicy distributionPolicy,
     ConfiguredUnicastRoutes configuredUnicastRoutes,
     IReadOnlyList <DistributionStrategy> customDistributionStrategies,
     EndpointInstances settingsEndpointInstances,
     bool enforceBestPractices,
     string returnAddressOverride)
 {
     UnicastRoutingTable          = unicastRoutingTable;
     Publishers                   = publishers;
     DistributionPolicy           = distributionPolicy;
     CustomDistributionStrategies = customDistributionStrategies;
     ConfiguredUnicastRoutes      = configuredUnicastRoutes;
     EnforceBestPractices         = enforceBestPractices;
     PublicReturnAddress          = returnAddressOverride;
     EndpointInstances            = settingsEndpointInstances;
 }
        public void Should_add_instances_grouped_by_endpoint_name()
        {
            var          instances     = new EndpointInstances();
            const string endpointName1 = "EndpointA";
            const string endpointName2 = "EndpointB";

            instances.AddOrReplaceInstances("A", new List <EndpointInstance>
            {
                new EndpointInstance(endpointName1),
                new EndpointInstance(endpointName2)
            });

            var salesInstances = instances.FindInstances(endpointName1);

            Assert.AreEqual(1, salesInstances.Count());

            var otherInstances = instances.FindInstances(endpointName2);

            Assert.AreEqual(1, otherInstances.Count());
        }
 public SubscriptionRouter(Publishers publishers, EndpointInstances endpointInstances, Func<EndpointInstance, string> transportAddressTranslation)
 {
     this.publishers = publishers;
     this.endpointInstances = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
 public InstanceMappingFileMonitor(string filePath, TimeSpan checkInterval, IAsyncTimer timer, IInstanceMappingFileAccess fileAccess, EndpointInstances endpointInstances)
 {
     this.filePath          = filePath;
     this.checkInterval     = checkInterval;
     this.timer             = timer;
     this.fileAccess        = fileAccess;
     this.endpointInstances = endpointInstances;
 }
 public UnicastSendRouter(UnicastRoutingTable unicastRoutingTable, EndpointInstances endpointInstances, Func<EndpointInstance, string> transportAddressTranslation)
 {
     this.unicastRoutingTable = unicastRoutingTable;
     this.endpointInstances = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
 public SubscriptionRouter(Publishers publishers, EndpointInstances endpointInstances, Func <EndpointInstance, string> transportAddressTranslation)
 {
     this.publishers                  = publishers;
     this.endpointInstances           = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
Beispiel #30
0
 public NativeSubscriptionForwarder(IManageSubscriptions subscriptionManager, RuntimeTypeGenerator typeGenerator, EndpointInstances endpointInstances)
 {
     this.subscriptionManager = subscriptionManager;
     this.typeGenerator       = typeGenerator;
     this.endpointInstances   = endpointInstances;
 }
Beispiel #31
0
 public UnicastSendRouter(UnicastRoutingTable unicastRoutingTable, EndpointInstances endpointInstances, Func <EndpointInstance, string> transportAddressTranslation)
 {
     this.unicastRoutingTable         = unicastRoutingTable;
     this.endpointInstances           = endpointInstances;
     this.transportAddressTranslation = transportAddressTranslation;
 }
Beispiel #32
0
 public SendRouter(EndpointInstances endpointInstances, RawDistributionPolicy distributionPolicy)
 {
     this.endpointInstances  = endpointInstances;
     this.distributionPolicy = distributionPolicy;
 }
 public MessageDrivenSubscribeRouter(ISubscriptionStorage subscriptionStorage, EndpointInstances endpointInstances)
     : base(subscriptionStorage)
 {
     this.endpointInstances = endpointInstances;
 }