Exemplo n.º 1
0
        public RabbitMqHost(RabbitMqHostSettings hostSettings)
        {
            _hostSettings = hostSettings;

            _connectionCache = new RabbitMqConnectionCache(hostSettings);
            MessageNameFormatter = new RabbitMqMessageNameFormatter();
        }
Exemplo n.º 2
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;
            _connectionFactory = settings.GetConnectionFactory();

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConnectionCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
 public RabbitMqSslConfigurator(RabbitMqHostSettings settings)
 {
     CertificatePath = settings.ClientCertificatePath;
     CertificatePassphrase = settings.ClientCertificatePassphrase;
     ServerName = settings.SslServerName;
     _acceptablePolicyErrors = settings.AcceptablePolicyErrors | SslPolicyErrors.RemoteCertificateChainErrors;
 }
Exemplo n.º 4
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings)
        {
            _signal = new StopSignal();

            _settings = settings;

            _connectionFactory = settings.GetConnectionFactory();
        }
 public RabbitMqSslConfigurator(RabbitMqHostSettings settings)
 {
     CertificatePath = settings.ClientCertificatePath;
     CertificatePassphrase = settings.ClientCertificatePassphrase;
     Certificate = settings.ClientCertificate;
     UseCertificateAsAuthenticationIdentity = settings.UseClientCertificateAsAuthenticationIdentity;
     ServerName = settings.SslServerName;
     Protocol = settings.SslProtocol;
     _acceptablePolicyErrors = settings.AcceptablePolicyErrors | SslPolicyErrors.RemoteCertificateChainErrors;
 }
        RabbitMqConnectionContext(IConnection connection, RabbitMqHostSettings hostSettings, ITaskParticipant participant)
            : base(new PayloadCache(), participant.StoppedToken)
        {
            _connection = connection;
            _hostSettings = hostSettings;

            _participant = participant;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);

            connection.ConnectionShutdown += OnConnectionShutdown;
        }
Exemplo n.º 7
0
        public RabbitMqHost(RabbitMqHostSettings hostSettings)
        {
            _hostSettings = hostSettings;

            var exceptionFilter = Retry.Selected<RabbitMqConnectionException>();

            _connectionRetryPolicy = exceptionFilter.Exponential(1000, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1));

            _supervisor = new TaskSupervisor($"{TypeMetadataCache<RabbitMqHost>.ShortName} - {_hostSettings.ToDebugString()}");

            _connectionCache = new RabbitMqConnectionCache(hostSettings, _supervisor);
        }
        public RabbitMqHostBusFactory(ISettingsProvider settingsProvider)
        {
            RabbitMqSettings settings;
            if (!settingsProvider.TryGetSettings("RabbitMQ", out settings))
                throw new ConfigurationException("The RabbitMQ settings were not available");

            _hostSettings = new ConfigurationHostSettings
            {
                Host = settings.Host ?? "[::1]",
                Port = settings.Port ?? 5672,
                VirtualHost = string.IsNullOrWhiteSpace(settings.VirtualHost) ? "/" : settings.VirtualHost.Trim('/'),
                Username = settings.Username ?? "guest",
                Password = settings.Password ?? "guest",
                Heartbeat = settings.Heartbeat ?? 0
            };
        }
        static string FormatDescription(RabbitMqHostSettings settings)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(settings.Username))
            {
                sb.Append(settings.Username).Append('@');
            }

            sb.Append(settings.Host);

            var actualHost = settings.HostNameSelector?.LastHost;

            if (!string.IsNullOrWhiteSpace(actualHost))
            {
                sb.Append('(').Append(actualHost).Append(')');
            }

            if (settings.Port != -1)
            {
                sb.Append(':').Append(settings.Port);
            }

            if (string.IsNullOrWhiteSpace(settings.VirtualHost))
            {
                sb.Append('/');
            }
            else if (settings.VirtualHost.StartsWith("/"))
            {
                sb.Append(settings.VirtualHost);
            }
            else
            {
                sb.Append("/").Append(settings.VirtualHost);
            }

            return(sb.ToString());
        }
