/// <summary> /// 发布一条指定了特定routerKey的消息 /// </summary> /// <param name="msg">消息内容</param> /// <param name="routerKey">消息特定标识</param> /// <returns>bool</returns> public static bool Publish(MQProtocol <M> msg, string routerKey) { msg.ExChange = ExchangeConst.DefaultExchange; msg.RouterKey = routerKey; using (DefaultPublisher <MQProtocol <M> > p = new DefaultPublisher <MQProtocol <M> >(msg, routerKey, false)) { return(p.Publish()); } }
/// <summary> /// 指定虚拟机,发送特定routerKey的消息 /// </summary> /// <param name="msg">msg</param> /// <param name="routerKey">routerKey</param> /// <param name="host">host</param> /// <returns>bool</returns> public static bool Publish(MQProtocol <M> msg, string routerKey, VirtualHost host) { msg.ExChange = ExchangeConst.DefaultExchange; msg.RouterKey = routerKey; using (DefaultPublisher <MQProtocol <M> > p = new DefaultPublisher <MQProtocol <M> >(msg, ExchangeConst.DefaultExchange, routerKey, MQueueConst.DefaultGrantMQ, false, host)) { // consumers.Add(p); return(p.Publish()); } }