/// <summary> /// 在订阅者的构造中注册事件 /// </summary> /// <param name="sender"></param> public BaseEventSubscriber(BaseEventSender sender) { this.factory = new ConnectionFactory(); factory.HostName = "localhost"; factory.UserName = "******"; factory.Password = "******"; sender.OnDataChange += new BaseEventSender.MqHandler(this.BaseSubscriberProxyMethod); }
/// <summary> /// 测试方法 /// </summary> /// <param name="args"></param> static void Main(string[] args) { BaseEventSender sender = new BaseEventSender(1000); BaseEventSubscriber subscriber = new BaseEventSubscriber(sender); sender.Run(); RabbitMqMessageReceiver receiver = new RabbitMqMessageReceiver(); receiver.ReceiveMessage(); Console.ReadKey(); }
/// <summary> /// 反注册事件 /// </summary> /// <param name="sender"></param> public void UnRegisterBaseEventSender(BaseEventSender sender) { sender.OnDataChange -= new BaseEventSender.MqHandler(this.BaseSubscriberProxyMethod); }