public RabbitMqHealthCheck(string rabbitConnectionString, SslOption ssl = null) : this( new Uri(rabbitConnectionString), ssl) { }
/// <summary> /// Add a health check for RabbitMQ services using connection string (amqp uri). /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="rabbitMQConnectionString">The RabbitMQ connection string to be used.</param> /// <param name="sslOption">The RabbitMQ ssl options. Optional. If <c>null</c>, the ssl option will counted as disabled and not used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'rabbitmq' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param> public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder, string rabbitMQConnectionString, SslOption sslOption = null, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { return(builder.Add(new HealthCheckRegistration( name ?? NAME, new RabbitMQHealthCheck(rabbitMQConnectionString, sslOption), failureStatus, tags, timeout))); }
public RabbitMqHealthCheck(Uri rabbitConnectionString, SslOption ssl = null) : this(CreateFactory(rabbitConnectionString, ssl)) { }
public static Result Receive(Receive param) { var queueResult = new Result(); var connectionFactory = new ConnectionFactory() { HostName = param.HostName, VirtualHost = param.VirtualHost, UserName = param.UserName, Password = param.Password }; if (param.EnableSSL) { var sslOption = new SslOption { Enabled = true, ServerName = param.HostName, AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors }; connectionFactory.Ssl = sslOption; } if (param.Port.HasValue) { connectionFactory.Port = param.Port.Value; } try { using (var connection = connectionFactory.CreateConnection()) { using (var channel = connection.CreateModel()) { var declare = channel.QueueDeclare(queue: param.QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); int downloadSize = param.DownloadSize.HasValue ? (param.DownloadSize.Value > (int)declare.MessageCount ? (int)declare.MessageCount : param.DownloadSize.Value) : (int)declare.MessageCount; while (downloadSize > 0) { BasicGetResult result = channel.BasicGet(param.QueueName, true); if (result != null) { string data = Encoding.UTF8.GetString(result.Body); queueResult.Results.Add(data); } downloadSize--; } } } } catch (RabbitMQ.Client.Exceptions.BrokerUnreachableException ex) { queueResult.Exceptions.Add("Unreachable Exception: " + ex.Message); } catch (RabbitMQ.Client.Exceptions.ConnectFailureException connEx) { queueResult.Exceptions.Add("Connect Failure Exception: " + connEx.Message); } catch (RabbitMQ.Client.Exceptions.AuthenticationFailureException authEx) { queueResult.Exceptions.Add("Authentication Failure Exception: " + authEx.Message); } return(queueResult); }
public HostConfiguration() { Ssl = new SslOption(); }
public static Result Send(Send param) { var queueResult = new Result(); var connectionFactory = new ConnectionFactory() { HostName = param.HostName, VirtualHost = param.VirtualHost, UserName = param.UserName, Password = param.Password }; if (param.EnableSSL) { var sslOption = new SslOption { Enabled = true, ServerName = param.HostName, AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors }; connectionFactory.Ssl = sslOption; } if (param.Port.HasValue) { connectionFactory.Port = param.Port.Value; } try { using (var connection = connectionFactory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: param.QueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); var body = Encoding.UTF8.GetBytes(param.Message); channel.BasicPublish(exchange: "", routingKey: param.QueueName, basicProperties: null, body: body); } } } catch (RabbitMQ.Client.Exceptions.BrokerUnreachableException ex) { queueResult.Exceptions.Add("Unreachable Exception: " + ex.Message); } catch (RabbitMQ.Client.Exceptions.ConnectFailureException connEx) { queueResult.Exceptions.Add("Connect Failure Exception: " + connEx.Message); } catch (RabbitMQ.Client.Exceptions.AuthenticationFailureException authEx) { queueResult.Exceptions.Add("Authentication Failure Exception: " + authEx.Message); } return(queueResult); }
public IRabbitMqOptionsBuilder WithSsl(SslOption ssl) { _options.Ssl = ssl; return(this); }
private SslHelper(SslOption sslOption) { _sslOption = sslOption; }
public RabbitMQHealthCheck(Uri rabbitConnectionString, SslOption ssl) { _rabbitConnectionString = rabbitConnectionString; _sslOption = ssl; }
/// <summary> /// Add a health check for RabbitMQ services using connection string (amqp uri). /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="rabbitMQConnectionString">The RabbitMQ connection string to be used.</param> /// <param name="sslOption">The RabbitMQ ssl options. Optional. If <c>null</c>, the ssl option will counted as disabled and not used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'rabbitmq' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddRabbitMQ(this IHealthChecksBuilder builder, Uri rabbitConnectionString, SslOption sslOption = null, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { builder.Services .AddSingleton(sp => new RabbitMQHealthCheck(rabbitConnectionString, sslOption)); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => sp.GetRequiredService <RabbitMQHealthCheck>(), failureStatus, tags, timeout))); }