コード例 #1
0
 private void AndAPublisherToTheSecondaryRegion(string secondaryRegion)
 {
     _secondaryPublisher = CreateMeABus
                           .WithLogging(new LoggerFactory())
                           .InRegion(secondaryRegion)
                           .WithSqsMessagePublisher <GenericMessage>(configuration => { });
 }
コード例 #2
0
        protected async Task Act()
        {
            _sampleHandler = new SampleHandler();
            var publisher = CreateMeABus.WithLogging(new LoggerFactory())
                            .InRegion(region)
                            .WithSnsMessagePublisher <GenericMessage>();

            var bus = CreateMeABus.WithLogging(new LoggerFactory())
                      .InRegion(region)
                      .WithMonitoring(Substitute.For <IMessageMonitor>())
                      .WithMessageLockStoreOf(new MessageLockStore())
                      .WithSqsTopicSubscriber()
                      .IntoQueue(QueueName)
                      .ConfigureSubscriptionWith(cfg =>
            {
                cfg.MessageRetentionSeconds = 60;
            }).WithMessageHandler(_sampleHandler);

            publisher.StartListening();
            bus.StartListening();

            await publisher.PublishAsync(_message);

            await publisher.PublishAsync(_message);
        }
コード例 #3
0
        protected override IAmJustSayingFluently CreateSystemUnderTest()
        {
            var handler = Substitute.For <IHandler <GenericMessage> >();

            handler.When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(x => _handler.Complete((GenericMessage)x.Args()[0]));

            Monitoring = Substitute.For <IMessageMonitor>();

            ServiceBus = CreateMeABus.InRegion(RegionEndpoint.EUWest1.SystemName)
                         .WithMonitoring(Monitoring)
                         .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = _config.PublishFailureBackoffMilliseconds;
                c.PublishFailureReAttempts          = _config.PublishFailureReAttempts;
            })
                         .WithSnsMessagePublisher <GenericMessage>()
                         .WithSqsTopicSubscriber()
                         .IntoQueue("queuename")
                         .ConfigureSubscriptionWith(cf =>
            {
                cf.MessageRetentionSeconds  = 60;
                cf.VisibilityTimeoutSeconds = JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT;
                cf.InstancePosition         = 1;
            })
                         .WithMessageHandler(handler);

            ServiceBus.StartListening();
            return(ServiceBus);
        }
コード例 #4
0
 private IMayWantOptionalSettings GetBus(AWSCredentials credentials)
 {
     return(CreateMeABus
            .WithLogging(LoggerFactory)
            .InRegion(TestEnvironment.Region.SystemName)
            .WithAwsClientFactory(() => new DefaultAwsClientFactory(credentials)));
 }
コード例 #5
0
        protected override JustSaying.JustSayingFluently CreateSystemUnderTest()
        {
            var fns = CreateMeABus.InRegion(Configuration.Region)
                      .WithMonitoring(null)
                      .ConfigurePublisherWith(x =>
            {
                x.PublishFailureBackoffMilliseconds = Configuration.PublishFailureBackoffMilliseconds;
                x.PublishFailureReAttempts          = Configuration.PublishFailureReAttempts;
            }) as JustSaying.JustSayingFluently;

            if (_mockNotificationStack)
            {
                NotificationStack = Substitute.For <IAmJustSaying>();

                var notificationStackField = fns.GetType().GetField("Bus", BindingFlags.Instance | BindingFlags.NonPublic);

                var constructedStack = (JustSaying.JustSayingBus)notificationStackField.GetValue(fns);

                NotificationStack.Config.Returns(constructedStack.Config);

                notificationStackField.SetValue(fns, NotificationStack);
            }

            return(fns);
        }
コード例 #6
0
        private void GivenSubscriptionsToAQueueInTwoRegions()
        {
            var primaryHandler = Substitute.For <IHandlerAsync <GenericMessage> >();

            primaryHandler.Handle(Arg.Any <GenericMessage>()).Returns(true);
            primaryHandler
            .When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(async x => await _primaryHandler.Complete((GenericMessage)x.Args()[0]));

            _primaryBus = CreateMeABus
                          .InRegion(PrimaryRegion)
                          .WithSqsPointToPointSubscriber()
                          .IntoQueue(string.Empty)
                          .WithMessageHandler(primaryHandler);
            _primaryBus.StartListening();

            var secondaryHandler = Substitute.For <IHandlerAsync <GenericMessage> >();

            secondaryHandler.Handle(Arg.Any <GenericMessage>()).Returns(true);
            secondaryHandler
            .When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(async x => await _secondaryHandler.Complete((GenericMessage)x.Args()[0]));

            _secondaryBus = CreateMeABus
                            .InRegion(SecondaryRegion)
                            .WithSqsPointToPointSubscriber()
                            .IntoQueue(string.Empty)
                            .WithMessageHandler(secondaryHandler);
            _secondaryBus.StartListening();
        }
