public void TestMQ() { var bus = RabbitHutch.CreateBus(ConfigurationAppSetting.RabbitMQHost, reg => reg.Register <IEasyNetQLogger>(log => new Log4NetLogger())).Advanced; var queue = bus.QueueDeclare("Test"); var exchange = bus.ExchangeDeclare("JinRiNotifyExchangeTest", ExchangeType.Topic); var binding = bus.Bind(exchange, queue, ""); var properties = new MessageProperties(); for (int i = 0; i < 100; i++) { NotifyMessage mess = new NotifyMessage() { MessageId = IdentityGenerator.New(), AppId = "11011", MessagePriority = MessagePriorityEnum.High, MessageKey = MessagePriorityEnum.High.ToString(), MessageType = "OrderTicketOut", NotifyData = "a=1&b=2", SourceFrom = "test", ClientIP = "127.0.0.1" }; var body = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(mess)); bus.Publish(exchange, "", false, false, properties, body); } bus.Consume(queue, (b, ps, info) => Task.Factory.StartNew(() => { var message = Encoding.UTF8.GetString(b); RabbitMQBusiness.ComsumeMessage(JsonConvert.DeserializeObject <NotifyMessage>(message)); })); }
private void StartComsume() { RabbitMQBusiness bus = new RabbitMQBusiness(); bus.Subscribe(MessagePriorityEnum.High, Comsume); }