public SqsMessageProducerSendTests() { _myCommand = new MyCommand { Value = "Test" }; _correlationId = Guid.NewGuid(); _replyTo = "http:\\queueUrl"; _contentType = "text\\plain"; var channelName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _connection = new Connection <MyCommand>( name: new ConnectionName(channelName), channelName: new ChannelName(channelName), routingKey: new RoutingKey(_topicName) ); _message = new Message( new MessageHeader(_myCommand.Id, _topicName, MessageType.MT_COMMAND, _correlationId, _replyTo, _contentType), new MessageBody(JsonConvert.SerializeObject((object)_myCommand)) ); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); _channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); _channel = _channelFactory.CreateChannel(_connection); _messageProducer = new SqsMessageProducer(awsConnection); }
public AWSValidateQueuesTests() { var channelName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); string topicName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(topicName); _subscription = new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, makeChannels: OnMissingChannel.Validate ); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); _awsConnection = new AWSMessagingGatewayConnection(credentials, region); //We need to create the topic at least, to check the queues var producer = new SqsMessageProducer(_awsConnection, new SqsPublication { MakeChannels = OnMissingChannel.Create }); producer.ConfirmTopicExists(topicName); }
public SqsMessageConsumerRequeueTests() { _myCommand = new MyCommand { Value = "Test" }; _correlationId = Guid.NewGuid(); _replyTo = "http:\\queueUrl"; _contentType = "text\\plain"; _topicName = AWSNameExtensions.ToValidSNSTopicName((string)_myCommand.GetType().FullName.ToString()); _message = new Message( new MessageHeader(_myCommand.Id, _topicName, MessageType.MT_COMMAND, _correlationId, _replyTo, _contentType), new MessageBody(JsonConvert.SerializeObject((object)_myCommand)) ); //Must have credentials stored in the SDK Credentials store or shared credentials file if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); _channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); _channel = _channelFactory.CreateChannel(new Connection <MyCommand>()); _messageProducer = new SqsMessageProducer(awsConnection); } }
public SQSBufferedConsumerTests() { //Must have credentials stored in the SDK Credentials store or shared credentials file var credentialChain = new CredentialProfileStoreChain(); if (credentialChain.TryGetAWSCredentials("default", out var credentials) && credentialChain.TryGetProfile("default", out var profile)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, profile.Region); ChannelFactory channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); var name = Guid.NewGuid().ToString(); //we need the channel to create the queues and notifications channelFactory.CreateChannel(new Connection <MyCommand>( name: new ConnectionName(name), channelName: new ChannelName(name), routingKey: new RoutingKey(_topicName), bufferSize: BUFFER_SIZE )); //we want to access via a consumer, to receive multiple messages - we don't want to expose on channel //just for the tests, so create a new consumer from the properties _consumer = new SqsMessageConsumer(awsConnection, new ChannelName(name).ToValidSQSQueueName(), BUFFER_SIZE); _messageProducer = new SqsMessageProducer(awsConnection); } }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var serviceCollection = new ServiceCollection(); if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); var producer = new SqsMessageProducer(awsConnection); serviceCollection.AddBrighter(options => { var outBox = new InMemoryOutbox(); options.BrighterMessaging = new BrighterMessaging(outBox, outBox, producer, null); }).AutoFromAssemblies(); var serviceProvider = serviceCollection.BuildServiceProvider(); var commandProcessor = serviceProvider.GetService <IAmACommandProcessor>(); commandProcessor.Post(new GreetingEvent("Ian")); } }
static void Main(string[] args) { var container = new TinyIoCContainer(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(GreetingEvent), typeof(GreetingEventMessageMapper) } }; if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); var producer = new SqsMessageProducer(awsConnection); var builder = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration()) .DefaultPolicy() .TaskQueues(new MessagingConfiguration(new InMemoryMessageStore(), producer, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()); var commandProcessor = builder.Build(); commandProcessor.Post(new GreetingEvent("Ian")); } }
public SQSBufferedConsumerTests() { (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); _channelFactory = new ChannelFactory(awsConnection); var channelName = $"Buffered-Consumer-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Buffered-Consumer-Tests-{Guid.NewGuid().ToString()}".Truncate(45); //we need the channel to create the queues and notifications var routingKey = new RoutingKey(_topicName); var channel = _channelFactory.CreateChannel(new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, bufferSize: BUFFER_SIZE )); //we want to access via a consumer, to receive multiple messages - we don't want to expose on channel //just for the tests, so create a new consumer from the properties _consumer = new SqsMessageConsumer(awsConnection, channel.Name.ToValidSQSQueueName(), routingKey, BUFFER_SIZE); _messageProducer = new SqsMessageProducer(awsConnection, new SqsPublication { MakeChannels = OnMissingChannel.Create, RoutingKey = routingKey }); }
public SqsRawMessageDeliveryTests() { (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); _channelFactory = new ChannelFactory(awsConnection); var channelName = $"Raw-Msg-Delivery-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Raw-Msg-Delivery-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(_topicName); var bufferSize = 10; //Set rawMessageDelivery to false _channel = _channelFactory.CreateChannel(new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, bufferSize: bufferSize, makeChannels: OnMissingChannel.Create, rawMessageDelivery: false)); _messageProducer = new SqsMessageProducer(awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Create }); }
public AWSAssumeQueuesTests() { var channelName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); string topicName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(topicName); var subscription = new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, makeChannels: OnMissingChannel.Assume ); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); //create the topic, we want the queue to be the issue var _ = new SqsMessageProducer(awsConnection, new SqsPublication { MakeChannels = OnMissingChannel.Create, RoutingKey = routingKey }); _channelFactory = new ChannelFactory(awsConnection); var channel = _channelFactory.CreateChannel(subscription); //We need to create the topic at least, to check the queues _consumer = new SqsMessageConsumer(awsConnection, channel.Name.ToValidSQSQueueName(), routingKey); }
public SqsMessageConsumerRequeueTests() { _myCommand = new MyCommand { Value = "Test" }; Guid correlationId = Guid.NewGuid(); string replyTo = "http:\\queueUrl"; string contentType = "text\\plain"; var channelName = $"Consumer-Requeue-Tests-{Guid.NewGuid().ToString()}".Truncate(45); string topicName = $"Consumer-Requeue-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(topicName); SqsSubscription <MyCommand> subscription = new( name : new SubscriptionName(channelName), channelName : new ChannelName(channelName), routingKey : routingKey ); _message = new Message( new MessageHeader(_myCommand.Id, topicName, MessageType.MT_COMMAND, correlationId, replyTo, contentType), new MessageBody(JsonSerializer.Serialize((object)_myCommand, JsonSerialisationOptions.Options)) ); //Must have credentials stored in the SDK Credentials store or shared credentials file (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); //We need to do this manually in a test - will create the channel from subscriber parameters _channelFactory = new ChannelFactory(awsConnection); _channel = _channelFactory.CreateChannel(subscription); _messageProducer = new SqsMessageProducer(awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Create }); }
public SqsMessageProducerSendTests() { _myCommand = new MyCommand { Value = "Test" }; _correlationId = Guid.NewGuid(); _replyTo = "http:\\queueUrl"; _contentType = "text\\plain"; var channelName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(_topicName); SqsSubscription <MyCommand> subscription = new( name : new SubscriptionName(channelName), channelName : new ChannelName(channelName), routingKey : routingKey ); _message = new Message( new MessageHeader(_myCommand.Id, _topicName, MessageType.MT_COMMAND, _correlationId, _replyTo, _contentType), new MessageBody(JsonSerializer.Serialize((object)_myCommand, JsonSerialisationOptions.Options)) ); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); _channelFactory = new ChannelFactory(awsConnection); _channel = _channelFactory.CreateChannel(subscription); _messageProducer = new SqsMessageProducer(awsConnection, new SnsPublication { Topic = new RoutingKey(_topicName), MakeChannels = OnMissingChannel.Create }); }
public AWSValidateInfrastructureByArnTests() { _myCommand = new MyCommand { Value = "Test" }; Guid correlationId = Guid.NewGuid(); string replyTo = "http:\\queueUrl"; string contentType = "text\\plain"; var channelName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); string topicName = $"Producer-Send-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(topicName); SqsSubscription <MyCommand> subscription = new( name : new SubscriptionName(channelName), channelName : new ChannelName(channelName), routingKey : routingKey, makeChannels : OnMissingChannel.Create ); _message = new Message( new MessageHeader(_myCommand.Id, topicName, MessageType.MT_COMMAND, correlationId, replyTo, contentType), new MessageBody(JsonSerializer.Serialize((object)_myCommand, JsonSerialisationOptions.Options)) ); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); //We need to do this manually in a test - will create the channel from subscriber parameters //This doesn't look that different from our create tests - this is because we create using the channel factory in //our AWS transport, not the consumer (as it's a more likely to use infrastructure declared elsewhere) _channelFactory = new ChannelFactory(awsConnection); var channel = _channelFactory.CreateChannel(subscription); var topicArn = FindTopicArn(credentials, region, routingKey.Value); var routingKeyArn = new RoutingKey(topicArn); //Now change the subscription to validate, just check what we made subscription = new( name : new SubscriptionName(channelName), channelName : channel.Name, routingKey : routingKeyArn, findTopicBy : TopicFindBy.Arn, makeChannels : OnMissingChannel.Validate ); _messageProducer = new SqsMessageProducer( awsConnection, new SqsPublication { TopicArns = new Dictionary <string, string>() { { topicName, topicArn } }, FindTopicBy = TopicFindBy.Arn, MakeChannels = OnMissingChannel.Validate }); _consumer = new SqsMessageConsumerFactory(awsConnection).Create(subscription); }
private static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .ConfigureServices((hostContext, services) => { if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); var producer = new SqsMessageProducer(awsConnection); services.AddBrighter() .UseInMemoryOutbox() .UseExternalBus(producer) .AutoFromAssemblies(typeof(GreetingEvent).Assembly); } services.AddHostedService <RunCommandProcessor>(); } ) .UseConsoleLifetime() .UseSerilog() .Build(); await host.RunAsync(); }
public SQSBufferedConsumerTests() { //Must have credentials stored in the SDK Credentials store or shared credentials file var credentialChain = new CredentialProfileStoreChain(); (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); var awsConnection = new AWSMessagingGatewayConnection(credentials, region); _channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); var channelName = $"Buffered-Consumer-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Buffered-Consumer-Tests-{Guid.NewGuid().ToString()}".Truncate(45); //we need the channel to create the queues and notifications _channelFactory.CreateChannel(new Connection <MyCommand>( name: new ConnectionName(channelName), channelName: new ChannelName(channelName), routingKey: new RoutingKey(_topicName), bufferSize: BUFFER_SIZE )); //we want to access via a consumer, to receive multiple messages - we don't want to expose on channel //just for the tests, so create a new consumer from the properties var sqsQueueName = new ChannelName(channelName).ToValidSQSQueueName(); _consumer = new SqsMessageConsumer(awsConnection, sqsQueueName, BUFFER_SIZE); _messageProducer = new SqsMessageProducer(awsConnection); }
public void Establish() { _queueListener = new TestAWSQueueListener(new AnonymousAWSCredentials(), queueUrl); _message = new Message(header: new MessageHeader(Guid.NewGuid(), "TestSqsTopic", MessageType.MT_COMMAND), body: new MessageBody("test content")); var credentials = new AnonymousAWSCredentials(); _messageProducer = new SqsMessageProducer(credentials); }
public SqsMessageProeducerSendTests() { _queueListener = new TestAWSQueueListener(new AnonymousAWSCredentials(), _queueUrl); _message = new Message(new MessageHeader(Guid.NewGuid(), "TestSqsTopic", MessageType.MT_COMMAND), new MessageBody("test content")); var credentials = new AnonymousAWSCredentials(); _messageProducer = new SqsMessageProducer(credentials); }
static void Main(string[] args) { var container = new TinyIoCContainer(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(GreetingEvent), typeof(GreetingEventMessageMapper) } }; var messageStore = new InMemoryMessageStore(); if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); var producer = new SqsMessageProducer(awsConnection); var builder = CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration()) .DefaultPolicy() .TaskQueues(new MessagingConfiguration(messageStore, producer, messageMapperRegistry)) .RequestContextFactory(new InMemoryRequestContextFactory()); var commandProcessor = builder.Build(); Console.WriteLine("Press <ENTER> to stop sending messages"); long loop = 0; while (true) { loop++; if (Console.KeyAvailable) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { break; } } Console.WriteLine($"Sending message #{loop}"); commandProcessor.Post(new GreetingEvent($"Ian #{loop}")); if (loop % 100 == 0) { Console.WriteLine("Pausing for breath..."); Task.Delay(4000).Wait(); } } } }
private static IAmACommandProcessor GetCommandProcessor() { var container = new TinyIoCContainer(); var messageMapperFactory = new TinyIoCMessageMapperFactory(container); //create policies var retryPolicy = Policy .Handle <Exception>() .WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) }); var circuitBreakerPolicy = Policy .Handle <Exception>() .CircuitBreaker(1, TimeSpan.FromMilliseconds(500)); var policyRegistry = new PolicyRegistry() { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } }; //create message mappers var messageMapperRegistry = new MessageMapperRegistry(messageMapperFactory) { { typeof(FolderCreatedEvent), typeof(FolderCreatedEventMessageMapper) }, { typeof(DocumentCreatedEvent), typeof(DocumentCreatedEventMessageMapper) }, { typeof(DocumentUpdatedEvent), typeof(DocumentUpdatedEventMessageMapper) } }; var awsCredentials = new StoredProfileAWSCredentials(); var sqsMessageProducer = new SqsMessageProducer(awsCredentials); var processor = new CommandProcessor( null, policyRegistry, messageMapperRegistry, new FakeMessageStore(), sqsMessageProducer ); return(processor); }
public void When_topic_missing_verify_throws() { //arrange var producer = new SqsMessageProducer(_awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Validate }); //act && assert Assert.Throws <BrokerUnreachableException>(() => producer.Send(new Message( new MessageHeader { Topic = _routingKey, ContentType = "plain/text" }, new MessageBody("Test")))); }
public SqsQueuePurgeTests() { MyCommand myCommand = new MyCommand { Value = "Test" }; _message = new Message( new MessageHeader(myCommand.Id, "MyCommand", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject((object)myCommand)) ); //Must have credentials stored in the SDK Credentials store or shared credentials file if (new CredentialProfileStoreChain().TryGetAWSCredentials("default", out var credentials)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, RegionEndpoint.EUWest1); _channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); _channel = _channelFactory.CreateChannel(new Connection <MyCommand>()); _messageProducer = new SqsMessageProducer(awsConnection); } }
public SqsQueuePurgeTests() { MyCommand myCommand = new MyCommand { Value = "Test" }; _message = new Message( new MessageHeader(myCommand.Id, "MyCommand", MessageType.MT_COMMAND), new MessageBody(JsonConvert.SerializeObject((object)myCommand)) ); var credentialChain = new CredentialProfileStoreChain(); if (credentialChain.TryGetAWSCredentials("default", out var credentials) && credentialChain.TryGetProfile("default", out var profile)) { var awsConnection = new AWSMessagingGatewayConnection(credentials, profile.Region); _channelFactory = new ChannelFactory(awsConnection, new SqsMessageConsumerFactory(awsConnection)); _channel = _channelFactory.CreateChannel(_connection); _messageProducer = new SqsMessageProducer(awsConnection); } }
public SnsReDrivePolicySDlqTests() { Guid correlationId = Guid.NewGuid(); string replyTo = "http:\\queueUrl"; string contentType = "text\\plain"; var channelName = $"Redrive-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _dlqChannelName = $"Redrive-DLQ-Tests-{Guid.NewGuid().ToString()}".Truncate(45); _topicName = $"Redrive-Tests-{Guid.NewGuid().ToString()}".Truncate(45); var routingKey = new RoutingKey(_topicName); //how are we consuming var subscription = new SqsSubscription <MyCommand>( name: new SubscriptionName(channelName), channelName: new ChannelName(channelName), routingKey: routingKey, //don't block the redrive policy from owning retry management requeueCount: -1, //delay before requeuing requeueDelayInMs: 50, //we want our SNS subscription to manage requeue limits using the DLQ for 'too many requeues' redrivePolicy: new RedrivePolicy ( deadLetterQueueName: new ChannelName(_dlqChannelName), maxReceiveCount: 2 )); //what do we send var myCommand = new MyDeferredCommand { Value = "Hello Redrive" }; _message = new Message( new MessageHeader(myCommand.Id, _topicName, MessageType.MT_COMMAND, correlationId, replyTo, contentType), new MessageBody(JsonSerializer.Serialize((object)myCommand, JsonSerialisationOptions.Options)) ); //Must have credentials stored in the SDK Credentials store or shared credentials file (AWSCredentials credentials, RegionEndpoint region) = CredentialsChain.GetAwsCredentials(); _awsConnection = new AWSMessagingGatewayConnection(credentials, region); //how do we send to the queue _sender = new SqsMessageProducer(_awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Create }); //We need to do this manually in a test - will create the channel from subscriber parameters _channelFactory = new ChannelFactory(_awsConnection); _channel = _channelFactory.CreateChannel(subscription); //how do we handle a command IHandleRequests <MyDeferredCommand> handler = new MyDeferredCommandHandler(); //hook up routing for the command processor var subscriberRegistry = new SubscriberRegistry(); subscriberRegistry.Register <MyDeferredCommand, MyDeferredCommandHandler>(); //once we read, how do we dispatch to a handler. N.B. we don't use this for reading here _commandProcessor = new CommandProcessor( subscriberRegistry: subscriberRegistry, handlerFactory: new QuickHandlerFactory(() => handler), requestContextFactory: new InMemoryRequestContextFactory(), policyRegistry: new PolicyRegistry() ); //pump messages from a channel to a handler - in essence we are building our own dispatcher in this test IAmAMessageMapper <MyDeferredCommand> mapper = new MyDeferredCommandMessageMapper(_topicName); _messagePump = new MessagePumpBlocking <MyDeferredCommand>(_commandProcessor, mapper) { Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3 }; }