Exemplo n.º 1
0
        /// <summary>
        /// 采取线程的方式,向指定的队列发送
        /// </summary>
        static void PublishMQ(string exchangeName, string routingKey, int count, CancellationToken cancellationToken)
        {
            RabbitMQClient c1 = new RabbitMQClient(ipAddress, "", port, userName, pwd);

            //创建一个exchange
            c1.ManagerInstance.ExchangeDeclare(exchangeName, RabbitExchangeType.Topic);

            Task taskPublish = Task.Factory.StartNew(() =>
            {
                int num = 0;
                while (!cancellationToken.IsCancellationRequested)
                {
                    Thread.Sleep(1000);
                    Dictionary <string, object> header = new Dictionary <string, object>();
                    c1.PublisherInstance.Publish(exchangeName, header, string.Format("这是第{0}条消息,发送时间{1:HH:mm:ss}", ++num, DateTime.Now), true, routingKey);
                }
                c1.Dispose();
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// 停止接收
 /// </summary>
 public void StopReceive()
 {
     m_RabbitMQ.Dispose();
 }