public ConnectionConfiguration() { // set default values Port = DefaultPort; VirtualHost = "/"; UserName = "******"; Password = "******"; RequestedHeartbeat = 10; Timeout = 10; // seconds PublisherConfirms = false; PersistentMessages = true; CancelOnHaFailover = false; UseBackgroundThreads = false; ConnectIntervalAttempt = TimeSpan.FromSeconds(5); // prefetchCount determines how many messages will be allowed in the local in-memory queue // setting to zero makes this infinite, but risks an out-of-memory exception. // set to 50 based on this blog post: // http://www.rabbitmq.com/blog/2012/04/25/rabbitmq-performance-measurements-part-2/ PrefetchCount = 50; AuthMechanisms = new AuthMechanismFactory[] {new PlainMechanismFactory()}; Hosts = new List<HostConfiguration>(); Ssl = new SslOption(); }
///<summary>Construct an AmqpTcpEndpoint with the given ///IProtocol, hostname, port number and ssl option. If the port ///number is -1, the default port number for the IProtocol ///will be used.</summary> public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne, SslOption ssl) { m_protocol = protocol; m_hostName = hostName; m_port = portOrMinusOne; m_ssl = ssl; }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { SslHelper helper = new SslHelper(sslOption); SslStream sslStream = new SslStream(tcpStream, false, new RemoteCertificateValidationCallback(helper.CertificateValidationCallback), new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback)); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
/// <summary> /// Upgrade a Tcp stream to an Ssl stream using the SSL options provided. /// </summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { var helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? helper.CertificateValidationCallback; LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? helper.CertificateSelectionCallback; var sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
public RabbitMQReportsConfig() { HostName = "localhost"; Port = 5672; UserName = "******"; Password = "******"; ExchangeType = RMQ.ExchangeType.Topic; Protocol = RMQ.Protocols.DefaultProtocol; ExchangeName = "metrics"; ExchangeDurable = false; ExchangeAutoDelete = true; ExchangePassive = false; RoutingKey = "metrics"; ReplaceDotsOnFieldNames = false; VirtualHost = "/"; ConnectionTimeout = 10; Ssl = new RMQ.SslOption(); }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption) { SslHelper helper = new SslHelper(sslOption); // Use the client specified remote certificate validation callback if it is not null RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? new RemoteCertificateValidationCallback( helper.CertificateValidationCallback); // Use the client specified local certificate selector callback if it is not null LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? new LocalCertificateSelectionCallback( helper.CertificateSelectionCallback); SslStream sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); return sslStream; }
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options ///provided</summary> public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption, int timeout) { SslHelper helper = new SslHelper(sslOption); RemoteCertificateValidationCallback remoteCertValidator = sslOption.CertificateValidationCallback ?? new RemoteCertificateValidationCallback(helper.CertificateValidationCallback); LocalCertificateSelectionCallback localCertSelector = sslOption.CertificateSelectionCallback ?? new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback); SslStream sslStream = new SslStream(tcpStream, false, remoteCertValidator, localCertSelector); sslStream.AuthenticateAsClient(sslOption.ServerName, sslOption.Certs, sslOption.Version, false); sslStream.ReadTimeout = timeout; sslStream.WriteTimeout = timeout; return sslStream; }
private SslHelper(SslOption sslOption) { m_sslOption = sslOption; }
///<summary>Construct an AmqpTcpEndpoint with the given ///IProtocol, Uri and ssl options.</summary> ///<remarks> /// Please see the class overview documentation for /// information about the Uri format in use. ///</remarks> public AmqpTcpEndpoint(IProtocol protocol, Uri uri, SslOption ssl) : this(protocol, uri.Host, uri.Port, ssl) { }
/// <summary> /// Creates a new instance of the <see cref="AmqpTcpEndpoint"/>. /// </summary> /// <param name="hostName">Hostname.</param> /// <param name="portOrMinusOne"> Port number. If the port number is -1, the default port number will be used.</param> /// <param name="ssl">Ssl option.</param> public AmqpTcpEndpoint(string hostName, int portOrMinusOne, SslOption ssl) { HostName = hostName; _port = portOrMinusOne; Ssl = ssl; }
/// <summary> /// Creates a new instance of the <see cref="AmqpTcpEndpoint"/> with the given Uri and ssl options. /// </summary> /// <remarks> /// Please see the class overview documentation for information about the Uri format in use. /// </remarks> public AmqpTcpEndpoint(Uri uri, SslOption ssl) : this(uri.Host, uri.Port, ssl) { }
public RawRabbitConfiguration() { RequestTimeout = TimeSpan.FromSeconds(10); PublishConfirmTimeout = TimeSpan.FromSeconds(1); PersistentDeliveryMode = true; AutoCloseConnection = true; AutomaticRecovery = true; TopologyRecovery = true; RecoveryInterval = TimeSpan.FromSeconds(10); Ssl = new SslOption {Enabled = false}; Hostnames = new List<string>(); Exchange = new GeneralExchangeConfiguration { AutoDelete = false, Durable = true, Type = ExchangeType.Direct }; Queue = new GeneralQueueConfiguration { Exclusive = false, AutoDelete = false, Durable = true }; }
public HostConfiguration() { Ssl = new SslOption(); }
public ConnectionConfiguration() { // set default values Port = DefaultPort; VirtualHost = "/"; UserName = "******"; Password = "******"; RequestedHeartbeat = 10; Timeout = 10; // seconds PublisherConfirms = false; PersistentMessages = true; // prefetchCount determines how many messages will be allowed in the local in-memory queue // setting to zero makes this infinite, but risks an out-of-memory exception. // set to 50 based on this blog post: // http://www.rabbitmq.com/blog/2012/04/25/rabbitmq-performance-measurements-part-2/ PrefetchCount = 50; Hosts = new List<IHostConfiguration>(); Ssl = new SslOption(); }
public static int Main(string[] args) { Hashtable cnxSettings = new Hashtable(); if (AppConfig.Load(ref cnxSettings) > 0) { Console.WriteLine( "error occurred while parsing .exe.config."); } string queueName = cnxSettings["AMQ_QUEUE"].ToString(); ServicePointManager.ServerCertificateValidationCallback = ValidateSslCerts; try { Console.WriteLine("connecting to Active MQ queue {4} over tcp/{1} on {0} with {2}/{3} credentials", cnxSettings["AMQ_HOST"].ToString(), cnxSettings["AMQ_PORT"].ToString(), cnxSettings["AMQ_USER"].ToString(), cnxSettings["AMQ_PASS"].ToString(), cnxSettings["AMQ_QUEUE"].ToString() ); ConnectionFactory factory = new ConnectionFactory(); factory.HostName = cnxSettings["AMQ_HOST"].ToString(); factory.UserName = cnxSettings["AMQ_USER"].ToString(); factory.Password = cnxSettings["AMQ_PASS"].ToString(); factory.VirtualHost = cnxSettings["AMQ_VHOST"].ToString(); factory.Port = Convert.ToInt32(cnxSettings["AMQ_PORT"]); SslOption sslopts = new SslOption(); sslopts.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors | SslPolicyErrors.RemoteCertificateNotAvailable; sslopts.Enabled = true; sslopts.Version = System.Security.Authentication.SslProtocols.Tls12; sslopts.ServerName = cnxSettings["AMQ_HOSTNAME"].ToString(); factory.Ssl = sslopts; // AMQP 0-9-1 Protocol Spec: https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf //IProtocol protocol = Protocols.DefaultProtocol; IProtocol protocol = Protocols.AMQP_0_9_1; IConnection conn = factory.CreateConnection(); IModel channel = conn.CreateModel(); channel.QueueDeclarePassive(queueName); // Disable AutoAcknowledgements. This way a broker will keep items in the queue const bool noAck = false; BasicGetResult result = channel.BasicGet(queueName, noAck); byte[] body = result.Body; string resultMessage = System.Text.Encoding.UTF8.GetString(body); Console.WriteLine(resultMessage); conn.Close(200, "Closing the connection"); Console.WriteLine("closing the connection ..."); } catch(Exception e) { Console.WriteLine(e.Source.ToString() + ": " + e.Message.ToString()); return 1; } return 0; }
// ReSharper disable once UnusedMethodReturnValue.Local private bool Connect() { if (_config.RabbitMqUseSsl) { var ssl = new SslOption {Enabled = true, ServerName = _config.RabbitMqHost}; _connectionFactory = new ConnectionFactory { HostName = _config.RabbitMqHost, UserName = _config.RabbitMqUsername, Password = _config.RabbitPassword, RequestedHeartbeat = _config.RabbitHearBeatIntervalInSeconds, Ssl = ssl }; } else { _connectionFactory = new ConnectionFactory { HostName = _config.RabbitMqHost, UserName = _config.RabbitMqUsername, Password = _config.RabbitPassword, RequestedHeartbeat = _config.RabbitHearBeatIntervalInSeconds, }; } try { _connection = _connectionFactory.CreateConnection(); if (_connection != null && _connection.IsOpen) { _model = _connection.CreateModel(); return _model != null && _model.IsOpen; } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception error) { MessageBox.Show("Error connecting to RabbitMQ: " + error.Message); } return false; // Failed to create connection }
public RawRabbitConfiguration() { RequestTimeout = TimeSpan.FromSeconds(10); PublishConfirmTimeout = TimeSpan.FromSeconds(1); PersistentDeliveryMode = true; AutoCloseConnection = true; AutomaticRecovery = true; TopologyRecovery = true; RouteWithGlobalId = true; RecoveryInterval = TimeSpan.FromSeconds(10); GracefulShutdown = TimeSpan.FromSeconds(10); Ssl = new SslOption {Enabled = false}; Hostnames = new List<string>(); Exchange = new GeneralExchangeConfiguration { AutoDelete = false, Durable = true, Type = ExchangeType.Topic }; Queue = new GeneralQueueConfiguration { Exclusive = false, AutoDelete = false, Durable = true }; VirtualHost = "/"; Username = "******"; Password = "******"; Port = 5672; Hostnames = new List<string> {"localhost"}; }