private static void Main() { using (IMessageQueueFactory messageQueueFactory = new AliyunMessageQueueFactory(new AliyunMessageQueueFactoryOptions { AccessKey = "xxxxxxxx", SecretKey = "xxxxxxxxxx" })) { using (var producer = messageQueueFactory.CreateProducer("ChunSun").Result) { producer.Start().Wait(); while (true) { Console.WriteLine("请输入消息,输入exit退出..."); var content = Console.ReadLine(); if (string.Equals(content, "exit", StringComparison.OrdinalIgnoreCase)) { break; } var message = new AliyunMessage { Topic = "ChunSun", Body = content }; var messageId = producer.Send(message).Result; Console.WriteLine($"发送成功,MessageId:{messageId}"); } } } }
private static void Main() { using (IMessageQueueFactory messageQueueFactory = new AliyunMessageQueueFactory(new AliyunMessageQueueFactoryOptions { AccessKey = "xxxxxxxx", SecretKey = "xxxxxxxxxx" })) { Console.WriteLine("请输入消费者Id..."); var consumerId = Console.ReadLine(); using (var consumer = messageQueueFactory.CreateConsumer(consumerId).Result) { consumer.Subscribe("ChunSun", "*", message => { Console.WriteLine($"topic:{message.Topic}"); Console.WriteLine($"key:{message.Key}"); Console.WriteLine($"msdid:{message.MessageId}"); Console.WriteLine($"body:{message.Body}"); Console.WriteLine($"tag:{message.Tag}"); Console.WriteLine($"getStartDeliverTime:{message.StartDeliverTime}"); Console.WriteLine("======================================================"); return null; }); consumer.Start().Wait(); Console.WriteLine("正在监听,按任意键退出..."); Console.ReadLine(); } } }
private static void Main() { using (IMessageQueueFactory messageQueueFactory = new AliyunMessageQueueFactory(new AliyunMessageQueueFactoryOptions { AccessKey = "xxxxxxxx", SecretKey = "xxxxxxxxxx" })) { Console.WriteLine("请输入消费者Id..."); var consumerId = Console.ReadLine(); using (var consumer = messageQueueFactory.CreateConsumer(consumerId).Result) { consumer.Subscribe("ChunSun", "*", message => { Console.WriteLine($"topic:{message.Topic}"); Console.WriteLine($"key:{message.Key}"); Console.WriteLine($"msdid:{message.MessageId}"); Console.WriteLine($"body:{message.Body}"); Console.WriteLine($"tag:{message.Tag}"); Console.WriteLine($"getStartDeliverTime:{message.StartDeliverTime}"); Console.WriteLine("======================================================"); return(null); }); consumer.Start().Wait(); Console.WriteLine("正在监听,按任意键退出..."); Console.ReadLine(); } } }