Exemplo n.º 1
0
        static void Main(string[] args)
        {
            GetAppSettingsFile();
            try
            {
                var factory = CreateRabbitMQFactory();
                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.QueueDeclare(queue: "viajanet",
                                             durable: false,
                                             exclusive: false,
                                             autoDelete: false,
                                             arguments: null);

                        var consumer = new EventingBasicConsumer(channel);
                        consumer.Received += (model, args) =>
                        {
                            var body     = args.Body;
                            var message  = Encoding.UTF8.GetString(body);
                            var userData = Newtonsoft.Json.JsonConvert.DeserializeObject <UserData>(message);

                            bool couchSaved = CouchbaseConnection.Create(_iconfiguration).Upsert(userData);
                            bool sqlSaved   = SqlServer.Create(_iconfiguration).Insert(userData);

                            if (couchSaved && sqlSaved)
                            {
                                Console.WriteLine("Message saved on both databases");
                            }
                            else
                            {
                                Console.WriteLine("Something went wront when saving the message");
                            }
                        };
                        channel.BasicConsume(queue: "viajanet",
                                             autoAck: true,
                                             consumer: consumer);

                        Console.ReadLine();
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
 public LeituraController(IConfiguration IConfiguration)
 {
     _iconfiguration = IConfiguration;
     repository      = CouchbaseConnection.Create(_iconfiguration);
 }