Esempio n. 1
0
        public async Task Should_batch_non_isolated_operations()
        {
            var settings = new SettingsHolder();

            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, mockSqsClient, null, new QueueCache(mockSqsClient, transportConfiguration), null);

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address1"),
                    DispatchConsistency.Default),
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address2"),
                    DispatchConsistency.Default));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.IsEmpty(mockSqsClient.RequestsSent);
            Assert.AreEqual(2, mockSqsClient.BatchRequestsSent.Count);
            Assert.AreEqual("address1", mockSqsClient.BatchRequestsSent.ElementAt(0).QueueUrl);
            Assert.AreEqual("address2", mockSqsClient.BatchRequestsSent.ElementAt(1).QueueUrl);
        }
Esempio n. 2
0
        public async Task Should_not_dispatch_multicast_operation_if_event_type_is_object()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();

            //given that a subscriber never sets up a topic for object this has to return null
            mockSnsClient.FindTopicAsyncResponse = topic => null;

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, null, mockSnsClient, new QueueCache(null, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(object)))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.IsEmpty(mockSnsClient.PublishedEvents);
        }
Esempio n. 3
0
        public void Should_raise_queue_does_not_exists_for_delayed_delivery_for_isolated_dispatch()
        {
            var settings            = new SettingsHolder();
            var transportExtensions = new TransportExtensions <SqsTransport>(settings);

            transportExtensions.UnrestrictedDurationDelayedDelivery();

            var mockSqsClient = new MockSqsClient();

            mockSqsClient.RequestResponse = req => throw new QueueDoesNotExistException("Queue does not exist");

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, mockSqsClient, null, new QueueCache(mockSqsClient, transportConfiguration), null);

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address1"),
                    DispatchConsistency.Isolated,
                    new List <DeliveryConstraint>
            {
                new DelayDeliveryWith(TimeSpan.FromMinutes(30))
            }));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            var exception = Assert.ThrowsAsync <QueueDoesNotExistException>(async() => await dispatcher.Dispatch(transportOperations, transportTransaction, context));

            StringAssert.StartsWith("Destination 'address1' doesn't support delayed messages longer than", exception.Message);
        }
Esempio n. 4
0
        public async Task Should_not_deduplicate_if_compatibility_mode_is_enabled_and_no_subscription_found()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();
            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, mockSqsClient, mockSnsClient, new QueueCache(mockSqsClient, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var messageId = Guid.NewGuid().ToString();
            var headers   = new Dictionary <string, string>()
            {
                { Headers.EnclosedMessageTypes, typeof(Event).AssemblyQualifiedName }
            };
            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(messageId, headers, Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(Event))),
                new TransportOperation(
                    new OutgoingMessage(messageId, headers, Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("abc"))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(1, mockSnsClient.PublishedEvents.Count);
            Assert.AreEqual(1, mockSqsClient.BatchRequestsSent.Count);
        }
Esempio n. 5
0
        public async Task Should_dispatch_multicast_operations()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();

            var transportConfiguration = new TransportConfiguration(settings);

            var dispatcher = new MessageDispatcher(transportConfiguration, null, null, mockSnsClient, new QueueCache(null, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(Event))),
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(AnotherEvent)))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(2, mockSnsClient.PublishedEvents.Count);
            Assert.AreEqual("arn:aws:sns:us-west-2:123456789012:NServiceBus-Transport-SQS-Tests-MessageDispatcherTests-Event", mockSnsClient.PublishedEvents.ElementAt(0).TopicArn);
            Assert.AreEqual("arn:aws:sns:us-west-2:123456789012:NServiceBus-Transport-SQS-Tests-MessageDispatcherTests-AnotherEvent", mockSnsClient.PublishedEvents.ElementAt(1).TopicArn);
        }
