Esempio n. 1
0
 public Connection()
 {
     _io = new ConnectionIO(this)
     {
         OnError = this.OnError
     };
 }
Esempio n. 2
0
 public Connection()
 {
     _io = new ConnectionIO(this)
     {
         ErrorCallbacks = _errorsCallbacks
     };
 }
Esempio n. 3
0
        public async Task <IConnection> StartConnection(bool autoRecovery = false)
        {
            using (var console = new RestConsole(_host, _username, _password))
            {
                var vhosts = await console.GetVHosts();

                var users = await console.GetUsers();

                Console.WriteLine("vhosts: " + vhosts.Aggregate(" ", (agg, vhst) => agg + " " + vhst.Name));
                Console.WriteLine("users: " + users.Aggregate(" ", (agg, u) => agg + " " + u.Name + "[" + u.Tags + "]"));

                if (!vhosts.Any(v => v.Name == _vhost))
                {
                    await console.CreateVHost(_vhost);

                    await console.SetUserVHostPermission(_username, _vhost);
                }
            }

            LogAdapter.LogDebugFn = (cat, msg, exc) =>
            {
                Console.WriteLine("DEBUG [{0}] : {1} - {2}", cat, msg, exc);
            };
            LogAdapter.LogErrorFn = (cat, msg, exc) =>
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("ERROR [{0}] : {1} - {2}", cat, msg, exc);
                Console.ForegroundColor = color;
            };
            LogAdapter.LogWarnFn = (cat, msg, exc) =>
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("WARN  [{0}] : {1} - {2}", cat, msg, exc);
                Console.ForegroundColor = color;
            };

            var conn = await ConnectionFactory.Connect(_host, _vhost, _username, _password, autoRecovery : autoRecovery);

            if (conn is Connection)
            {
                _io = (conn as Connection)._io;
            }
            else if (conn is RecoveryEnabledConnection)
            {
                _io = (conn as RecoveryEnabledConnection)._connection._io;
            }

            _conn = conn;
            return(conn);
        }
Esempio n. 4
0
        public Channel(ChannelOptions options, ushort channelNumber, ConnectionIO connectionIo, CancellationToken cancellationToken)
        {
            _options = options;

            _schedulerToDeliverMessages = (options != null ? options.Scheduler : null) ?? TaskScheduler.Default;

            _cancellationToken = cancellationToken;
            _io = new ChannelIO(this, channelNumber, connectionIo)
            {
                ErrorCallbacks = _errorsCallbacks
            };

            _consumerSubscriptions = new ConcurrentDictionary <string, BasicConsumerSubscriptionInfo>(StringComparer.Ordinal);

            _propertiesPool = new ObjectPoolArray <BasicProperties>(() => new BasicProperties(isFrozen: false, reusable: true), 100, preInitialize: false);
        }
Esempio n. 5
0
        public Channel(ushort channelNumber, ConnectionIO connectionIo, CancellationToken cancellationToken)
        {
            _cancellationToken = cancellationToken;
            _io = new ChannelIO(this, channelNumber, connectionIo)
            {
                OnError = error =>
                {
                    var ev = this.OnError;
                    if (ev != null)
                    {
                        ev(error);
                    }
                }
            };

            _consumerSubscriptions = new ConcurrentDictionary <string, BasicConsumerSubscriptionInfo>(StringComparer.Ordinal);

            _propertiesPool = new ObjectPool <BasicProperties>(() => new BasicProperties(false, reusable: true), 100, preInitialize: false);
        }
Esempio n. 6
0
 public static void StartConnections()
 {
     ConnectionIO.StartReception();
     ConnectionMove.StartReception();
     ConnectionCan.StartReception();
 }