RawRabbit.Channel.ChannelFactory.GetChannelAsync C# (CSharp) Method

GetChannelAsync() public method

public GetChannelAsync ( ) : Task
return Task
		public Task<IModel> GetChannelAsync()
		{
			var tcs = new TaskCompletionSource<IModel>();
			_requestQueue.Enqueue(tcs);
			if (_connection.IsOpen)
			{
				EnsureRequestsAreHandled();
			}
			else
			{
				var recoverable = _connection as IRecoverable;
				if (recoverable == null)
				{
					throw new ChannelAvailabilityException("Unable to retrieve chanel. Connection to broker is closed and not recoverable.");
				}
			}
			return tcs.Task;
		}

Usage Example

		public async Task Should_Round_Robin_Between_Existing_Channels()
		{
			/* Setup */
			_channelConfig.MaxChannelCount = 3;
			_channelConfig.InitialChannelCount = 3;
			_connection
				.Setup(c => c.IsOpen)
				.Returns(true);
			_connection
				.SetupSequence(c => c.CreateModel())
				.Returns(_thirdChannel.Object)
				.Returns(_firstChannel.Object)
				.Returns(_secondChannel.Object);
			_firstChannel
				.Setup(c => c.IsOpen)
				.Returns(true);
			_secondChannel
				.Setup(c => c.IsOpen)
				.Returns(true);
			_thirdChannel
				.Setup(c => c.IsOpen)
				.Returns(true);
			var factory = new ChannelFactory(_connectionFactory.Object, _config, _channelConfig);

			/* Test */
			var first = await factory.GetChannelAsync();
			var second = await factory.GetChannelAsync();
			var third = await factory.GetChannelAsync();
			var firstAgain = await factory.GetChannelAsync();
			var secondAgain = await factory.GetChannelAsync();
			var thirdAgain = await factory.GetChannelAsync();

			/* Assert */
			Assert.Equal(first, _firstChannel.Object);
			Assert.Equal(second, _secondChannel.Object);
			Assert.Equal(third, _thirdChannel.Object);
			Assert.Equal(firstAgain, _firstChannel.Object);
			Assert.Equal(secondAgain, _secondChannel.Object);
			Assert.Equal(thirdAgain, _thirdChannel.Object);
		}
All Usage Examples Of RawRabbit.Channel.ChannelFactory::GetChannelAsync