private void AndAPublisherToTheSecondaryRegion(string secondaryRegion) { _secondaryPublisher = CreateMeABus .WithLogging(new LoggerFactory()) .InRegion(secondaryRegion) .WithSqsMessagePublisher <GenericMessage>(configuration => { }); }
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); }
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); }
private IMayWantOptionalSettings GetBus(AWSCredentials credentials) { return(CreateMeABus .WithLogging(LoggerFactory) .InRegion(TestEnvironment.Region.SystemName) .WithAwsClientFactory(() => new DefaultAwsClientFactory(credentials))); }
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); }
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(); }
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; }
// 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(); }
private void AndAPublisherToThePrimaryRegion(string primaryRegion) { _primaryPublisher = CreateMeABus .WithLogging(LoggerFactory) .InRegion(primaryRegion) .WithSnsMessagePublisher <SimpleMessage>(); }
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()); }
protected override Task When() { CreateMeABus .WithLogging(new LoggerFactory()).InRegion(null) .ConfigurePublisherWith(configuration => { }); return(Task.CompletedTask); }
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(); }
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); }
private void AndAPublisherToThePrimaryRegion(string primaryRegion) { _primaryPublisher = CreateMeABus .WithLogging(new LoggerFactory()) .InRegion(primaryRegion) .WithSnsMessagePublisher <GenericMessage>(); }
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); }
protected override IMessagePublisher CreateSystemUnderTest() { Publisher = CreateMeABus.WithLogging(new LoggerFactory()) .InRegion("eu-west-1") .WithSnsMessagePublisher <OrderPlaced>(); Publisher.StartListening(); return(Publisher); }
private static void DeleteQueue(RegionEndpoint regionEndpoint, string queueUrl) { var client = CreateMeABus.DefaultClientFactory().GetSqsClient(regionEndpoint); client.DeleteQueue(new DeleteQueueRequest { QueueUrl = queueUrl }); }
// 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 }); }
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); }