public void TestMethod()
        {
            var cf = new ConnectionFactory()
            {
                Uri = new Uri("amqp://*****:*****@localhost:5672")
            };

            var serviceName = "initExampleService";
            //var reporter = new LoggingReporter(logger);
            var transport = new JaegerHttpTransport();
            var sampler   = new ConstSampler(true);
            var tracer    = new Tracer.Builder(serviceName)
                            //.WithLoggerFactory(loggerFactory)
                            .WithTransport(transport)
                            //.WithReporter(reporter)
                            .WithSampler(sampler)
                            .Build();

            conn  = cf.CreateConnection("testtracing");
            model = new TracingModel(conn.CreateModel(), tracer);
            // TODO: Add your test code here

            model.BasicPublish("testexchange", "", false, null, Encoding.UTF8.GetBytes("testmessage"));
            Task.Delay(200).Wait();
            var consumer = new EventingBasicConsumer(model);

            consumer.Received += (ch, ea) =>
            {
                var body = ea.Body;
                // ... process the message
                model.BasicAck(ea.DeliveryTag, false);
            };


            var res = model.BasicConsume("testqueueu", false, consumer);

            Assert.Pass("Your first passing test");
        }
Exemplo n.º 2
0
        public void TestConsumer()
        {
            var cf = new ConnectionFactory()
            {
                Uri = new Uri("amqp://*****:*****@localhost:5672")
            };

            var serviceName = "initExampleService";
            var transport   = new JaegerHttpTransport("192.168.99.100");
            //var zt = new ZipkinJSONTransport(new Uri("http://192.168.99.100:9411"), 2);

            var reporter = new RemoteReporter.Builder(transport).Build();
            //var zreporter = new RemoteReporter.Builder(zt).Build();

            var sampler = new ConstSampler(true);

            var serviceProvider = new ServiceCollection()
                                  .AddLogging() //<-- You were missing this
                                  .BuildServiceProvider();
            //get logger
            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            loggerFactory.AddConsole(LogLevel.Trace);
            loggerFactory.AddDebug(LogLevel.Trace);

            var log = loggerFactory.CreateLogger("test");

            log.LogInformation("prova log {0}", "prova");

            var logReporter = new LoggingReporter(loggerFactory);

            var tracer = new Tracer.Builder(serviceName)
                         .WithLoggerFactory(loggerFactory)
                         //.WithTransport(transport)
                         .WithReporter(logReporter)
                         .WithSampler(sampler)
                         .Build();

            var conn  = cf.CreateConnection("testtracing");
            var model = new TracingModel(conn.CreateModel(), tracer);

            // TODO: Add your test code here

            model.BasicPublish("testexchange", "", false, null, Encoding.UTF8.GetBytes("testmessage"));
            var consumer = new EventingBasicConsumer(model);

            consumer.Received += (ch, ea) =>
            {
                var body = ea.Body;
                // ... process the message
                model.BasicAck(ea.DeliveryTag, false);
            };

            var trConsumer = new TracingConsumer(consumer, tracer);

            Task.Delay(200).Wait();

            var res = model.BasicConsume("testqueueu", false, trConsumer);


            Assert.True(true, "Your first passing test");
        }