Пример #1
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="msg"></param>
        public static void Subscribe(Message msg, IProcessMessage ipro)
        {
            //// 创建消息bus
            //using (IBus bus = BusBuilder.CreateMessageBus())
            //{
            //    try
            //    {
            //        bus.Subscribe<Message>(msg.MessageRouter, message => ipro.ProcessMsg(message), x => x.WithTopic(msg.MessageRouter));
            //    }
            //    catch (EasyNetQException ex)
            //    {
            //        //处理连接消息服务器异常
            //    }

            //}

            //// 创建消息bus
            IBus bus = BusBuilder.CreateMessageBus();

            try
            {
                bus.Subscribe <Message>(msg.MessageRouter, message => ipro.ProcessMsg(message), x => x.WithTopic(msg.MessageRouter));
            }
            catch (EasyNetQException ex)
            {
                //处理连接消息服务器异常
            }
        }
Пример #2
0
 /// <summary>
 /// 发送消息
 /// </summary>
 public static void Publish(Message msg)
 {
     //// 创建消息bus
     using (IBus bus = BusBuilder.CreateMessageBus())
     {
         try
         {
             bus.Publish(msg, x => x.WithTopic(msg.MessageRouter));
         }
         catch (EasyNetQException ex)
         {
             //处理连接消息服务器异常
         }
     }
 }