/// <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) { 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(); }
static void Main(string[] args) { try { Program p = new Program(); encoder = new UTF8Encoding(); _producer = new DefaultMQProducer("prod900900"); _producer.setNamesrvAddr("localhost:9876"); // _producer.setVipChannelEnabled(false); _producer.start(); bool printvalue = true; Console.WriteLine("Enter y to send message"); while (printvalue) { string line = Console.ReadLine(); if (line != "y") { printvalue = false; } p.sendMessage("topicF"); } _producer.shutdown(); } catch (Exception ex) { } Console.WriteLine("Enter to exit"); Console.ReadLine(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
/// <summary> /// 创建生产者 /// </summary> /// <param name="group"></param> /// <returns></returns> public static DefaultMQProducer CreateDefaultMQProducer(string groupName) { var producer = producers.Where(o => o.getProducerGroup() == groupName).FirstOrDefault(); if (producer == null) //双if +lock { lock (producer_lock) { producer = producers.Where(o => o.getProducerGroup() == groupName).FirstOrDefault(); if (producer == null) { producer = new DefaultMQProducer(groupName); producer.setNamesrvAddr(namesrvAddr); producer.start(); producers.Add(producer); } } } return(producer); }
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(); }
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(); }
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(); }
/// <summary> /// 创建生产者 /// </summary> /// <param name="group"></param> /// <returns></returns> public static DefaultMQProducer CreateDefaultMQProducer(string groupName, int queueCount = 6) { var producer = producers.Where(o => o.getProducerGroup() == groupName).FirstOrDefault(); if (producer == null) //双if +lock { lock (producer_lock) { producer = producers.Where(o => o.getProducerGroup() == groupName).FirstOrDefault(); if (producer == null) { producer = new DefaultMQProducer(groupName); producer.setNamesrvAddr(namesrvAddr); producer.setRetryTimesWhenSendFailed(3); producer.setDefaultTopicQueueNums(queueCount); producer.start(); producers.Add(producer); } } } return(producer); }