Exemplo n.º 10
0
        public static string ToDescription(this RabbitMqHostSettings settings)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(settings.Username))
            {
                sb.Append(settings.Username).Append('@');
            }

            sb.Append(settings.Host);

            ClusterNode?actualHost = settings.EndpointResolver?.LastHost;

            if (actualHost != null)
            {
                sb.Append('(').Append(actualHost).Append(')');
            }
            if (settings.Port != -1)
            {
                sb.Append(':').Append(settings.Port);
            }

            if (string.IsNullOrWhiteSpace(settings.VirtualHost))
            {
                sb.Append('/');
            }
            else if (settings.VirtualHost.StartsWith("/"))
            {
                sb.Append(settings.VirtualHost);
            }
            else
            {
                sb.Append("/").Append(settings.VirtualHost);
            }

            return(sb.ToString());
        }
 public RabbitMqConnectionContext(IConnection connection, RabbitMqHostSettings hostSettings, ITaskSupervisor supervisor)
     : this(connection, hostSettings,
            supervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqConnectionContext>.ShortName} - {hostSettings.ToDebugString()}"))
 {
 }
 public void WhenParsed()
 {
     _hostSettings = _uri.GetHostSettings();
 }
 public void WhenParsed()
 {
     _hostSettings = _uri.GetHostSettings();
     _receiveSettings = _uri.GetReceiveSettings();
 }
 public RabbitMqClusterConfigurator(RabbitMqHostSettings settings)
 {
     _settings = settings;
     _nodes    = new List <ClusterNode>();
 }
Exemplo n.º 15
0
 public RabbitMqConnectionContext(IConnection connection, RabbitMqHostSettings hostSettings, IRabbitMqHostTopology topology, string description, ITaskSupervisor supervisor)
     : this(connection, hostSettings, description, supervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqConnectionContext>.ShortName} - {description}"))
 {
     Topology = topology;
 }
        public IRabbitMqHost Host(RabbitMqHostSettings settings)
        {
            var host = new RabbitMqHost(settings);
            _hosts.Add(host);

            return host;
        }
 public RabbitMqConnectionContext(IConnection connection, RabbitMqHostSettings hostSettings, ITaskSupervisor supervisor)
     : this(connection, hostSettings,
         supervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqConnectionContext>.ShortName} - {hostSettings.ToDebugString()}"))
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// Returns a UriBuilder for the host and entity specified
 /// </summary>
 /// <param name="hostSettings">The host settings</param>
 /// <param name="entityName">The entity name (queue/exchange)</param>
 /// <returns>A UriBuilder</returns>
 static UriBuilder GetHostUriBuilder(RabbitMqHostSettings hostSettings, string entityName)
 {
     return new UriBuilder
     {
         Scheme = "rabbitmq",
         Host = hostSettings.Host,
         Port = hostSettings.Port,
         Path = (string.IsNullOrWhiteSpace(hostSettings.VirtualHost) || hostSettings.VirtualHost == "/")
             ? entityName
             : string.Join("/", hostSettings.VirtualHost, entityName)
     };
 }
 public DelayedExchangeMessageScheduler(ISendEndpointProvider sendEndpointProvider, RabbitMqHostSettings hostSettings)
 {
     _sendEndpointProvider = sendEndpointProvider;
     _hostSettings         = hostSettings;
 }
 public RabbitMqRequestResponseTransport(RabbitMqHostSettings hostSettings, IRequestResponseSettings settings)
 {
     _hostSettings = hostSettings;
     _settings     = settings;
 }
        public static ConnectionFactory GetConnectionFactory(this RabbitMqHostSettings settings)
        {
            var factory = new ConnectionFactory
            {
                AutomaticRecoveryEnabled = false,
                NetworkRecoveryInterval  = TimeSpan.FromSeconds(1),
                TopologyRecoveryEnabled  = false,
                HostName           = settings.Host,
                Port               = settings.Port,
                VirtualHost        = settings.VirtualHost ?? "/",
                RequestedHeartbeat = settings.Heartbeat
            };

            factory.Ssl.Enabled = settings.Ssl;
            factory.Ssl.Version = SslProtocols.Tls;
            factory.Ssl.AcceptablePolicyErrors = settings.AcceptablePolicyErrors;
            factory.Ssl.ServerName             = settings.SslServerName;
            if (string.IsNullOrWhiteSpace(factory.Ssl.ServerName))
            {
                factory.Ssl.AcceptablePolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
            }

            if (string.IsNullOrEmpty(settings.ClientCertificatePath))
            {
                if (!string.IsNullOrWhiteSpace(settings.Username))
                {
                    factory.UserName = settings.Username;
                }
                if (!string.IsNullOrWhiteSpace(settings.Password))
                {
                    factory.Password = settings.Password;
                }

                factory.Ssl.CertPath       = "";
                factory.Ssl.CertPassphrase = "";
                factory.Ssl.Certs          = null;
            }
            else
            {
                factory.Ssl.CertPath       = settings.ClientCertificatePath;
                factory.Ssl.CertPassphrase = settings.ClientCertificatePassphrase;
            }

            factory.ClientProperties = factory.ClientProperties ?? new Dictionary <string, object>();

            HostInfo hostInfo = HostMetadataCache.Host;

            factory.ClientProperties["client_api"]          = "MassTransit";
            factory.ClientProperties["masstransit_version"] = hostInfo.MassTransitVersion;
            factory.ClientProperties["net_version"]         = hostInfo.FrameworkVersion;
            factory.ClientProperties["hostname"]            = hostInfo.MachineName;
            factory.ClientProperties["connected"]           = DateTimeOffset.Now.ToString("R");
            factory.ClientProperties["process_id"]          = hostInfo.ProcessId.ToString();
            factory.ClientProperties["process_name"]        = hostInfo.ProcessName;
            if (hostInfo.Assembly != null)
            {
                factory.ClientProperties["assembly"] = hostInfo.Assembly;
            }
            if (hostInfo.AssemblyVersion != null)
            {
                factory.ClientProperties["assembly_version"] = hostInfo.AssemblyVersion;
            }

            return(factory);
        }
