Ejemplo n.º 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();
        }
Ejemplo n.º 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.");
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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 ......");
        }
Ejemplo n.º 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 .....");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 9
0
        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.");
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 11
0
        public void runtest(Object invokeEntity)
        {
            try
            {
                mongodbHelper = new ZC.DBUtils.MongodbHelper(System.Configuration.ConfigurationManager.AppSettings["mgdwhost"].ToString());
            }
            catch (Exception ex)
            {
                File.AppendAllText("error.txt", ex.Message);
            }

            //// 处理mongodb查询日志
            consumerQuery = RocketMqHelper.CreateDefaultMQPushConsumer <MongoDBQueryListener>("MongoDB_Query", MessageModel.CLUSTERING, "MongoDB", "Query");

            consumerUpdateVersion = RocketMqHelper.CreateDefaultMQPushConsumer <MongoDBUpdateVersionListener>("MongoDB_UpdateVersion", MessageModel.CLUSTERING, "MongoDB", "UpdateVersion");

            while (true)
            {
                Thread.Sleep(2000);
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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)
            {
            }
        }
Ejemplo n.º 14
0
 public MessageTopshelf()
 {
     consumer = RocketMqHelper.CreateDefaultMQPushConsumer <UploadOssMessageListener>(MqConst.UploadOssCusomerGroup);
 }
Ejemplo n.º 15
0
 public MessageTopshelf()
 {
     consumer = RocketMqHelper.CreateDefaultMQPushConsumer <SyncMessageListener>(MqConst.UserSyncMessageCusomerGroup);
 }