コード例 #1
0
        private static List <string> GetAllQueues(RegionEndpoint regionEndpoint, string queueName)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);
            var topics = client.ListQueues(new ListQueuesRequest());

            return(topics.QueueUrls.Where(x => x.IndexOf(queueName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList());
        }
コード例 #2
0
        public IAmazonSQS GetSqsClient(RegionEndpoint region)
        {
            var innerClient = CreateMeABus.DefaultClientFactory().GetSqsClient(region);
            var client      = Substitute.For <IAmazonSQS>();

            client.ListQueuesAsync(Arg.Any <ListQueuesRequest>())
            .ReturnsForAnyArgs(r => innerClient.ListQueuesAsync(r.Arg <ListQueuesRequest>(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("ListQueues", r.Arg <ListQueuesRequest>().QueueNamePrefix, r.Arg <ListQueuesRequest>()));

            client.CreateQueueAsync(Arg.Any <CreateQueueRequest>())
            .ReturnsForAnyArgs(r => innerClient.CreateQueueAsync(r.Arg <CreateQueueRequest>(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("CreateQueue", r.Arg <CreateQueueRequest>().QueueName, r.Arg <CreateQueueRequest>()));

            client.CreateQueueAsync(Arg.Any <string>())
            .ReturnsForAnyArgs(r => innerClient.CreateQueueAsync(r.Arg <string>(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("CreateQueue", r.Arg <string>()));

            client.GetQueueAttributesAsync(Arg.Any <GetQueueAttributesRequest>())
            .ReturnsForAnyArgs(r => innerClient.GetQueueAttributesAsync(r.Arg <GetQueueAttributesRequest>(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("GetQueueAttributes", r.Arg <GetQueueAttributesRequest>().QueueUrl, r.Arg <GetQueueAttributesRequest>()));

            client.GetQueueAttributesAsync(Arg.Any <string>(), Arg.Any <List <string> >())
            .ReturnsForAnyArgs(r => innerClient.GetQueueAttributesAsync(r.Arg <string>(), r.Arg <List <string> >(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("GetQueueAttributes", r.Arg <string>(), r.Arg <List <string> >()));

            client.ReceiveMessageAsync(Arg.Any <ReceiveMessageRequest>())
            .ReturnsForAnyArgs(r => innerClient.ReceiveMessageAsync(r.Arg <ReceiveMessageRequest>(), r.Arg <CancellationToken>()))
            .AndDoes(r => Increment("ReceiveMessageAsync", r.Arg <ReceiveMessageRequest>().QueueUrl, r.Arg <ReceiveMessageRequest>()));

            return(client);
        }
コード例 #3
0
        [Then, Timeout(70000)] // ToDo: Sorry about this, but SQS is a little slow to verify against. Can be better I'm sure? ;)
        public async Task QueueIsCreated()
        {
            var queue = new SqsQueueByName(RegionEndpoint.EUWest1,
                                           QueueName, CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1), 0);

            await Patiently.AssertThatAsync(
                queue.Exists, TimeSpan.FromSeconds(65));
        }
コード例 #4
0
        private static void DeleteQueue(RegionEndpoint regionEndpoint, string queueUrl)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);

            client.DeleteQueue(new DeleteQueueRequest {
                QueueUrl = queueUrl
            });
        }
コード例 #5
0
 protected override SnsTopicByName CreateSystemUnderTest()
 {
     Bus          = CreateMeABus.DefaultClientFactory().GetSnsClient(RegionEndpoint.EUWest1);
     UniqueName   = "test" + DateTime.Now.Ticks;
     CreatedTopic = new SnsTopicByName(UniqueName, Bus, new MessageSerialisationRegister(), new LoggerFactory());
     CreatedTopic.Create();
     return(CreatedTopic);
 }
コード例 #6
0
        // ToDo: All these can go because we have already implemented them in AwsTools... Seriously. Wasted effort.

        protected static void DeleteTopic(RegionEndpoint regionEndpoint, Topic topic)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSnsClient(regionEndpoint);

            client.DeleteTopic(new DeleteTopicRequest {
                TopicArn = topic.TopicArn
            });
        }
コード例 #7
0
        protected override SqsQueueByName CreateSystemUnderTest()
        {
            QueueUniqueKey = "test" + DateTime.Now.Ticks;
            var queue = new SqsQueueByName(RegionEndpoint.EUWest1, QueueUniqueKey, CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1), 1);

            queue.Exists();
            return(queue);
        }
コード例 #8
0
        protected bool QueueHasPolicyForTopic(RegionEndpoint regionEndpoint, Topic topic, string queueUrl)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);

            var policy = client.GetQueueAttributes(new GetQueueAttributesRequest {
                QueueUrl = queueUrl, AttributeNames = new List <string> {
                    "Policy"
                }
            }).Policy;

            return(policy.Contains(topic.TopicArn));
        }
コード例 #9
0
        public IAmazonSimpleNotificationService GetSnsClient(RegionEndpoint region)
        {
            var innerClient = CreateMeABus.DefaultClientFactory().GetSnsClient(region);
            var client      = Substitute.For <IAmazonSimpleNotificationService>();

            client.CreateTopic(Arg.Any <CreateTopicRequest>())
            .ReturnsForAnyArgs(r => innerClient.CreateTopic(r.Arg <CreateTopicRequest>()))
            .AndDoes(r => Increment("CreateTopic", r.Arg <CreateTopicRequest>().Name, r.Arg <CreateTopicRequest>()));

            client.FindTopic(Arg.Any <string>())
            .ReturnsForAnyArgs(r => innerClient.FindTopic(r.Arg <string>()))
            .AndDoes(r => Increment("FindTopic", r.Arg <string>(), r.Arg <string>()));

            return(client);
        }
コード例 #10
0
        protected override void Given()
        {
            base.Given();

            TopicName = "CustomerCommunication";
            QueueName = "queuename-" + DateTime.Now.Ticks;

            EnableMockedBus();

            Configuration = new MessagingConfig();

            DeleteTopicIfItAlreadyExists(TestEndpoint, TopicName).Wait();
            DeleteQueueIfItAlreadyExists(TestEndpoint, QueueName).Wait();
            Client = CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1);
        }
        public IAmazonSimpleNotificationService GetSnsClient(RegionEndpoint region)
        {
            var innerClient = CreateMeABus.DefaultClientFactory().GetSnsClient(region);
            var client      = Substitute.For <IAmazonSimpleNotificationService>();

            client.CreateTopicAsync(Arg.Any <CreateTopicRequest>())
            .ThrowsForAnyArgs(x => new AuthorizationErrorException("Denied"));

            client.FindTopicAsync(Arg.Any <string>())
            .ReturnsForAnyArgs(r => innerClient.FindTopicAsync(r.Arg <string>()));

            client.GetTopicAttributesAsync(Arg.Any <string>())
            .ReturnsForAnyArgs(r => innerClient.GetTopicAttributesAsync(r.Arg <string>()));

            return(client);
        }
コード例 #12
0
        private static List <Topic> GetAllTopics(RegionEndpoint regionEndpoint, string topicName)
        {
            var    client    = CreateMeABus.DefaultClientFactory().GetSnsClient(regionEndpoint);
            var    topics    = new List <Topic>();
            string nextToken = null;

            do
            {
                var topicsResponse = client.ListTopics(new ListTopicsRequest {
                    NextToken = nextToken
                });
                nextToken = topicsResponse.NextToken;
                topics.AddRange(topicsResponse.Topics);
            } while (nextToken != null);

            return(topics.Where(x => x.TopicArn.IndexOf(topicName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList());
        }
コード例 #13
0
        protected bool IsQueueSubscribedToTopic(RegionEndpoint regionEndpoint, Topic topic, string queueUrl)
        {
            var request = new GetQueueAttributesRequest {
                QueueUrl = queueUrl, AttributeNames = new List <string> {
                    "QueueArn"
                }
            };

            var sqsclient = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);

            var queueArn = sqsclient.GetQueueAttributes(request).QueueARN;

            var client = new AmazonSimpleNotificationServiceClient(regionEndpoint);

            var subscriptions = client.ListSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topic.TopicArn)).Subscriptions;

            return(subscriptions.Any(x => !string.IsNullOrEmpty(x.SubscriptionArn) && x.Endpoint == queueArn));
        }
コード例 #14
0
        protected async Task <bool> QueueHasPolicyForTopic(RegionEndpoint regionEndpoint, Topic topic, string queueUrl)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);

            var policy =
                (await client.GetQueueAttributesAsync(new GetQueueAttributesRequest
            {
                QueueUrl = queueUrl,
                AttributeNames = new List <string> {
                    "Policy"
                }
            })).Policy;

            int    pos = topic.TopicArn.LastIndexOf(':');
            string wildcardedSubscription = topic.TopicArn.Substring(0, pos + 1) + "*";

            return(policy.Contains(topic.TopicArn) || policy.Contains(wildcardedSubscription));
        }