Exemplo n.º 22
0
 public void WhenParsed()
 {
     _hostSettings = _uri.GetHostSettings();
 }
        public static ConnectionFactory GetConnectionFactory(this RabbitMqHostSettings settings)
        {
            var factory = new ConnectionFactory
            {
                AutomaticRecoveryEnabled = false,
                NetworkRecoveryInterval  = TimeSpan.FromSeconds(1),
                TopologyRecoveryEnabled  = false,
                HostName                   = settings.Host,
                Port                       = settings.Port,
                VirtualHost                = settings.VirtualHost ?? "/",
                RequestedHeartbeat         = settings.Heartbeat,
                RequestedConnectionTimeout = settings.RequestedConnectionTimeout,
                RequestedChannelMax        = settings.RequestedChannelMax
            };

            if (settings.EndpointResolver != null)
            {
                factory.HostName = null;
                factory.EndpointResolverFactory = x => settings.EndpointResolver;
            }

            if (settings.UseClientCertificateAsAuthenticationIdentity)
            {
                factory.AuthMechanisms.Clear();
                factory.AuthMechanisms.Add(new ExternalMechanismFactory());
                factory.UserName = "";
                factory.Password = "";
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(settings.Username))
                {
                    factory.UserName = settings.Username;
                }

                if (!string.IsNullOrWhiteSpace(settings.Password))
                {
                    factory.Password = settings.Password;
                }
            }

            ApplySslOptions(settings, factory.Ssl);

            factory.ClientProperties ??= new Dictionary <string, object>();

            HostInfo hostInfo = HostMetadataCache.Host;

            factory.ClientProperties["client_api"]          = "MassTransit";
            factory.ClientProperties["masstransit_version"] = hostInfo.MassTransitVersion;
            factory.ClientProperties["net_version"]         = hostInfo.FrameworkVersion;
            factory.ClientProperties["hostname"]            = hostInfo.MachineName;
            factory.ClientProperties["connected"]           = DateTimeOffset.Now.ToString("R");
            factory.ClientProperties["process_id"]          = hostInfo.ProcessId.ToString();
            factory.ClientProperties["process_name"]        = hostInfo.ProcessName;
            if (hostInfo.Assembly != null)
            {
                factory.ClientProperties["assembly"] = hostInfo.Assembly;
            }

            if (hostInfo.AssemblyVersion != null)
            {
                factory.ClientProperties["assembly_version"] = hostInfo.AssemblyVersion;
            }

            return(factory);
        }
Exemplo n.º 24
0
        public static Uri GetQueueAddress(this RabbitMqHostSettings hostSettings, string queueName)
        {
            UriBuilder builder = GetHostUriBuilder(hostSettings, queueName);

            return(builder.Uri);
        }
Exemplo n.º 25
0
 public void WhenParsed()
 {
     _hostSettings    = _uri.GetHostSettings();
     _receiveSettings = _uri.GetReceiveSettings();
 }
 public RabbitMqRequestResponseTransport(RabbitMqHostSettings hostSettings, IRequestResponseSettings settings)
 {
     _hostSettings = hostSettings;
     _settings = settings;
 }
Exemplo n.º 27
0
 public RabbitMqConnectionCache(RabbitMqHostSettings settings, IRabbitMqHostTopology topology)
     : base(new ConnectionContextFactory(settings, topology))
 {
     _description = settings.ToDebugString();
 }
 public RabbitMqMessageLatencyTransport(RabbitMqHostSettings hostSettings, IMessageLatencySettings settings)
 {
     _hostSettings = hostSettings;
     _settings = settings;
 }
