/// <summary> /// 生产者发布字符串 /// </summary> static void PublishString() { IProducer producer = SingleConnectionTool.Connection.CreateProducer("TestExchange");//此处是交换机名称 while (true) { string msg = Console.ReadLine(); if ("quit".Equals(msg)) { // 退出要把所有资源都关闭 producer.Close(); SingleConnectionTool.Close(); return; } producer.Publish(msg, "TestKey1");//此处是绑定key } }
/// <summary> /// 生产者发布字符串 /// </summary> static void PublishString() { //IProducer producer = SingleConnectionTool.Connection.CreateProducer("TestExchange");//此处是交换机名称 var conn = SingleConnectionTool.CreateConnectionFromConfigName("MessageQueue:RabbitConnectionString_vtest"); IProducer producer = conn.CreateProducer("TestExchange2");//此处是交换机名称 while (true) { string msg = Console.ReadLine(); if ("quit".Equals(msg)) { // 退出要把所有资源都关闭 producer.Close(); SingleConnectionTool.Close(); return; } producer.Publish(msg, "TestKey1");//此处是绑定key } }
public void Dispose() { // Close queue interfaces _actionRequestConsumer.Close(); _actionResponseProducer.Close(); }