Parses a connection string for the values required to connect to a RabbitMQ broker instance. Connection string should look something like this: host=192.168.1.1;port=5672;virtualHost=MyVirtualHost;username=MyUsername;password=MyPassword
예제 #1
0
        public virtual ITunnel Create(string connectionString, IRabbitWatcher watcher)
        {
            var connectionValues = new ConnectionString(connectionString);

            return Create(connectionValues.Host,
                          connectionValues.VirtualHost,
                          connectionValues.UserName,
                          connectionValues.Password,
                          watcher);
        }
예제 #2
0
        /// <summary>
        /// Create a tunnel with provided connection string and IRabbitWatcher object
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="watcher"></param>
        /// <returns></returns>
        public virtual ITunnel Create(string connectionString, IRabbitWatcher watcher)
        {
            var clusterConnections = connectionString.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
            if (clusterConnections.Length > 1)
            {
                var factories = clusterConnections.Select(x => new ManagedConnectionFactory(new ConnectionString(x)))
                                                  .ToList();

                var rabbitWatcher = watcher ?? Global.DefaultWatcher;
                var haConnection = new HaConnection(new DefaultRetryPolicy(), rabbitWatcher, factories);
                return Create(haConnection, rabbitWatcher);
            }

            var connectionValues = new ConnectionString(connectionString);
            return Create(new ManagedConnectionFactory(connectionValues), watcher);
        }