C#:
消费:
var factoryGet = new ConnectionFactory();
factoryGet.HostName = "127.0.0.1";
factoryGet.UserName = "guest";
factoryGet.Password = "guest";
var connectionGet = factoryGet.CreateConnection();
var channelGet = connectionGet.CreateModel();
channelGet.QueueDeclare("test", true, false, false, null);
var consumerGet = new QueueingBasicConsumer(channelGet);
channelGet.BasicConsume("test", false, consumerGet);
while (true)
{
var ea = (BasicDeliverEventArgs)consumerGet.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
}
发布:
var factoryPut = new ConnectionFactory();
factoryPut.HostName = "127.0.0.1";
factoryPut.UserName = "guest";
factoryPut.Password = "guest";
var connectionPut = factoryPut.CreateConnection();
var channelPut = connectionPut.CreateModel();
channelPut.ExchangeDeclare("test", "topic", true);
channelPut.QueueDeclare("test", true, false, false);
var result = await Browser1688PicSearch.BrowserInstance.GetBrowser().MainFrame.GetSourceAsync();
//记录到rq中
var properties = channelPut.CreateBasicProperties();
properties.DeliveryMode = 2;
channelPut.BasicPublish("", "test", properties, Encoding.UTF8.GetBytes("test"));
connectionPut.Close();