public ActiveLoggerProvider(IOptionsMonitor <ActiveLoggerOptions> options)
        {
            loggerOptions = options.CurrentValue;

            producer = ActiveProducer.Create(loggerOptions);
            producer.InitializeCount = loggerOptions.InitializeCount;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 测试生产者
        /// </summary>
        public static void TestProducer()
        {
            ActiveProducer producer = new ActiveProducer(_topic, _brokerUrl, true);

            // 创建生产者

            // 要发送的消息
            // String strMessage = "报警数据来了";
            // System.out.println("开始发送时间:" + DateHelper.getNowStringDate());


            for (int i = 0; i < 100; ++i)
            {
                string str = "报警数据aaaa" + i;
                // 批量发送文本数据
                producer.SendTextMessage(str);
            }

            List <string> textList = new List <string>();

            textList.Add("报警数据aaaa");
            textList.Add("报警数据bbbb");
            textList.Add("报警数据cccc");
            // 批量发送文本数据
            producer.SendTextListMessage(textList);

            // List<byte[]> byteList = new ArrayList<byte[]>();
            // byteList.add("报警数据4".getBytes("utf-8"));
            // byteList.add("报警数据5".getBytes("utf-8"));
            // byteList.add("报警数据6".getBytes("utf-8"));
            // 批量发送byte[]数据
            // ativeProducer.sendByteListMessage(byteList);

            producer.Stop();
        }
Ejemplo n.º 3
0
 private ActiveProducer GetProducer()
 {
     if (producer == null)
     {
         lock (this)
         {
             if (producer == null)
             {
                 producer = ActiveProducer.Create(activeProducerOptions);
                 producer.InitializeCount = activeProducerOptions.InitializeCount;
             }
         }
     }
     return(producer);
 }
        public async Task TopicTest()
        {
            int counter     = 0;
            var destination = $"integration.{topic}";

            //消费
            var consumer = new ActiveConsumer(true, brokerUris)
            {
                Password = password,
                UserName = userName
            };
            await consumer.ListenAsync(new ListenOptions()
            {
                AutoAcknowledge           = false,
                Destination               = destination,
                Durable                   = false,
                FromQueue                 = false,
                PrefetchCount             = 10,
                RecoverWhenNotAcknowledge = false
            }, result =>
            {
                Output.WriteLine($"{destination}:" + result.Message);
                counter++;
                result.Commit();
            });

            //发布
            var producer = new ActiveProducer(true, brokerUris)
            {
                Password = password,
                UserName = userName
            };
            await producer.PublishAsync(destination, "hello active");

            BlockUntil(() => counter >= 1, 3000);

            producer.Dispose();
            consumer.Dispose();

            Assert.Equal(1, counter);
        }
Ejemplo n.º 5
0
 public ActiveLogger(string category, ActiveLoggerOptions options, ActiveProducer producer)
 {
     this.category      = category ?? "";
     this.loggerOptions = options;
     this.producer      = producer;
 }
        public async Task SelectorTest()
        {
            int counter     = 0;
            var destination = $"integration.selector.{queue}";


            /*
             * 数字表达式: >,>=,<,<=,BETWEEN,=
             * 字符表达式:=,<>,IN
             * IS NULL 或 IS NOT NULL
             * 逻辑AND, 逻辑OR, 逻辑NOT
             *
             * 常数类型
             * 数字:3.1415926, 5
             * 字符: ‘a’,必须带有单引号
             * NULL,特别的常量
             * 布尔类型: TRUE,FALSE
             */

            //消费
            var consumer = new ActiveConsumer(true, brokerUris)
            {
                Password = password,
                UserName = userName
            };
            await consumer.ListenAsync(new ListenOptions()
            {
                AutoAcknowledge           = false,
                Destination               = destination,
                Durable                   = false,
                FromQueue                 = true,
                PrefetchCount             = 10,
                RecoverWhenNotAcknowledge = false,
                Selector                  = "apple = 10000 and xiaomi in ('1000','2000','3000') and huawei is null"
            }, result =>
            {
                Output.WriteLine($"{destination}:" + result.Message);
                counter++;
                result.Commit();
            });

            //发布
            var producer = new ActiveProducer(true, brokerUris)
            {
                Password = password,
                UserName = userName
            };
            var dict = new Dictionary <string, object>()
            {
                { "apple", 10000 },
                { "xiaomi", "5000" }
            };
            await producer.SendAsync(new ActiveMessage()
            {
                Destination = destination,
                Message     = "hello active",
                Properties  = dict
            });

            dict["xiaomi"] = "2000";
            await producer.SendAsync(new ActiveMessage()
            {
                Destination = destination,
                Message     = "hello active again",
                Properties  = dict
            });

            BlockUntil(() => counter >= 1, 3000);

            producer.Dispose();
            consumer.Dispose();

            Assert.Equal(1, counter);
        }