예제 #1
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;
 }
예제 #2
0
        static void UpdateRoutingTable(DatabaseReader databaseReader, string connectionString, UnicastRoutingTable routingTable, UnicastSubscriberTable subscriberTable, bool nativeSends, bool nativePublishes)
        {
            try
            {
                var endpoints = databaseReader.GetEndpoints(connectionString);

                var commandRoutes = new List <RouteTableEntry>();
                var eventRoutes   = new List <RouteTableEntry>();

                foreach (var endpoint in endpoints)
                {
                    var route = UnicastRoute.CreateFromEndpointName(endpoint.LogicalEndpointName);
                    foreach (var commandType in endpoint.Commands)
                    {
                        if (nativeSends)
                        {
                            _log.Warn($"Selected transport uses native command routing. Route for {commandType.FullName} to {endpoint.LogicalEndpointName} configured in database will be ignored.");
                        }
                        commandRoutes.Add(new RouteTableEntry(commandType, route));
                    }

                    foreach (var eventType in endpoint.Events)
                    {
                        if (nativePublishes)
                        {
                            _log.Warn($"Selected transport uses native event routing. Route for {eventType.FullName} to {endpoint.LogicalEndpointName} configured in database will be ignored.");
                        }
                        eventRoutes.Add(new RouteTableEntry(eventType, route));
                    }
                }

                routingTable.AddOrReplaceRoutes("DatabaseBasedRouting", commandRoutes);
                subscriberTable.AddOrReplaceRoutes("DatabaseBasedRouting", eventRoutes);

                _log.Debug($"Updated routing information from database");
            }
            catch (Exception e)
            {
                _log.Error($"Failed to update routing information from database. The last valid routing configuration will be used instead.", e);
                throw;
            }
        }