Example #1
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
        }
        static void Main(string[] args)
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ExampleConsumer");

            consumer.subscribe("TestTopic", "*");

            consumer.registerMessageListener(new TestListner());

            consumer.start();
        }
Example #3
0
        static void Main(string[] args)
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            consumer.subscribe("defaulttopic", "*");
            consumer.registerMessageListener(new TestListener());
            consumer.start();
            Console.WriteLine("Consumer Started.");
        }
Example #4
0
        static void Main(string[] args)
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            consumer.setNamesrvAddr("192.168.100.3:9876");
            consumer.subscribe("defaulttopic", "*");
            consumer.registerMessageListener(new TestListener());
            consumer.start();
        }
Example #5
0
        public void ConsumerMethod()
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            consumer.subscribe("TopicTest", "*");


            consumer.registerMessageListener(new MessageListener());
            consumer.start();
        }
Example #6
0
        public void Consumer()
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

            consumer.subscribe("TopicTest", "*"); //TagA || TagC || TagD

            consumer.registerMessageListener(new OrderedListener());

            consumer.start();
            Console.WriteLine("Consumer started ......");
        }
Example #7
0
        public void Consumer()
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("BroadcastConsumer");

            consumer.setMessageModel(MessageModel.BROADCASTING);

            consumer.subscribe("TopicBroadcast", "*");

            consumer.registerMessageListener(new MessageListener());

            consumer.start();
            Console.WriteLine("Consumer started .....");
        }
Example #8
0
        static void Main(string[] args)
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("example_group_name");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

            consumer.subscribe("TopicTest", "TagA || TagC || TagD");

            consumer.registerMessageListener(new TestListener1());

            consumer.start();

            Console.WriteLine("Consumer Started");
        }
        static void Main(string[] args)
        {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("BroadcastConsumerGroup");

            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);


            consumer.setMessageModel(MessageModel.BROADCASTING);

            consumer.subscribe("BroadTopicTest", "TagA");

            consumer.registerMessageListener(new TestListener());

            consumer.start();
            Console.WriteLine("Broadcast Consumer Started.");
        }
Example #10
0
 static void Main(string[] args)
 {
     try
     {
         DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("test");
         consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
         consumer.setNamesrvAddr("192.168.1.15:9876");
         consumer.subscribe("defaulttopic", "*");
         consumer.registerMessageListener(new TestListener());
         consumer.start();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     Console.ReadKey();
 }
Example #11
0
        /// <summary>
        /// 创建消费者
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static DefaultMQPushConsumer CreateDefaultMQPushConsumer <T>(string groupName) where T : MessageListenerConcurrently
        {
            var consumer = consumers.Where(o => o.getConsumerGroup() == groupName).FirstOrDefault();

            if (consumer == null) //双if +lock
            {
                lock (consumer_lock)
                {
                    consumer = consumers.Where(o => o.getConsumerGroup() == groupName).FirstOrDefault();
                    if (consumer == null)
                    {
                        consumer = new DefaultMQPushConsumer(groupName);
                        consumer.setNamesrvAddr(namesrvAddr);
                        consumer.setMessageModel(MessageModel.CLUSTERING);
                        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
                        consumer.registerMessageListener(Activator.CreateInstance <T>());
                        consumer.start();
                        consumers.Add(consumer);
                    }
                }
            }
            return(consumer);
        }
Example #12
0
        static void Main(string[] args)
        {
            try
            {
                string topic = "topicF";
                DefaultMQPushConsumer _consumer = new DefaultMQPushConsumer("prod900900");
                _consumer.setNamesrvAddr("localhost:9876");
                // _consumer.setVipChannelEnabled(false);
                _consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
                _consumer.subscribe(topic, "*");

                RoutingListener listener = new RoutingListener();
                _consumer.registerMessageListener(listener);
                _consumer.start();

                //_consumer.createTopic("TBW102", topic, 4);

                // Console.ReadKey();
            }
            catch (Exception ex)
            {
            }
        }