public async Task <string> AddConsumer(string queue, string consumerTag, IBasicConsumer consumer) { await semaphore.WaitAsync(); try { bool autoAck = false; bool noLocal = false; bool exclusive = false; IDictionary <String, Object> arguments = null; var sanitizedArguments = RabbitSetupSetting.GetSanitizedArguments(arguments); return(Model.BasicConsume(queue, autoAck, consumerTag, noLocal, exclusive, sanitizedArguments, consumer)); } finally { semaphore.Release(); } }
public async Task <IRabbitChannel> GetOrEstablishChannelAsync() { if (channel != null) { return(channel); } await semaphore.WaitAsync(); IsConnecting = true; // check again as another task may have established the channel while we awaited the semaphore if (channel != null) { IsConnecting = false; return(channel); } try { connection = RabbitSetupSetting.GetConnection(options); connection.CallbackException += ConnectionCallbackExceptionHandler; connection.ConnectionRecoveryError += ConnectionRecoveryErrorHandler; var model = RabbitSetupSetting.GetChannel(connection); channel = new RabbitChannel(model, options.Endpoint.Hostname); RabbitSetupSetting.StartExchanges(model, options.Exchanges.Values); return(channel); } catch (BrokerUnreachableException) { //retryTimer.Reset(TimeSpan.FromSeconds(5)); return(null); } finally { IsConnecting = false; semaphore.Release(); } }