Esempio n. 6
0
        public async Task Includes_message_id_in_message_attributes(List <DeliveryConstraint> constraints)
        {
            var settings            = new SettingsHolder();
            var transportExtensions = new TransportExtensions <SqsTransport>(settings);

            transportExtensions.UnrestrictedDurationDelayedDelivery();

            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);

            var dispatcher = new MessageDispatcher(transportConfiguration, null, mockSqsClient, null, new QueueCache(mockSqsClient, transportConfiguration), null);

            var expectedId = "1234";

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(expectedId, new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address"),
                    DispatchConsistency.Isolated,
                    constraints));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            var sentMessage = mockSqsClient.RequestsSent.First();

            Assert.AreEqual(expectedId, sentMessage.MessageAttributes[Headers.MessageId].StringValue);
        }
Esempio n. 7
0
        public async Task Does_not_send_extra_properties_in_payload_by_default()
        {
            var settings = new SettingsHolder();

            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);

            var dispatcher = new MessageDispatcher(transportConfiguration, null, mockSqsClient, null, new QueueCache(mockSqsClient, transportConfiguration), null);

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage("1234", new Dictionary <string, string>
            {
                { TransportHeaders.TimeToBeReceived, expectedTtbr.ToString() },
                { Headers.ReplyToAddress, expectedReplyToAddress }
            }, Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("address"),
                    DispatchConsistency.Isolated));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.IsNotEmpty(mockSqsClient.RequestsSent, "No requests sent");
            var request = mockSqsClient.RequestsSent.First();

            IDictionary <string, JToken> bodyJson = JObject.Parse(request.MessageBody);

            Assert.IsFalse(bodyJson.ContainsKey("TimeToBeReceived"), "TimeToBeReceived serialized");
            Assert.IsFalse(bodyJson.ContainsKey("ReplyToAddress"), "ReplyToAddress serialized");
        }
Esempio n. 8
0
        public async Task GetTopicArn_caches()
        {
            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.TopicNamePrefix, "PREFIX");
            settings.Set(SettingsKeys.TopicNameGenerator, (Func <Type, string, string>)TopicNameGenerator);

            var configuration = new TransportConfiguration(settings);
            var snsClient     = new MockSnsClient();

            var metadataRegistry = settings.SetupMessageMetadataRegistry();

            var cache = new TopicCache(snsClient, metadataRegistry, configuration);

            await cache.GetTopicArn(typeof(Event));

            var requestsSent = new List <string>(snsClient.FindTopicRequests);

            snsClient.FindTopicRequests.Clear();

            await cache.GetTopicArn(typeof(Event));

            Assert.IsEmpty(snsClient.FindTopicRequests);
            CollectionAssert.AreEqual(new List <string> {
                "PREFIXEvent"
            }, requestsSent);
        }
        public async Task CopyAllMessagesTest_many_messages()
        {
            //ARRANGE
            var messageToEnque = 10000;
            var consumed       = 0;
            var logger         = new LogProviderMock();
            var listener       = new MessageListener1(m => Interlocked.Increment(ref consumed));
            Func <ITransportConfiguration> configuration = () =>
            {
                var config = new TransportConfiguration
                {
                    ConsumerPeriod = Timeout.InfiniteTimeSpan
                };
                config.Listeners.Add(listener);
                return(config);
            };
            var transport = new InMemoryQueueTransport(logger, configuration);

            var message = new byte[] { 0, 1, 2 };
            await transport.Start();

            for (var i = 0; i < messageToEnque; i++)
            {
                transport.Enque(message);
            }
            var destination = new byte[transport.PendingMessages][];
            //ACT
            await transport.CopyMessages(destination);

            //ASSERT
            Assert.AreEqual(messageToEnque, destination.Count());
            Assert.AreEqual(messageToEnque, transport.PendingMessages);
        }
        internal VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, TransportConfiguration settings)
        {
            _dateTimeProvider        = dateTimeProvider;
            _settings                = settings;
            _exposingRequestPipeline = new ExposingPipelineFactory <TransportConfiguration>(settings, _dateTimeProvider);

            _syncCall = (t, r) => t.Request <VirtualResponse>(
                HttpMethod.GET, "/",
                PostData.Serializable(new {}), new RequestParameters(HttpMethod.GET, supportsBody: false)
            {
                RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null))
            });
            _asyncCall = async(t, r) =>
            {
                var res = await t.RequestAsync <VirtualResponse>
                          (
                    HttpMethod.GET, "/",
                    CancellationToken.None,
                    PostData.Serializable(new { }),
                    new RequestParameters(HttpMethod.GET, supportsBody : false)
                {
                    RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null))
                }
                          ).ConfigureAwait(false);

                return((ITransportResponse)res);
            };
        }
