public void Consumer(LiveBookApiClient client)
        {
            using var connection = factory.CreateConnection();
            using (var channel = connection.CreateModel())
            {
                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body    = ea.Body.ToArray();
                    var message = Encoding.UTF8.GetString(body);

                    var messg = JsonConvert.DeserializeObject <QueueMessage>(message);
                    try
                    {
                        var paragraph = client.Unlock(messg.ShortName, messg.ParagraphId);
                        Console.WriteLine($"Processing Consumer {messg.ShortName} -- {messg.ParagraphId}");
                        SaveFileAsync(messg.OutputPath, paragraph);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error ex");
                        throw ex;
                    }
                };

                channel.BasicConsume(queue: queueName, autoAck: true, consumer: consumer);
            }
        }
Exemplo n.º 2
0
 public Keeper(string url, string proxy = null)
 {
     _client = new LiveBookApiClient(url, proxy);
     //use for queue
     //_rabbitmqHandler = new RabbitmqHandler("localhost", "processing");
     //_rabbitmqHandler.Consumer(_client);
 }