Example #1
0
		public async Task Should_Be_Able_To_Bulk_Get_Messages()
		{
			var firstBasicMsg = new BasicMessage { Prop = "This is the first message" };
			var secondBasicMsg = new BasicMessage { Prop = "This is the second message" };
			var thridBasicMsg = new BasicMessage { Prop = "This is the thrid message" };
			var firstSimpleMsg = new SimpleMessage { IsSimple = true };

			using (var client = TestClientFactory.CreateExtendable())
			{
				await client.PublishAsync(secondBasicMsg);
				await client.PublishAsync(firstBasicMsg);
				await client.PublishAsync(thridBasicMsg);
				await client.PublishAsync(firstSimpleMsg);
				await Task.Delay(500);

				var bulk = client.GetMessages(cfg => cfg
					.ForMessage<BasicMessage>(msg => msg
						.FromQueues(_firstBasicQueue, _secondBasicQueue)
						.WithBatchSize(4))
					.ForMessage<SimpleMessage>(msg => msg
						.FromQueues(_firstSimpleQueue)
						.GetAll()
						.WithNoAck()
					));
				var basics = bulk.GetMessages<BasicMessage>().ToList();
				var simple = bulk.GetMessages<SimpleMessage>().ToList();
				bulk.AckAll();

				Assert.Equal(expected: 4, actual: basics.Count);
				Assert.Equal(expected: 1, actual: simple.Count);
			}
		}
		public async Task Should_Be_Able_To_Recieve_Different_Types_Of_Messages()
		{
			/* Setup */
			var publisher = BusClientFactory.CreateDefault();
			var subscriber = BusClientFactory.CreateDefault();

			var basicMsg = new BasicMessage {Prop = "Hello, world!"};
			var simpleMsg = new SimpleMessage {IsSimple = true};

			var basicMsgTcs = new TaskCompletionSource<BasicMessage>();
			var simpleMsgTcs = new TaskCompletionSource<SimpleMessage>();

			subscriber.SubscribeAsync<BasicMessage>((msg, i) =>
			{
				basicMsgTcs.SetResult(msg);
				return basicMsgTcs.Task;
			});
			subscriber.SubscribeAsync<SimpleMessage>((msg, i) =>
			{
				simpleMsgTcs.SetResult(msg);
				return basicMsgTcs.Task;
			});

			/* Test */
			publisher.PublishAsync(basicMsg);
			publisher.PublishAsync(simpleMsg);
			Task.WaitAll(basicMsgTcs.Task, simpleMsgTcs.Task);

			/* Assert */
			Assert.Equal(basicMsgTcs.Task.Result.Prop, basicMsg.Prop);
			Assert.Equal(simpleMsgTcs.Task.Result.IsSimple, simpleMsg.IsSimple);
		}
Example #3
0
		public void Should_Be_Able_To_Bulk_Get_Messages()
		{
			var firstBasicMsg = new BasicMessage { Prop = "This is the first message" };
			var secondBasicMsg = new BasicMessage { Prop = "This is the second message" };
			var thridBasicMsg = new BasicMessage { Prop = "This is the thrid message" };
			var firstSimpleMsg = new SimpleMessage { IsSimple = true };

			var client = RawRabbitFactory.GetExtendableClient() as ExtendableBusClient<MessageContext>;
			client.PublishAsync(secondBasicMsg);
			client.PublishAsync(firstBasicMsg);
			client.PublishAsync(thridBasicMsg);
			client.PublishAsync(firstSimpleMsg);

			var bulk = client.GetMessages(cfg => cfg
				.ForMessage<BasicMessage>(msg => msg
					.FromQueues(_firstBasicQueue, _secondBasicQueue)
					.WithBatchSize(4))
				.ForMessage<SimpleMessage>(msg => msg
					.FromQueues(_firstSimpleQueue)
					.GetAll()
					.WithNoAck()
				));
			var basics = bulk.GetMessages<BasicMessage>().ToList();
			var simple = bulk.GetMessages<SimpleMessage>().ToList();
			bulk.AckAll();
			
			Assert.Equal(basics.Count, 4);
			Assert.Equal(simple.Count, 1);
		}