/// <summary> /// 消费消息 /// </summary> /// <param name="exchange"></param> /// <param name="queue"></param> /// <param name="configure"></param> /// <param name="received"></param> /// <returns></returns> public ListenResult Listen(string exchange, string queue, Action <ExchangeConsumeQueueOptions> configure, Action <RecieveResult> received = null) { ExchangeConsumeQueueOptions options = new ExchangeConsumeQueueOptions(); configure?.Invoke(options); return(Listen(exchange, queue, options, received)); }
/// <summary> /// 消费消息 /// </summary> /// <param name="exchange"></param> /// <param name="queue"></param> /// <param name="options"></param> /// <param name="received"></param> /// <returns></returns> public ListenResult Listen(string exchange, string queue, ExchangeConsumeQueueOptions options = null, Action <RecieveResult> received = null) { if (string.IsNullOrEmpty(exchange)) { throw new ArgumentException("exchange cannot be empty", nameof(exchange)); } if (options.Type == RabbitExchangeType.None) { throw new NotSupportedException($"{nameof(RabbitExchangeType)} must be specified"); } options = options ?? new ExchangeConsumeQueueOptions(); var channel = GetChannel(); PrepareExchangeChannel(channel, exchange, options); return(ConsumeInternal(channel, queue, options.AutoAck, options.FetchCount, received)); }