Exemplo n.º 29
0
        public static ConnectionFactory GetConnectionFactory(this RabbitMqHostSettings settings)
        {
            var factory = new ConnectionFactory
            {
                AutomaticRecoveryEnabled = false,
                NetworkRecoveryInterval  = TimeSpan.FromSeconds(1),
                TopologyRecoveryEnabled  = false,
                HostName                   = settings.Host,
                Port                       = settings.Port,
                VirtualHost                = settings.VirtualHost ?? "/",
                RequestedHeartbeat         = settings.Heartbeat,
                RequestedConnectionTimeout = 10000
            };

            if (settings.ClusterMembers != null && settings.ClusterMembers.Any())
            {
                factory.HostName = null;
                factory.EndpointResolverFactory = x => new SequentialEndpointResolver(settings.ClusterMembers);
            }

            if (settings.UseClientCertificateAsAuthenticationIdentity)
            {
                factory.AuthMechanisms.Clear();
                factory.AuthMechanisms.Add(new ExternalMechanismFactory());
                factory.UserName = "";
                factory.Password = "";
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(settings.Username))
                {
                    factory.UserName = settings.Username;
                }
                if (!string.IsNullOrWhiteSpace(settings.Password))
                {
                    factory.Password = settings.Password;
                }
            }

            factory.Ssl.Enabled = settings.Ssl;
            factory.Ssl.Version = settings.SslProtocol;
            factory.Ssl.AcceptablePolicyErrors = settings.AcceptablePolicyErrors;
            factory.Ssl.ServerName             = settings.SslServerName;
            factory.Ssl.Certs = settings.ClientCertificate == null ? null : new X509Certificate2Collection {
                settings.ClientCertificate
            };
            factory.Ssl.CertificateSelectionCallback  = settings.CertificateSelectionCallback;
            factory.Ssl.CertificateValidationCallback = settings.CertificateValidationCallback;

            if (string.IsNullOrWhiteSpace(factory.Ssl.ServerName))
            {
                factory.Ssl.AcceptablePolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
            }

            if (string.IsNullOrEmpty(settings.ClientCertificatePath))
            {
                factory.Ssl.CertPath       = "";
                factory.Ssl.CertPassphrase = "";
            }
            else
            {
                factory.Ssl.CertPath       = settings.ClientCertificatePath;
                factory.Ssl.CertPassphrase = settings.ClientCertificatePassphrase;
            }

            factory.ClientProperties = factory.ClientProperties ?? new Dictionary <string, object>();

            HostInfo hostInfo = HostMetadataCache.Host;

            factory.ClientProperties["client_api"]          = "MassTransit";
            factory.ClientProperties["masstransit_version"] = hostInfo.MassTransitVersion;
            factory.ClientProperties["net_version"]         = hostInfo.FrameworkVersion;
            factory.ClientProperties["hostname"]            = hostInfo.MachineName;
            factory.ClientProperties["connected"]           = DateTimeOffset.Now.ToString("R");
            factory.ClientProperties["process_id"]          = hostInfo.ProcessId.ToString();
            factory.ClientProperties["process_name"]        = hostInfo.ProcessName;
            if (hostInfo.Assembly != null)
            {
                factory.ClientProperties["assembly"] = hostInfo.Assembly;
            }
            if (hostInfo.AssemblyVersion != null)
            {
                factory.ClientProperties["assembly_version"] = hostInfo.AssemblyVersion;
            }

            if (string.IsNullOrEmpty(settings.ClientProvidedName))
            {
                factory.ClientProperties["connection_name"] = $"{hostInfo.MachineName}.{hostInfo.Assembly}_{hostInfo.ProcessName}";
            }
            else
            {
                factory.ClientProperties["connection_name"] = settings.ClientProvidedName;
            }

            return(factory);
        }
 public RabbitMqMessageLatencyTransport(RabbitMqHostSettings hostSettings, IMessageLatencySettings settings)
 {
     _hostSettings = hostSettings;
     _settings     = settings;
 }
Exemplo n.º 31
0
            public ConnectionScope(ITaskScope scope, RabbitMqHostSettings settings)
            {
                _connectionContext = new TaskCompletionSource <RabbitMqConnectionContext>();

                _taskScope = scope.CreateScope($"ConnectionScope: {settings.ToDebugString()}", CloseContext);
            }
Exemplo n.º 32
0
            public ConnectionScope(ITaskScope scope, RabbitMqHostSettings settings)
            {
                _connectionContext = new TaskCompletionSource<RabbitMqConnectionContext>();

                _taskScope = scope.CreateScope($"ConnectionScope: {settings.ToDebugString()}", CloseContext);
            }