コード例 #15
0
 public IAmazonSimpleNotificationService CreateSnsClient()
 => CreateMeABus.DefaultClientFactory().GetSnsClient(Region);
コード例 #16
0
 public WhenOptingOutOfErrorQueue()
 {
     _client = CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1);
 }
コード例 #17
0
 public WhenOptingOutOfErrorQueue(ITestOutputHelper outputHelper)
 {
     Region        = TestEnvironment.Region;
     LoggerFactory = outputHelper.ToLoggerFactory();
     _client       = CreateMeABus.DefaultClientFactory().GetSqsClient(Region);
 }
コード例 #18
0
 protected override ErrorQueue CreateSystemUnderTest()
 {
     QueueUniqueKey = "test" + DateTime.Now.Ticks;
     return(new ErrorQueue(RegionEndpoint.EUWest1, QueueUniqueKey, CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1), new LoggerFactory()));
 }
 public IAmazonSQS GetSqsClient(RegionEndpoint region)
 => CreateMeABus.DefaultClientFactory().GetSqsClient(region);
コード例 #20
0
        // Use this to manually test the performance / throttling of getting messages out of the queue.
        public async Task HandlingManyMessages(int throttleMessageCount)
        {
            var locker         = new object();
            var awsQueueClient = CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1);

            var q = new SqsQueueByName(RegionEndpoint.EUWest1, "throttle_test", awsQueueClient, 1, new LoggerFactory());

            if (!await q.ExistsAsync())
            {
                await q.CreateAsync(new SqsBasicConfiguration());

                await Task.Delay(TimeSpan.FromMinutes(1));  // wait 60 secs for queue creation to be guaranteed completed by aws. :(
            }

            Assert.True(await q.ExistsAsync());

            Console.WriteLine($"{DateTime.Now} - Adding {throttleMessageCount} messages to the queue.");

            var entriesAdded = 0;

            // Add some messages
            do
            {
                var entries = new List <SendMessageBatchRequestEntry>();
                for (var j = 0; j < 10; j++)
                {
                    var batchEntry = new SendMessageBatchRequestEntry
                    {
                        MessageBody = "{\"Subject\":\"GenericMessage\", \"Message\": \"" + entriesAdded.ToString() + "\"}",
                        Id          = Guid.NewGuid().ToString()
                    };
                    entries.Add(batchEntry);
                    entriesAdded++;
                }
                await awsQueueClient.SendMessageBatchAsync(new SendMessageBatchRequest { QueueUrl = q.Url, Entries = entries });
            }while (entriesAdded < throttleMessageCount);

            Console.WriteLine($"{DateTime.Now} - Done adding messages.");

            var handleCount    = 0;
            var serialisations = Substitute.For <IMessageSerialisationRegister>();
            var monitor        = Substitute.For <IMessageMonitor>();
            var handler        = Substitute.For <IHandlerAsync <GenericMessage> >();

            handler.Handle(null).ReturnsForAnyArgs(true).AndDoes(x => { lock (locker) { handleCount++; } });

            serialisations.DeserializeMessage(string.Empty).ReturnsForAnyArgs(new GenericMessage());
            var listener = new SqsNotificationListener(q, serialisations, monitor, new LoggerFactory());

            listener.AddMessageHandler(() => handler);

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            listener.Listen();
            var waitCount = 0;

            do
            {
                await Task.Delay(TimeSpan.FromSeconds(5));

                Console.WriteLine($"{DateTime.Now} - Handled {handleCount} messages. Waiting for completion.");
                waitCount++;
            }while (handleCount < throttleMessageCount && waitCount < 100);

            listener.StopListening();
            stopwatch.Stop();

            Console.WriteLine($"{DateTime.Now} - Handled {handleCount} messages.");
            Console.WriteLine($"{DateTime.Now} - Took {stopwatch.ElapsedMilliseconds} ms");
            Console.WriteLine(
                $"{DateTime.Now} - Throughput {(float) handleCount/stopwatch.ElapsedMilliseconds*1000} msg/sec");
            Assert.Equal(throttleMessageCount, handleCount);
        }
コード例 #21
0
 public IAmazonSQS CreateSqsClient()
 => CreateMeABus.DefaultClientFactory().GetSqsClient(Region);
コード例 #22
0
 public void SetUp()
 {
     _client = CreateMeABus.DefaultClientFactory().GetSqsClient(RegionEndpoint.EUWest1);
 }
コード例 #23
0
        public IAmazonSQS GetSqsClient(RegionEndpoint region)
        {
            var innerClient = CreateMeABus.DefaultClientFactory().GetSqsClient(region);

            return(innerClient);
        }