コード例 #7
0
        public void Given()
        {
            _handler.Handle(Arg.Any <GenericMessage>()).Returns(true).AndDoes(ex => { throw new Exception("My Ex"); });
            _globalErrorHandler = (ex, m) => { _handledException = true; };
            _monitoring         = Substitute.For <IMessageMonitor>();
            var bus = CreateMeABus.InRegion(RegionEndpoint.EUWest1.SystemName)
                      .WithMonitoring(_monitoring)
                      .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = 1;
                c.PublishFailureReAttempts          = 3;
            })
                      .WithSnsMessagePublisher <GenericMessage>()
                      .WithSqsTopicSubscriber()
                      .IntoQueue("queuename")
                      .ConfigureSubscriptionWith(cfg =>
            {
                cfg.MessageRetentionSeconds = 60;
                cfg.InstancePosition        = 1;
                cfg.OnError = _globalErrorHandler;
            })
                      .WithMessageHandler(_handler);

            bus.StartListening();
            _bus = bus;
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: fish0185/youtube
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            CreateMeABus.DefaultClientFactory = () =>
                                                new DefaultAwsClientFactory(new BasicAWSCredentials("changed", "changed"));

            var publisher = CreateMeABus.WithLogging(_loggerFactory)
                            .InRegion(RegionEndpoint.APSoutheast2.SystemName)
                            .WithNamingStrategy(
                () => new Naming(Configuration["Env"]))
                            .ConfigurePublisherWith(
                c =>
            {
                c.PublishFailureReAttempts          = 3;
                c.PublishFailureBackoffMilliseconds = 50;
            })
                            .WithSnsMessagePublisher <CreateSongCommand>(
                c =>
            {
                c.HandleException = (e) =>
                {
                    // log exception
                    return(false);
                };
            });

            services.AddSingleton(publisher);
            services.AddMvc();
        }
コード例 #9
0
 private void AndAPublisherToThePrimaryRegion(string primaryRegion)
 {
     _primaryPublisher = CreateMeABus
                         .WithLogging(LoggerFactory)
                         .InRegion(primaryRegion)
                         .WithSnsMessagePublisher <SimpleMessage>();
 }
コード例 #10
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());
        }
コード例 #11
0
 protected override Task When()
 {
     CreateMeABus
     .WithLogging(new LoggerFactory()).InRegion(null)
     .ConfigurePublisherWith(configuration => { });
     return(Task.CompletedTask);
 }
コード例 #12
0
        private async Task Given()
        {
            // Setup
            var doneSignal = new TaskCompletionSource <object>();

            // Given
            _handler.Handle(Arg.Any <GenericMessage>())
            .Returns(true)
            .AndDoes(_ => Tasks.DelaySendDone(doneSignal));

            var bus = CreateMeABus.WithLogging(new LoggerFactory())
                      .InRegion(RegionEndpoint.EUWest1.SystemName)
                      .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = 1;
                c.PublishFailureReAttempts          = 1;
            })
                      .WithSnsMessagePublisher <GenericMessage>()
                      .WithSqsTopicSubscriber()
                      .IntoQueue("queuename")
                      .ConfigureSubscriptionWith(cfg => cfg.InstancePosition = 1)
                      .WithMessageHandler(_handler);

            _bus = bus;

            // When
            _bus.StartListening();
            await _bus.PublishAsync(new GenericMessage());

            // Teardown
            await doneSignal.Task;

            bus.StopListening();
        }
コード例 #13
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);
        }
コード例 #14
0
 private void AndAPublisherToThePrimaryRegion(string primaryRegion)
 {
     _primaryPublisher = CreateMeABus
                         .WithLogging(new LoggerFactory())
                         .InRegion(primaryRegion)
                         .WithSnsMessagePublisher <GenericMessage>();
 }
コード例 #15
0
        protected override IAmJustSayingFluently CreateSystemUnderTest()
        {
            const int TimeoutMillis = 1000;

            var snsHandler = Substitute.For <IHandlerAsync <GenericMessage> >();

            snsHandler.When(x => x.Handle(Arg.Any <GenericMessage>()))
            .Do(x =>
            {
                var msg = (GenericMessage)x.Args()[0];
                if (_snsHandler != null)
                {
                    _snsHandler.Complete(msg).Wait(TimeoutMillis);
                }
            });

            var sqsHandler = Substitute.For <IHandlerAsync <AnotherGenericMessage> >();

            sqsHandler.When(x => x.Handle(Arg.Any <AnotherGenericMessage>()))
            .Do(x =>
            {
                var msg = (AnotherGenericMessage)x.Args()[0];
                if (_sqsHandler != null)
                {
                    _sqsHandler.Complete(msg).Wait(TimeoutMillis);
                }
            });

            Monitoring = Substitute.For <IMessageMonitor>();

            ServiceBus = CreateMeABus.WithLogging(new LoggerFactory())
                         .InRegion(RegionEndpoint.EUWest1.SystemName)
                         .WithMonitoring(Monitoring)

                         .ConfigurePublisherWith(c =>
            {
                c.PublishFailureBackoffMilliseconds = _config.PublishFailureBackoffMilliseconds;
                c.PublishFailureReAttempts          = _config.PublishFailureReAttempts;
            })

                         .WithSnsMessagePublisher <GenericMessage>()
                         .WithSqsTopicSubscriber()
                         .IntoQueue("queuename")
                         .ConfigureSubscriptionWith(cf =>
            {
                cf.MessageRetentionSeconds  = 60;
                cf.VisibilityTimeoutSeconds = JustSayingConstants.DEFAULT_VISIBILITY_TIMEOUT;
                cf.InstancePosition         = 1;
            })
                         .WithMessageHandler(snsHandler)

                         .WithSqsMessagePublisher <AnotherGenericMessage>(configuration => { })
                         .WithSqsPointToPointSubscriber()
                         .IntoDefaultQueue()
                         .WithMessageHandler(sqsHandler);

            ServiceBus.StartListening();
            return(ServiceBus);
        }
コード例 #16
0
 protected override IMessagePublisher CreateSystemUnderTest()
 {
     Publisher = CreateMeABus.WithLogging(new LoggerFactory())
                 .InRegion("eu-west-1")
                 .WithSnsMessagePublisher <OrderPlaced>();
     Publisher.StartListening();
     return(Publisher);
 }
コード例 #17
0
        private static void DeleteQueue(RegionEndpoint regionEndpoint, string queueUrl)
        {
            var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint);

            client.DeleteQueue(new DeleteQueueRequest {
                QueueUrl = queueUrl
            });
        }
コード例 #18
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
            });
        }
コード例 #19
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);
 }