Beispiel #1
0
        void SubscribeRunde(IModel channel, SqlQueryInsert queryInsert)
        {
            channel.ExchangeDeclare(exchange: "Runde", type: "fanout");

            var queueName = channel.QueueDeclare().QueueName;

            channel.QueueBind(queue: queueName,
                              exchange: "Runde",
                              routingKey: "");


            var consumer = new EventingBasicConsumer(channel);

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

                Runde item = Newtonsoft.Json.JsonConvert.DeserializeObject <Runde>(message);
                queryInsert.RunderInsert(item);
            };
            channel.BasicConsume(queue: queueName,
                                 autoAck: true,
                                 consumer: consumer);

            /*
             * channel.QueueDeclare(queue: "Opret",
             *                   durable: true,
             *                   exclusive: false,
             *                   autoDelete: false,
             *                   arguments: null);
             *
             * channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);*/
            /*
             * var consumer = new EventingBasicConsumer(channel);
             * consumer.Received += (model, ea) =>
             * {
             *  var body = ea.Body;
             *  var message = Encoding.UTF8.GetString(body);
             *  Console.WriteLine(" [x] Received {0}", message);
             * };
             * channel.BasicConsume(queue: "Opret",
             *                   autoAck: true,
             *                   consumer: consumer);*/
        }
Beispiel #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    SqlQueryInsert queryInsert = new SqlQueryInsert();
                    SubscribeDelete(channel, queryInsert);
                    SubscribeRunde(channel, queryInsert);
                    await Task.Delay(1);

                    while (true)
                    {
                    }
                }
        }