示例#1
0
		public async Task Should_Perform_Rpc_Without_Direct_Reply_To()
		{
			/* Setup */
			var response = new BasicResponse { Prop = "This is the response." };
			var requester = BusClientFactory.CreateDefault();
			var responder = BusClientFactory.CreateDefault();
			responder.RespondAsync<BasicRequest, BasicResponse>((req, i) =>
			{
				return Task.FromResult(response);
			});

			/* Test */
			var firstRecieved = await requester.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest(),
				configuration: cfg => cfg
					.WithReplyQueue(
						q => q
							.WithName("special_reply_queue")
							.WithAutoDelete())
					.WithNoAck(false));
			var secondRecieved = await requester.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest(),
				configuration: cfg => cfg
					.WithReplyQueue(
						q => q
							.WithName("another_special_reply_queue")
							.WithAutoDelete())
					.WithNoAck(false)
			);

			/* Assert */
			Assert.Equal(expected: response.Prop, actual: firstRecieved.Prop);
			Assert.Equal(expected: response.Prop, actual: secondRecieved.Prop);
		}
示例#2
0
		public async void Should_Be_Able_To_Nack_Message()
		{
			/* Setup */
			var service = new ServiceCollection()
				.AddRawRabbit<AdvancedMessageContext>()
				.BuildServiceProvider();

			var firstResponder = service.GetService<IBusClient<AdvancedMessageContext>>();
			var secondResponder = service.GetService<IBusClient<AdvancedMessageContext>>();
			var requester = service.GetService<IBusClient<AdvancedMessageContext>>();

			var hasBeenNacked = false;
			firstResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
			{
				BasicResponse response = null;
				if (!hasBeenNacked)
				{
					context?.Nack();
					hasBeenNacked = true;
				}
				else
				{
					response = new BasicResponse();
				}
				return Task.FromResult(response);
			}, c => c.WithNoAck(false));
			secondResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
			{
				BasicResponse response = null;
				if (!hasBeenNacked)
				{
					context?.Nack();
					hasBeenNacked = true;
				}
				else
				{
					response = new BasicResponse();
				}
				return Task.FromResult(response);
			}, c => c.WithNoAck(false));

			/* Test */
			var result = await requester.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest(), configuration: cfg => cfg
					 .WithReplyQueue(
						 q => q.WithName("special_reply_queue")));

			/* Assert */
			Assert.NotNull(result);
			Assert.True(hasBeenNacked);
		}
示例#3
0
		public async Task Should_Be_Able_To_Nack_Message()
		{
			/* Setup */
			using (var firstResponder = TestClientFactory.CreateNormal<AdvancedMessageContext>())
			using (var secondResponder = TestClientFactory.CreateNormal<AdvancedMessageContext>())
			using (var requester = TestClientFactory.CreateNormal<AdvancedMessageContext>())
			{

				var hasBeenNacked = false;
				firstResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
				{
					BasicResponse response = null;
					if (!hasBeenNacked)
					{
						context?.Nack();
						hasBeenNacked = true;
					}
					else
					{
						response = new BasicResponse();
					}
					return Task.FromResult(response);
				}, c => c.WithNoAck(false));
				secondResponder.RespondAsync<BasicRequest, BasicResponse>((request, context) =>
				{
					BasicResponse response = null;
					if (!hasBeenNacked)
					{
						context?.Nack();
						hasBeenNacked = true;
					}
					else
					{
						response = new BasicResponse();
					}
					return Task.FromResult(response);
				}, c => c.WithNoAck(false));

				/* Test */
				var result = await requester.RequestAsync<BasicRequest, BasicResponse>(new BasicRequest(), configuration: cfg => cfg
						 .WithReplyQueue(
							 q => q.WithName("special_reply_queue")));

				/* Assert */
				Assert.NotNull(result);
				Assert.True(hasBeenNacked);
			}
		}
示例#4
0
		public async Task Should_Perform_Basic_Rpc_Without_Any_Config()
		{
			/* Setup */
			var response = new BasicResponse { Prop = "This is the response." };
			var requester = BusClientFactory.CreateDefault();
			var responder = BusClientFactory.CreateDefault();
			responder.RespondAsync<BasicRequest, BasicResponse>((req, i) =>
			{
				return Task.FromResult(response);
			});

			/* Test */
			var recieved = await requester.RequestAsync<BasicRequest, BasicResponse>();

			/* Assert */
			Assert.Equal(recieved.Prop, response.Prop);
		}
示例#5
0
		public async Task Should_Perform_Basic_Rpc_Without_Any_Config()
		{
			/* Setup */
			using (var requester = TestClientFactory.CreateNormal())
			using (var responder = TestClientFactory.CreateNormal())
			{
				var response = new BasicResponse { Prop = "This is the response." };
				responder.RespondAsync<BasicRequest, BasicResponse>((req, i) =>
				{
					return Task.FromResult(response);
				});

				/* Test */
				var recieved = await requester.RequestAsync<BasicRequest, BasicResponse>();

				/* Assert */
				Assert.Equal(expected: response.Prop, actual: recieved.Prop);
			}
		}
示例#6
0
		public async Task Should_Work_With_Queueing_Consumer_Factory()
		{
			/* Setup */
			var response = new BasicResponse { Prop = "This is the response." };
			var requester = BusClientFactory.CreateDefault();

			var responder = BusClientFactory.CreateDefault(service => service.AddTransient<IConsumerFactory, QueueingBaiscConsumerFactory>());
			responder.RespondAsync<BasicRequest, BasicResponse>((req, i) => Task.FromResult(response));

			/* Test */
			var recieved = await requester.RequestAsync<BasicRequest, BasicResponse>();

			/* Assert */
			Assert.Equal(recieved.Prop, response.Prop);
		}