Ejemplo n.º 1
0
        // start the connection for sending messages
        public void Start()
        {
            // clean connections
            var activeConnections = ManagementClient.GetConnections();

            foreach (var connection in activeConnections)
            {
                ManagementClient.CloseConnection(connection);
            }

            // factory uses default user: guest/guest
            var factory = new ConnectionFactory
            {
                HostName    = RabbitIp,
                VirtualHost = VirtualHostName
            };

            _connection = factory.CreateConnection();
            _channel    = _connection.CreateModel();
            _channel.ExchangeDeclare(exchange: UfExchange, type: ExchangeType.Topic, true);

            _timer          = new SdkTimer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            _timer.Elapsed += TimerCheckAndSend;
            _timer.Start();
            _isRunning = true;
        }
Ejemplo n.º 2
0
        private void IntermittentDisconnection()
        {
            const int secondsBetweenDisconnection = 2;

            Task.Factory.StartNew(() =>
            {
                var client = new ManagementClient("http://localhost", "guest", "guest", 15672);
                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(secondsBetweenDisconnection));
                    var connections = client.GetConnections();
                    foreach (var connection in connections)
                    {
                        client.CloseConnection(connection);
                    }
                }
            }, TaskCreationOptions.LongRunning);
        }
Ejemplo n.º 3
0
        private void IntermittentDisconnection()
        {
            const int secondsBetweenDisconnection = 2;

            Task.Factory.StartNew(() =>
                {
                    var client = new ManagementClient("http://localhost", "guest", "guest", 15672);
                    while (true)
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(secondsBetweenDisconnection)); 
                        var connections = client.GetConnections();
                        foreach (var connection in connections)
                        {
                            client.CloseConnection(connection);
                        }
                    }
                }, TaskCreationOptions.LongRunning);
        }