コード例 #1
0
        public void Connect()
        {
            if (this.connection != null && this.connection.IsOpen)
            {
                this.connection.Close();
            }

            var factory = new ConnectionFactory()
            {
                HostName = this.BrokerHostname,
                UserName = this.BrokerUsername,
                Password = this.BrokerPassword,
                Port     = this.BrokerPort
            };

            this.connection = factory.CreateConnection();
            var rmqChannel = connection.CreateModel();

            rmqChannel.ExchangeDeclare(exchange: "shift_topology_exchange", type: "topic");

            var queueName = rmqChannel.QueueDeclare().QueueName;

            rmqChannel.QueueBind(queue: queueName,
                                 exchange: "shift_topology_exchange",
                                 routingKey: this.RoutingKey);

            //Logger.Print.BulletMessage(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "(): " +
            //    "Connected to exclusive IGP topology queue.", Logger.Print.ConsoleColor.ForestGreen, true);

            var consumer = new EventingBasicConsumer(rmqChannel);

            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                var data = Encoding.UTF8.GetString(body);

                JObject exabgp_bgp_ls_message = JObject.Parse(data);

                exabgp_bgp_ls_message.Add("yggdrasil-data-type", "exabgp-bgp-ls-message");

                OnTopologyChangeCallback?.Invoke(exabgp_bgp_ls_message);
            };

            rmqChannel.BasicConsume(queue: queueName, consumer: consumer, autoAck: true);
        }
コード例 #2
0
        public void Connect()
        {
            if (this.connection != null && this.connection.IsOpen)
            {
                this.connection.Close();
            }

            var factory = new ConnectionFactory()
            {
                HostName = this.BrokerHostname,
                UserName = this.BrokerUsername,
                Password = this.BrokerPassword,
                Port     = this.BrokerPort
            };

            this.connection = factory.CreateConnection();
            var rmqChannel = connection.CreateModel();

            rmqChannel.ExchangeDeclare(exchange: "shift_topology_exchange", type: "topic");

            var queueName = rmqChannel.QueueDeclare().QueueName;

            rmqChannel.QueueBind(queue: queueName,
                                 exchange: "shift_topology_exchange",
                                 routingKey: this.RoutingKey);

            var consumer = new EventingBasicConsumer(rmqChannel);

            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                var data = Encoding.UTF8.GetString(body);

                JObject shift_pcep_message = JObject.Parse(data);

                shift_pcep_message.Add("yggdrasil-data-type", "shift-pcep-message");

                OnTopologyChangeCallback?.Invoke(shift_pcep_message);
            };

            rmqChannel.BasicConsume(queue: queueName, consumer: consumer, autoAck: true);
        }