Esempio n. 11
0
        /// <summary>
        /// Uses the command line to override the UA TCP implementation specified in the configuration.
        /// </summary>
        /// <param name="configuration">The configuration instance that stores the configurable information for a UA application.
        /// </param>
        public static void OverrideUaTcpImplementation(ApplicationConfiguration configuration)
        {
            // check if UA TCP configuration included.
            TransportConfiguration transport = null;

            for (int ii = 0; ii < configuration.TransportConfigurations.Count; ii++)
            {
                if (configuration.TransportConfigurations[ii].UriScheme == Utils.UriSchemeOpcTcp)
                {
                    transport = configuration.TransportConfigurations[ii];
                    break;
                }
            }

            // check if UA TCP implementation explicitly specified.
            if (transport != null)
            {
                string[] args = Environment.GetCommandLineArgs();

                if (args != null && args.Length > 1)
                {
                    if (String.Compare(args[1], "-uaTcpAnsiC", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        transport.TypeName = Utils.UaTcpBindingNativeStack;
                    }
                    else if (String.Compare(args[1], "-uaTcpDotNet", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        transport.TypeName = Utils.UaTcpBindingDefault;
                    }
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Displays the UA-TCP configuration in the form.
        /// </summary>
        /// <param name="form">The form to display the UA-TCP configuration.</param>
        /// <param name="configuration">The configuration instance that stores the configurable information for a UA application.</param>
        public static void DisplayUaTcpImplementation(Form form, ApplicationConfiguration configuration)
        {
            // check if UA TCP configuration included.
            TransportConfiguration transport = null;

            for (int ii = 0; ii < configuration.TransportConfigurations.Count; ii++)
            {
                if (configuration.TransportConfigurations[ii].UriScheme == Utils.UriSchemeOpcTcp)
                {
                    transport = configuration.TransportConfigurations[ii];
                    break;
                }
            }

            // check if UA TCP implementation explicitly specified.
            if (transport != null)
            {
                string text = form.Text;

                int index = text.LastIndexOf("(UA TCP - ");

                if (index >= 0)
                {
                    text = text.Substring(0, index);
                }

                form.Text = Utils.Format("{0} (UA TCP - C#)", text);
            }
        }
 public QueueCreator(TransportConfiguration configuration, IAmazonS3 s3Client, IAmazonSQS sqsClient, QueueUrlCache queueUrlCache)
 {
     this.configuration = configuration;
     this.s3Client      = s3Client;
     this.sqsClient     = sqsClient;
     this.queueUrlCache = queueUrlCache;
 }
Esempio n. 14
0
        public void GetTopicName_caches()
        {
            var called = 0;

            string Generator(Type eventType, string prefix)
            {
                called++;
                return($"{prefix}{eventType.Name}");
            }

            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.TopicNamePrefix, "PREFIX");
            settings.Set(SettingsKeys.TopicNameGenerator, (Func <Type, string, string>)Generator);

            var configuration = new TransportConfiguration(settings);

            var metadataRegistry = settings.SetupMessageMetadataRegistry();
            var metadata         = metadataRegistry.GetMessageMetadata(typeof(Event));

            var cache = new TopicCache(null, metadataRegistry, configuration);

            cache.GetTopicName(metadata);
            cache.GetTopicName(metadata);

            Assert.AreEqual(1, called);
        }
Esempio n. 15
0
        public async Task OneTimeTearDown()
        {
            // Once all tests have completed, delete all queues that were created.
            // Use the QueueNamePrefix to determine which queues to delete.
            var transport = new TransportExtensions <SqsTransport>(new SettingsHolder());

            transport = transport.ConfigureSqsTransport(SqsQueueNamePrefix);
            var transportConfiguration = new TransportConfiguration(transport.GetSettings());

            using (var sqsClient = SqsTransportExtensions.CreateSQSClient())
            {
                var listQueuesResult = await sqsClient.ListQueuesAsync(transportConfiguration.QueueNamePrefix).ConfigureAwait(false);

                foreach (var queueUrl in listQueuesResult.QueueUrls)
                {
                    try
                    {
                        await sqsClient.DeleteQueueAsync(queueUrl).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception when deleting queue: {ex}");
                    }
                }
            }
        }
        public static TransportConfiguration Create()
        {
            var connection = new InMemoryConnection();
            var pool       = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var settings   = new TransportConfiguration(pool, connection);

            return(settings);
        }
Esempio n. 17
0
 public MessagePump(TransportConfiguration configuration, IAmazonS3 s3Client, IAmazonSQS sqsClient, QueueUrlCache queueUrlCache)
 {
     this.configuration = configuration;
     this.s3Client      = s3Client;
     this.sqsClient     = sqsClient;
     this.queueUrlCache = queueUrlCache;
     awsEndpointUrl     = sqsClient.Config.DetermineServiceURL();
 }
        public void Setup()
        {
            var connection = new InMemoryConnection();
            var pool       = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var settings   = new TransportConfiguration(pool, connection);

            _transport = new Transport(settings);
        }
        public void Preserves_FifoQueue(string destination, string expected)
        {
            var configuration = new TransportConfiguration(new SettingsHolder());

            var result = QueueNameHelper.GetSqsQueueName(destination, configuration);

            Assert.AreEqual(expected, result);
        }
Esempio n. 20
0
 public MessageDispatcher(TransportConfiguration configuration, IAmazonS3 s3Client, IAmazonSQS sqsClient, QueueUrlCache queueUrlCache)
 {
     this.configuration = configuration;
     this.s3Client      = s3Client;
     this.sqsClient     = sqsClient;
     this.queueUrlCache = queueUrlCache;
     serializerStrategy = configuration.UseV1CompatiblePayload ? SimpleJson.PocoJsonSerializerStrategy : ReducedPayloadSerializerStrategy.Instance;
 }
Esempio n. 21
0
        public void MinimalUsage()
        {
            var settings  = new TransportConfiguration(new Uri("http://localhost:9200"));
            var transport = new Transport(settings);

            var response = transport.Get <StringResponse>("/");

            var headResponse = transport.Head("/");
        }
        public static TransportConfiguration RerouteToProxyIfNeeded(TransportConfiguration config)
        {
            if (!RunningMitmProxy)
            {
                return(config);
            }

            return(config.Proxy(new Uri("http://127.0.0.1:8080"), null, (string)null));
        }
Esempio n. 23
0
        public void MinimalElasticsearch()
        {
            var uri       = new Uri("http://localhost:9200");
            var settings  = new TransportConfiguration(uri, ElasticsearchProductRegistration.Default);
            var transport = new Transport(settings);

            var response = transport.Get <StringResponse>("/");

            var headResponse = transport.Head("/");
        }
Esempio n. 24
0
        public LogController(IPluginFactory outputFactory, ILogger <LogController> logger, IConfiguration configuration)
        {
            _logger = logger;

            _logger.SLT00003_Debug_LogController_Start();
            _outputFactory = outputFactory;
            _config        = new TransportConfiguration();

            configuration?.GetSection("Transport")?.Bind(_config);
            _logger.SLT00002_Debug_LogController_End();
        }
Esempio n. 25
0
        public void Init()
        {
            _logger        = new LFGenerator2.Trace.Logger("a");
            _configuration = new TransportConfiguration
            {
                BaudRate = 1,
                PortName = "COM0"
            };

            _boundary = new SerialPortBoundary(_configuration.PortName, _configuration.BaudRate, _configuration.Parity, _configuration.DataBits, _configuration.StopBits);
        }
Esempio n. 26
0
        public SqsTransportInfrastructure(ReadOnlySettings settings)
        {
            this.settings           = settings;
            messageMetadataRegistry = this.settings.Get <MessageMetadataRegistry>();
            configuration           = new TransportConfiguration(settings);

            if (settings.HasSetting(SettingsKeys.DisableNativePubSub))
            {
                OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast);
            }
            else
            {
                OutboundRoutingPolicy = new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Multicast, OutboundRoutingType.Unicast);
            }

            try
            {
                sqsClient = configuration.SqsClientFactory();
            }
            catch (AmazonClientException e)
            {
                var message = "Unable to configure the SQS client. Make sure the environment variables for AWS_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set or the client factory configures the created client accordingly";
                Logger.Error(message, e);
                throw new Exception(message, e);
            }

            try
            {
                snsClient = configuration.SnsClientFactory();
            }
            catch (AmazonClientException e)
            {
                var message = "Unable to configure the SNS client. Make sure the environment variables for AWS_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set or the client factory configures the created client accordingly";
                Logger.Error(message, e);
                throw new Exception(message, e);
            }

            try
            {
                if (!string.IsNullOrEmpty(settings.GetOrDefault <string>(SettingsKeys.S3BucketForLargeMessages)))
                {
                    s3Client = configuration.S3ClientFactory();
                }
            }
            catch (AmazonClientException e)
            {
                var message = "Unable to configure the S3 client. Make sure the environment variables for AWS_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set or the client factory configures the created client accordingly";
                Logger.Error(message, e);
                throw new Exception(message, e);
            }

            queueCache = new QueueCache(sqsClient, configuration);
            topicCache = new TopicCache(snsClient, messageMetadataRegistry, configuration);
        }
        public MessageDispatcher(TransportConfiguration configuration, IAmazonS3 s3Client, IAmazonSQS sqsClient, QueueUrlCache queueUrlCache)
        {
            this.configuration = configuration;
            this.s3Client      = s3Client;
            this.sqsClient     = sqsClient;
            this.queueUrlCache = queueUrlCache;

            jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = configuration.UseV1CompatiblePayload ? new DefaultContractResolver() : new ReducedPayloadContractResolver()
            };
        }
        public void Preserves_FifoQueue(string destination, string expected)
        {
            var configuration = new TransportConfiguration(new SettingsHolder());

            var cache = new QueueCache(null, configuration);

            var result           = cache.GetPhysicalQueueName(destination);
            var resultIdempotent = cache.GetPhysicalQueueName(result);

            Assert.AreEqual(expected, result);
            Assert.AreEqual(expected, resultIdempotent);
        }
Esempio n. 29
0
        public void Usage()
        {
            var pool       = new StaticConnectionPool(new[] { new Node(new Uri("http://localhost:9200")) });
            var connection = new HttpConnection();
            var serializer = LowLevelRequestResponseSerializer.Instance;
            var product    = ElasticsearchProductRegistration.Default;

            var settings  = new TransportConfiguration(pool, connection, serializer, product);
            var transport = new Transport <TransportConfiguration>(settings);

            var response = transport.Request <StringResponse>(HttpMethod.GET, "/");
        }
        public void SetUp()
        {
            cancellationTokenSource = new CancellationTokenSource();

            var settings = new SettingsHolder();

            mockSqsClient = new MockSqsClient();
            mockS3Client  = new MockS3Client();

            var transportConfiguration = new TransportConfiguration(settings);

            pump = new InputQueuePump(transportConfiguration, mockS3Client, mockSqsClient, new QueueCache(mockSqsClient, transportConfiguration));
        }