Exemplo n.º 1
0
        public static SendResult SendMessage(this DefaultMQProducer defaultMQProducer, Message message)
        {
            var sendResult = defaultMQProducer.send(message);
            int count      = 0;

            if (sendResult.getSendStatus() != SendStatus.SEND_OK)
            {
                if (count > 5)
                {
                    Wechat.Util.Log.Logger.GetLog <DefaultMQProducer>().Error($"推送作业消息失败,推送内容【{Encoding.UTF8.GetString(message.getBody())}】");
                }
                sendResult = defaultMQProducer.send(message);
            }
            return(sendResult);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            DefaultMQProducer p = new DefaultMQProducer("ProducerGroup");

            p.start();
            for (int i = 0; i < 100; i++)
            {
                try
                {
                    var     data = Encoding.Default.GetBytes("Hello To All" + i);
                    Message m    = new Message("defaulttopic", data);

                    SendResult sendResult = p.send(m);

                    Console.WriteLine(sendResult);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    break;
                }
            }
            p.shutdown();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public async Task sendMessage(string toipcName)
        {
            try
            {
                var     message         = Guid.NewGuid().ToString();;
                byte[]  data            = encoder.GetBytes(message);
                Message msg             = new Message(toipcName, "*", "skey_02", data);
                MessageQueueSelector qs = new QueueSelector();
                string     hh           = "c091e548-b45a-49b4-b8ec-2cb5e2_global";
                SendResult result       = _producer.send(msg);
                Console.WriteLine("Message send :" + result.getMsgId());

                //Message msg2 = new Message("251122b1-fec6-491d-969a-44a87138fc31", "dca90c36-da58-4fef-b3f8-2f7fec99d138", "skey_03", data);

                //for(int i = 0; i < 10; i++)
                //{
                //    SendResult result = _producer.send(msg, qs, 0);
                //    Console.WriteLine("Message send :" + result.getMsgId());
                //}

                //Parallel.For(0, 10000,
                //   index => {
                //       SendResult result = _producer.send(msg, qs, 0);
                //       SendResult result2 = _producer.send(msg2, qs, 0);
                //       Console.WriteLine("Message send :" + result.getMsgId());
                //   });
            }

            catch (Exception e)

            {
                e.GetBaseException();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            #region 生产消息
            DefaultMQProducer producer = null;
            try
            {
                ////wulangtes  是分组名字,用来区分生产者
                producer = new DefaultMQProducer("wulangtes");

                ////服务器ip
                producer.setNamesrvAddr("192.168.10.2:9876");
                producer.start();

                ////Go_Ticket_WuLang_Test 为 toptic 名字,taga是比toptic更为精确地内容划分,RocketMQ会重试是内容
                Message    msg        = new Message("Go_Ticket_WuLang_Test", "TagA", Encoding.UTF8.GetBytes("RocketMQ会重试 "));
                SendResult sendResult = producer.send(msg);
            }
            finally
            {
                producer.shutdown();
            }
            #endregion

            #region 消费者
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test");
            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            consumer.setNamesrvAddr("192.168.10.2:9876");
            ////Go_Ticket_WuLang_Test toptic名字,* 表示不过滤tag,如果过滤,可使用 ||划分
            consumer.subscribe("Go_Ticket_WuLang_Test", "*");
            consumer.registerMessageListener(new TestListener());
            consumer.start();
            #endregion
        }
Exemplo n.º 5
0
        public void ProducerMethod()
        {
            DefaultMQProducer producer = new DefaultMQProducer("ProducerGroup");

            //producer.setNamesrvAddr(" 192.168.100.3:9876 ");

            producer.start();


            for (int i = 0; i < 100; i++)
            {
                try
                {
                    Message    msg        = new Message("TopicTestKaro", "TagA", Encoding.Default.GetBytes("Hello world"));
                    SendResult sendResult = producer.send(msg);
                    Console.WriteLine(sendResult);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Thread.Sleep(1000);
                }
            }
            producer.shutdown();
        }
Exemplo n.º 6
0
        public static SendResult SendMessage(this DefaultMQProducer defaultMQProducer, Message message, int delayLevel)
        {
            message.setDelayTimeLevel(delayLevel);
            var sendResult = defaultMQProducer.send(message);

            if (sendResult.getSendStatus() != SendStatus.SEND_OK)
            {
                Wechat.Util.Log.Logger.GetLog <DefaultMQProducer>().Error($"推送作业消息失败,推送内容【{Encoding.UTF8.GetString(message.getBody())}】");
            }
            return(sendResult);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            DefaultMQProducer p = new DefaultMQProducer("test");

            p.setNamesrvAddr("localhost:9876");
            p.start();
            var data = Encoding.UTF8.GetBytes("swathi");
            //  com.alibaba.rocketmq.common.message.Message m = new com.alibaba.rocketmq.common.message.Message("defaulttopic1", data);
            Message msg = new Message("", "", "dkey_01", data);

            p.send(msg);
            p.shutdown();
        }
Exemplo n.º 8
0
        public void Producer()
        {
            DefaultMQProducer producer = new DefaultMQProducer("Broadcast");

            producer.start();


            //string[] tags = new string[]{ "TagA", "TagB", "TagC", "TagD" };
            for (int i = 0; i < 100; i++)
            {
                Message message = new Message("TopicBroadcast", /* tags[i%tags.Length], */ "OrderID188", Encoding.Default.GetBytes("Hello world"));

                SendResult sendResult = producer.send(message);
                Console.WriteLine(sendResult);
            }
            producer.shutdown();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");

            producer.start();
            String[] tags = new String[] { "TagA", "TagB" };
            for (int i = 0; i < 50; i++)
            {
                Message msg = new Message("BroadTopicTest",
                                          tags[i % 2],
                                          "OrderID188",
                                          Encoding.Default.GetBytes("Hello world" + i));
                SendResult sendResult = producer.send(msg);
                Console.WriteLine(sendResult);
            }
            producer.shutdown();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");

            producer.start();
            int totalMessagesToSend = 100;

            for (int i = 0; i < totalMessagesToSend; i++)
            {
                Message message = new Message("TestTopic", Encoding.Default.GetBytes("Hello scheduled message " + i));

                message.setDelayTimeLevel(3);

                producer.send(message);
            }


            producer.shutdown();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            DefaultMQProducer p = new DefaultMQProducer(" test ");

            p.setNamesrvAddr("192.168.1.15:9876 ");
            try
            {
                p.start();
                var     data = Encoding.UTF8.GetBytes("Hello to all");
                Message m    = new Message(" defaulttopic1 ", data);
                p.send(m);
                p.shutdown();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            Console.ReadKey();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            MQProducer producer = new DefaultMQProducer("example_group_name");

            //Launch the instance.
            producer.start();
            string[] tags = new string[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
            for (int i = 0; i < 100; i++)
            {
                int orderId = i % 10;

                Message msg = new Message("TopicTestjjj", tags[i % tags.Length], "KEY" + i,
                                          Encoding.Default.GetBytes("Hello RocketMQ " + i));
                SendResult sendResult = producer.send(msg, new MessageQueueSelector1()
                                                      , orderId);

                Console.WriteLine(sendResult);
            }
            producer.shutdown();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            try
            {
                DefaultMQProducer p = new DefaultMQProducer("test");

                p.setNamesrvAddr("localhost:9876");
                p.start();
                var        data       = Encoding.UTF8.GetBytes("hello data");
                Message    m          = new Message("topic", data);
                SendResult sendResult = p.send(m);
                Console.WriteLine("%s%n", sendResult);
                //     p.send(m);
                p.shutdown();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            Console.ReadLine();
        }
Exemplo n.º 14
0
        public void Producer()
        {
            MQProducer producer = new DefaultMQProducer("OrderedGroup");

            //Launch the instance.
            producer.start();
            String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
            for (int i = 0; i < 100; i++)
            {
                int orderId = i % 10;
                //Create a message instance, specifying topic, tag and message body.
                Message msg = new Message("TopicTest", tags[i % tags.Length], "KEY" + i,
                                          ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));


                SendResult sendResult = producer.send(msg, new QueueSelector(), orderId);

                Console.WriteLine(sendResult);
            }
            //server shutdown
            producer.shutdown();
        }