Beispiel #1
0
        public void SqsPublishFlow_batch_should_send_messages_to_SQS_in_batches()
        {
            client.SendMessageBatchAsync(Arg.Any <SendMessageBatchRequest>()).Returns(req =>
                                                                                      Task.FromResult(new SendMessageBatchResponse
            {
                Failed     = new List <BatchResultErrorEntry>(0),
                Successful = ((SendMessageBatchRequest)req[0]).Entries
                             .Select(e => new SendMessageBatchResultEntry
                {
                    Id = e.Id
                }).ToList()
            }));

            var publisher  = this.CreatePublisherProbe <string[]>();
            var subscriber = this.CreateSubscriberProbe <string[]>();

            Source.FromPublisher(publisher)
            .Select(msgs => msgs.Select(msg => new SendMessageRequest(TestQueueUrl, msg)))
            .Via(SqsPublishFlow.Batch(client, TestQueueUrl))
            .Select(list => list.Select(x => x.Request.MessageBody).ToArray())
            .To(Sink.FromSubscriber(subscriber))
            .Run(materializer);

            subscriber.Request(2);

            publisher.SendNext(new[] { "a-1", "a-2" });
            publisher.SendNext(new[] { "b-1", "b-2", "b-3" });

            subscriber.ExpectNext <string[]>(x => x.SequenceEqual(new[] { "a-1", "a-2" }));
            subscriber.ExpectNext <string[]>(x => x.SequenceEqual(new[] { "b-1", "b-2", "b-3" }));

            subscriber.Cancel();
        }
Beispiel #2
0
        public void SqsPublishFlow_batch_should_fail_downstream_on_partial_failures()
        {
            client.SendMessageBatchAsync(Arg.Any <SendMessageBatchRequest>()).Returns(req =>
            {
                var request = ((SendMessageBatchRequest)req[0]);
                var success = request.Entries[0];
                var failure = request.Entries[1];
                return(Task.FromResult(new SendMessageBatchResponse
                {
                    Failed = new List <BatchResultErrorEntry>
                    {
                        new BatchResultErrorEntry {
                            Code = "Test Error", Id = failure.Id
                        }
                    },
                    Successful = new List <SendMessageBatchResultEntry>
                    {
                        new SendMessageBatchResultEntry {
                            Id = success.Id
                        }
                    }
                }));
            });

            var publisher  = this.CreatePublisherProbe <string[]>();
            var subscriber = this.CreateSubscriberProbe <string[]>();

            Source.FromPublisher(publisher)
            .Select(msgs => msgs.Select(msg => new SendMessageRequest(TestQueueUrl, msg)))
            .Via(SqsPublishFlow.Batch(client, TestQueueUrl))
            .Select(list => list.Select(x => x.Request.MessageBody).ToArray())
            .To(Sink.FromSubscriber(subscriber))
            .Run(materializer);

            subscriber.Request(2);

            publisher.SendNext(new[] { "a-1", "a-2" });
            publisher.SendNext(new[] { "b-1", "b-2" });

            subscriber.ExpectError();
        }