示例#1
0
        public async Task PeekUsingConnectionStringWithSisgnature()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
            {
                var options          = new ServiceBusClientOptions();
                var audience         = ServiceBusConnection.BuildConnectionResource(options.TransportType, TestEnvironment.FullyQualifiedNamespace, scope.QueueName);
                var connectionString = TestEnvironment.BuildConnectionStringWithSharedAccessSignature(scope.QueueName, audience);

                await using var client = new ServiceBusClient(connectionString, options);
                var messageCt = 10;

                ServiceBusSender sender = client.CreateSender(scope.QueueName);
                using ServiceBusMessageBatch batch = await sender.CreateMessageBatchAsync();

                IEnumerable <ServiceBusMessage> sentMessages = AddMessages(batch, messageCt).AsEnumerable <ServiceBusMessage>();

                await sender.SendMessagesAsync(batch);

                await using var receiver = client.CreateReceiver(scope.QueueName);
                var messageEnum = sentMessages.GetEnumerator();

                var ct = 0;
                while (ct < messageCt)
                {
                    foreach (ServiceBusReceivedMessage peekedMessage in await receiver.PeekMessagesAsync(
                                 maxMessages: messageCt))
                    {
                        messageEnum.MoveNext();
                        Assert.AreEqual(messageEnum.Current.MessageId, peekedMessage.MessageId);
                        ct++;
                    }
                }
                Assert.AreEqual(messageCt, ct);
            }
        }
        public async Task LogsPluginExceptionEvents()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
            {
                var options = new ServiceBusClientOptions();
                options.AddPlugin(new PluginLiveTests.SendExceptionPlugin());
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                ServiceBusSender  sender  = client.CreateSender(scope.QueueName);
                ServiceBusMessage message = GetMessage();
                Assert.That(
                    async() => await sender.SendMessageAsync(message),
                    Throws.InstanceOf <NotImplementedException>());
                _listener.SingleEventById(ServiceBusEventSource.PluginStartEvent);
                _listener.SingleEventById(ServiceBusEventSource.PluginExceptionEvent);

                options = new ServiceBusClientOptions();
                options.AddPlugin(new PluginLiveTests.ReceiveExceptionPlugin());
                client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                sender = client.CreateSender(scope.QueueName);
                await sender.SendMessageAsync(message);

                Assert.AreEqual(2, _listener.EventsById(ServiceBusEventSource.PluginStartEvent).Count());
                Assert.AreEqual(1, _listener.EventsById(ServiceBusEventSource.PluginExceptionEvent).Count());

                var receiver = client.CreateReceiver(scope.QueueName);
                Assert.That(
                    async() => await receiver.ReceiveMessageAsync(),
                    Throws.InstanceOf <NotImplementedException>());
                Assert.AreEqual(3, _listener.EventsById(ServiceBusEventSource.PluginStartEvent).Count());
                Assert.AreEqual(2, _listener.EventsById(ServiceBusEventSource.PluginExceptionEvent).Count());
            };
        }
示例#3
0
        public async Task PluginsCanAlterMessage(bool schedule)
        {
            await using var scope = await ServiceBusScope.CreateWithQueue(
                            enablePartitioning : false,
                            enableSession : false);

            var plugin  = new SendReceivePlugin();
            var options = new ServiceBusClientOptions();

            options.AddPlugin(plugin);
            var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);

            var sender   = client.CreateSender(scope.QueueName);
            var receiver = client.CreateReceiver(scope.QueueName);

            if (schedule)
            {
                await sender.ScheduleMessageAsync(new ServiceBusMessage(), DateTimeOffset.UtcNow);
            }
            else
            {
                await sender.SendMessageAsync(new ServiceBusMessage());
            }

            Assert.True(plugin.WasCalled);
            var receivedMessage = await receiver.ReceiveMessageAsync();

            Assert.AreEqual("received", receivedMessage.Body.ToString());
        }
        /// <summary>
        ///   Initializes a new instance of the <see cref="AmqpClient"/> class.
        /// </summary>
        ///
        /// <param name="host">The fully qualified host name for the Service Bus namespace.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls may be specified by the Service Bus namespace or the requested Service Bus entity, depending on Azure configuration.</param>
        /// <param name="clientOptions">A set of options to apply when configuring the client.</param>
        /// <param name="connectionScope">The optional scope to use for AMQP connection management.  If <c>null</c>, a new scope will be created.</param>
        ///
        /// <remarks>
        ///   As an internal type, this class performs only basic sanity checks against its arguments.  It
        ///   is assumed that callers are trusted and have performed deep validation.
        ///
        ///   Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose;
        ///   creation of clones or otherwise protecting the parameters is assumed to be the purview of the
        ///   caller.
        /// </remarks>
        ///
        protected AmqpClient(
            string host,
            ServiceBusTokenCredential credential,
            ServiceBusClientOptions clientOptions,
            AmqpConnectionScope connectionScope)
        {
            Argument.AssertNotNullOrEmpty(host, nameof(host));
            Argument.AssertNotNull(credential, nameof(credential));
            Argument.AssertNotNull(clientOptions, nameof(clientOptions));

            try
            {
                //TODO add event ServiceBusEventSource.Log.ClientCreateStart(host, entityName);

                ServiceEndpoint = new UriBuilder
                {
                    Scheme = clientOptions.TransportType.GetUriScheme(),
                    Host   = host
                }.Uri;

                Credential      = credential;
                ConnectionScope = connectionScope ?? new AmqpConnectionScope(ServiceEndpoint, credential, clientOptions.TransportType, clientOptions.Proxy);
            }
            finally
            {
                // TODO add event  ServiceBusEventSource.Log.ServiceBusClientCreateComplete(host, entityName);
            }
        }
示例#5
0
        public async Task PluginsCanAlterMessageUsingSessionProcessor()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: true))
            {
                var plugin  = new SendReceivePlugin();
                var options = new ServiceBusClientOptions();
                options.AddPlugin(plugin);
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                var sender = client.CreateSender(scope.QueueName);

                await sender.SendMessageAsync(GetMessage("sessionId"));

                Assert.True(plugin.WasCalled);
                var processor = client.CreateSessionProcessor(scope.QueueName, new ServiceBusSessionProcessorOptions
                {
                    MaxConcurrentSessions = 1
                });
                processor.ProcessErrorAsync += ExceptionHandler;
                var tcs = new TaskCompletionSource <bool>();
                processor.ProcessMessageAsync += args =>
                {
                    Assert.AreEqual("received", args.Message.Body.ToString());
                    tcs.SetResult(true);
                    return(Task.CompletedTask);
                };
                await processor.StartProcessingAsync();

                await tcs.Task;
                await processor.StopProcessingAsync();
            }
        }
示例#6
0
        public async Task PluginCausingExceptionShouldThrow()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: false))
            {
                var options = new ServiceBusClientOptions();
                options.AddPlugin(new SendExceptionPlugin());
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                var sender = client.CreateSender(scope.QueueName);
                Assert.That(
                    async() => await sender.SendMessageAsync(new ServiceBusMessage()),
                    Throws.InstanceOf <NotImplementedException>());

                options = new ServiceBusClientOptions();
                options.AddPlugin(new ReceiveExceptionPlugin());
                client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                sender = client.CreateSender(scope.QueueName);
                await sender.SendMessageAsync(new ServiceBusMessage());

                var receiver = client.CreateReceiver(scope.QueueName);
                Assert.That(
                    async() => await receiver.ReceiveMessageAsync(),
                    Throws.InstanceOf <NotImplementedException>());
            }
        }
        public async Task ClientCanConnectUsingSharedKeyCredential()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: true, enableSession: false))
            {
                var options    = new ServiceBusClientOptions();
                var audience   = ServiceBusConnection.BuildConnectionResource(options.TransportType, TestEnvironment.FullyQualifiedNamespace, scope.QueueName);
                var credential = new AzureNamedKeyCredential(TestEnvironment.SharedAccessKeyName, TestEnvironment.SharedAccessKey);

                await using (var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, credential, options))
                {
                    Assert.That(async() =>
                    {
                        ServiceBusReceiver receiver = null;

                        try
                        {
                            receiver = client.CreateReceiver(scope.QueueName);
                        }
                        finally
                        {
                            await(receiver?.DisposeAsync() ?? new ValueTask());
                        }
                    }, Throws.Nothing);
                }
            }
        }
示例#8
0
        public async Task OrderOfPluginsRespected()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: false))
            {
                var options = new ServiceBusClientOptions();
                options.AddPlugin(new FirstPlugin());
                options.AddPlugin(new SecondPlugin());
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);

                var sender      = client.CreateSender(scope.QueueName);
                var receiver    = client.CreateReceiver(scope.QueueName);
                var sendMessage = new ServiceBusMessage();
                await sender.SendMessageAsync(sendMessage);

                var receivedMessage = await receiver.ReceiveMessageAsync();

                var firstSendPluginUserProperty  = (bool)receivedMessage.Properties["FirstSendPlugin"];
                var secondSendPluginUserProperty = (bool)receivedMessage.Properties["SecondSendPlugin"];

                Assert.True(firstSendPluginUserProperty);
                Assert.True(secondSendPluginUserProperty);
            }
        }
示例#9
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="AmqpClient"/> class.
        /// </summary>
        ///
        /// <param name="host">The fully qualified host name for the Service Bus namespace.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls may be specified by the Service Bus namespace or the requested Service Bus entity, depending on Azure configuration.</param>
        /// <param name="options">A set of options to apply when configuring the client.</param>
        ///
        /// <remarks>
        ///   As an internal type, this class performs only basic sanity checks against its arguments.  It
        ///   is assumed that callers are trusted and have performed deep validation.
        ///
        ///   Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose;
        ///   creation of clones or otherwise protecting the parameters is assumed to be the purview of the
        ///   caller.
        /// </remarks>
        ///
        internal AmqpClient(
            string host,
            ServiceBusTokenCredential credential,
            ServiceBusClientOptions options)
        {
            Argument.AssertNotNullOrEmpty(host, nameof(host));
            Argument.AssertNotNull(credential, nameof(credential));
            Argument.AssertNotNull(options, nameof(options));

            ServiceEndpoint = new UriBuilder
            {
                Scheme = options.TransportType.GetUriScheme(),
                Host   = host
            }.Uri;

            Credential = credential;
            if (options.EnableTransportMetrics)
            {
                TransportMetrics = new ServiceBusTransportMetrics();
            }
            ConnectionScope = new AmqpConnectionScope(
                ServiceEndpoint,
                credential,
                options.TransportType,
                options.WebProxy,
                options.EnableCrossEntityTransactions,
                options.RetryOptions.TryTimeout,
                TransportMetrics);
        }
        public async Task TransactionalSendMultipleSessionsRollback()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
            {
                var options = new ServiceBusClientOptions();
                options.RetryOptions.TryTimeout = TimeSpan.FromSeconds(5);
                options.RetryOptions.MaxRetries = 0;

                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                ServiceBusSender sender = client.CreateSender(scope.QueueName);

                ServiceBusMessage message1 = GetMessage("session1");
                ServiceBusMessage message2 = GetMessage("session2");
                using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    await sender.SendAsync(message1);

                    await sender.ScheduleMessageAsync(message2, DateTimeOffset.UtcNow.AddMinutes(1));
                }
                Assert.That(
                    async() =>
                    await client.CreateSessionReceiverAsync(scope.QueueName), Throws.InstanceOf <ServiceBusException>()
                    .And.Property(nameof(ServiceBusException.Reason))
                    .EqualTo(ServiceBusException.FailureReason.ServiceTimeout));
            };
        }
示例#11
0
        public async Task CrossEntityTransactionWrongOrder()
        {
            await using var queueA = await ServiceBusScope.CreateWithQueue(enablePartitioning : false, enableSession : false);

            await using var queueB = await ServiceBusScope.CreateWithQueue(enablePartitioning : false, enableSession : false);

            await using var topicC = await ServiceBusScope.CreateWithTopic(enablePartitioning : false, enableSession : false);

            #region Snippet:ServiceBusCrossEntityTransactionWrongOrder
#if SNIPPET
            string connectionString = "<connection_string>";
            var    options          = new ServiceBusClientOptions {
                EnableCrossEntityTransactions = true
            };
            await using var client = new ServiceBusClient(connectionString, options);

            ServiceBusReceiver receiverA = client.CreateReceiver("queueA");
            ServiceBusSender   senderB   = client.CreateSender("queueB");
            ServiceBusSender   senderC   = client.CreateSender("topicC");
#else
            await using var client = new ServiceBusClient(
                            TestEnvironment.ServiceBusConnectionString,
                            new ServiceBusClientOptions
            {
                EnableCrossEntityTransactions = true
            });

            ServiceBusSender senderA = client.CreateSender(queueA.QueueName);
            await senderA.SendMessageAsync(new ServiceBusMessage());

            ServiceBusReceiver receiverA = client.CreateReceiver(queueA.QueueName);
            ServiceBusSender   senderB   = client.CreateSender(queueB.QueueName);
            ServiceBusSender   senderC   = client.CreateSender(topicC.TopicName);
#endif

            // SenderB becomes the entity through which subsequent "sends" are routed through, since it is the first
            // entity on which an operation is performed with the cross-entity transaction client.
            await senderB.SendMessageAsync(new ServiceBusMessage());

            ServiceBusReceivedMessage receivedMessage = await receiverA.ReceiveMessageAsync();

            using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                // This will through an InvalidOperationException because a "receive" cannot be
                // routed through a different entity.
                await receiverA.CompleteMessageAsync(receivedMessage);

                await senderB.SendMessageAsync(new ServiceBusMessage());

                await senderC.SendMessageAsync(new ServiceBusMessage());

                ts.Complete();
            }
            #endregion

            receivedMessage = await receiverA.ReceiveMessageAsync();

            Assert.IsNull(receivedMessage);
        }
示例#12
0
            internal override TransportClient CreateTransportClient(ServiceBusTokenCredential credential,
                                                                    ServiceBusClientOptions options)
            {
                TransportClientCredential = credential;
                TransportClient ??= new();

                return(TransportClient);
            }
        public void ConstructorWithExpandedArgumentsValidatesOptions()
        {
            var token          = new Mock <ServiceBusTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var invalidOptions = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpTcp, Proxy = Mock.Of <IWebProxy>()
            };

            Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", Mock.Of <TokenCredential>(), invalidOptions), Throws.InstanceOf <ArgumentException>(), "The expanded argument constructor should validate client options");
        }
        public SubmissionServiceBusService(string serviceBusConnection, string queueName, ILogger log)
        {
            _serviceBusClientOptions = new ServiceBusClientOptions();
#if DEBUG
            _serviceBusClientOptions.TransportType = ServiceBusTransportType.AmqpWebSockets;
#endif
            _serviceBusClient = new ServiceBusClient(serviceBusConnection, _serviceBusClientOptions);
            _log = log;
        }
示例#15
0
        public void ConstructorWithConnectionStringValidatesOptions()
        {
            var fakeConnection = "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake";
            var invalidOptions = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of <IWebProxy>()
            };

            Assert.That(() => new ServiceBusClient(fakeConnection, invalidOptions), Throws.InstanceOf <ArgumentException>(), "The connection string constructor should validate client options");
        }
示例#16
0
        public void ConstructorWithSharedKeyCredentialValidatesOptions()
        {
            var token          = new AzureNamedKeyCredential("key", "value");
            var invalidOptions = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of <IWebProxy>()
            };

            Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", token, invalidOptions), Throws.InstanceOf <ArgumentException>(), "The expanded argument constructor should validate client options");
        }
示例#17
0
        public void ConstructorWithSharedKeyCredentialSetsTransportTypeFromOptions()
        {
            var token   = new AzureNamedKeyCredential("key", "value");
            var options = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            };
            var client = new ServiceBusClient("fullyQualifiedNamespace", token, options);

            Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
        }
示例#18
0
        public void ConstructorWithTokenCredentialSetsTransportTypeFromOptions()
        {
            var token   = new Mock <ServiceBusTokenCredential>(Mock.Of <TokenCredential>());
            var options = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            };
            var client = new ServiceBusClient("fullyQualifiedNamespace", Mock.Of <TokenCredential>(), options);

            Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
        }
示例#19
0
        public void ConstructorWithConnectionStringSetsTransportTypeFromOptions()
        {
            var fakeConnection = "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake";
            var options        = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            };
            var client = new ServiceBusClient(fakeConnection, options);

            Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
        }
示例#20
0
        public void ConstructorWithSasCredentialValidatesOptions()
        {
            var signature      = new SharedAccessSignature("sb://fake.thing.com", "fakeKey", "fakeValue");
            var token          = new AzureSasCredential(signature.Value);
            var invalidOptions = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpTcp, WebProxy = Mock.Of <IWebProxy>()
            };

            Assert.That(() => new ServiceBusClient("fullyQualifiedNamespace", token, invalidOptions), Throws.InstanceOf <ArgumentException>(), "The expanded argument constructor should validate client options");
        }
示例#21
0
        public void ConstructorWithSasCredentialSetsTransportTypeFromOptions()
        {
            var signature = new SharedAccessSignature("sb://fake.thing.com", "fakeKey", "fakeValue");
            var token     = new AzureSasCredential(signature.Value);
            var options   = new ServiceBusClientOptions {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            };
            var client = new ServiceBusClient("fullyQualifiedNamespace", token, options);

            Assert.That(client.TransportType, Is.EqualTo(options.TransportType));
        }
示例#22
0
        public void ConstructorCreatesDefaultOptions(ReadableOptionsMock client,
                                                     string constructorDescription)
        {
            var defaultOptions = new ServiceBusClientOptions();
            ServiceBusClientOptions options = client.Options;

            Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set default options.");
            Assert.That(options, Is.Not.SameAs(defaultOptions), $"The { constructorDescription } constructor should not have the same options instance.");
            Assert.That(options.TransportType, Is.EqualTo(defaultOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type.");
            Assert.That(options.WebProxy, Is.EqualTo(defaultOptions.WebProxy), $"The { constructorDescription } constructor should have the correct proxy.");
        }
示例#23
0
        public void ConstructorClonesOptions(ReadableOptionsMock client,
                                             ServiceBusClientOptions constructorOptions,
                                             string constructorDescription)
        {
            ServiceBusClientOptions options = client.Options;

            Assert.That(options, Is.Not.Null, $"The { constructorDescription } constructor should have set the options.");
            Assert.That(options, Is.Not.SameAs(constructorOptions), $"The { constructorDescription } constructor should have cloned the options.");
            Assert.That(options.TransportType, Is.EqualTo(constructorOptions.TransportType), $"The { constructorDescription } constructor should have the correct connection type.");
            Assert.That(options.WebProxy, Is.EqualTo(constructorOptions.WebProxy), $"The { constructorDescription } constructor should have the correct proxy.");
        }
        public async Task SendConnStringWithSignature()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
            {
                var options          = new ServiceBusClientOptions();
                var audience         = ServiceBusConnection.BuildConnectionResource(options.TransportType, TestEnvironment.FullyQualifiedNamespace, scope.QueueName);
                var connectionString = TestEnvironment.BuildConnectionStringWithSharedAccessSignature(scope.QueueName, audience);

                await using var sender = new ServiceBusClient(connectionString, options).CreateSender(scope.QueueName);
                await sender.SendMessageAsync(GetMessage());
            }
        }
示例#25
0
        public async Task CrossEntityTransaction()
        {
            await using var queueA = await ServiceBusScope.CreateWithQueue(enablePartitioning : false, enableSession : false);

            await using var queueB = await ServiceBusScope.CreateWithQueue(enablePartitioning : false, enableSession : false);

            await using var topicC = await ServiceBusScope.CreateWithTopic(enablePartitioning : false, enableSession : false);

            #region Snippet:ServiceBusCrossEntityTransaction
#if SNIPPET
            string connectionString = "<connection_string>";
            var    options          = new ServiceBusClientOptions {
                EnableCrossEntityTransactions = true
            };
            await using var client = new ServiceBusClient(connectionString, options);

            ServiceBusReceiver receiverA = client.CreateReceiver("queueA");
            ServiceBusSender   senderB   = client.CreateSender("queueB");
            ServiceBusSender   senderC   = client.CreateSender("topicC");
#else
            await using var client = new ServiceBusClient(
                            TestEnvironment.ServiceBusConnectionString,
                            new ServiceBusClientOptions
            {
                EnableCrossEntityTransactions = true
            });
            ServiceBusSender senderA = client.CreateSender(queueA.QueueName);
            await senderA.SendMessageAsync(new ServiceBusMessage());

            ServiceBusReceiver receiverA = client.CreateReceiver(queueA.QueueName);
            ServiceBusSender   senderB   = client.CreateSender(queueB.QueueName);
            ServiceBusSender   senderC   = client.CreateSender(topicC.TopicName);
#endif

            ServiceBusReceivedMessage receivedMessage = await receiverA.ReceiveMessageAsync();

            using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await receiverA.CompleteMessageAsync(receivedMessage);

                await senderB.SendMessageAsync(new ServiceBusMessage());

                await senderC.SendMessageAsync(new ServiceBusMessage());

                ts.Complete();
            }
            #endregion

            receivedMessage = await receiverA.ReceiveMessageAsync(TimeSpan.FromSeconds(5));

            Assert.IsNull(receivedMessage);
        }
示例#26
0
        /// <summary>
        ///   Provides test cases for the constructor tests.
        /// </summary>
        ///
        public static IEnumerable <object[]> ConstructorClonesOptionsCases()
        {
            var credential     = new Mock <ServiceBusTokenCredential>(Mock.Of <TokenCredential>());
            var fakeConnection = "Endpoint=sb://not-real.servicebus.windows.net/;SharedAccessKeyName=DummyKey;SharedAccessKey=[not_real];EntityPath=fake";

            var options = new ServiceBusClientOptions
            {
                TransportType = ServiceBusTransportType.AmqpWebSockets,
                WebProxy      = Mock.Of <IWebProxy>()
            };

            yield return(new object[] { new ReadableOptionsMock(fakeConnection, options), options, "connection string" });

            yield return(new object[] { new ReadableOptionsMock("fullyQualifiedNamespace", credential.Object, options), options, "expanded argument" });
        }
        protected ServiceBusClient CreateClient(int tryTimeout = DefaultTryTimeout)
        {
            var options =
                new ServiceBusClientOptions
            {
                RetryOptions = new ServiceBusRetryOptions
                {
                    TryTimeout = TimeSpan.FromSeconds(tryTimeout),
                }
            };

            return(new ServiceBusClient(
                       TestEnvironment.ServiceBusConnectionString,
                       options));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceScopeFactory"></param>
        /// <param name="busOptionsAccessor"></param>
        /// <param name="transportOptionsAccessor"></param>
        /// <param name="loggerFactory"></param>
        public AzureServiceBusTransport(IServiceScopeFactory serviceScopeFactory,
                                        IOptions <EventBusOptions> busOptionsAccessor,
                                        IOptions <AzureServiceBusTransportOptions> transportOptionsAccessor,
                                        ILoggerFactory loggerFactory)
            : base(serviceScopeFactory, busOptionsAccessor, transportOptionsAccessor, loggerFactory)
        {
            var connectionString = TransportOptions.ConnectionString;

            managementClient = new ServiceBusAdministrationClient(connectionString);

            var sbcOptions = new ServiceBusClientOptions {
                TransportType = TransportOptions.TransportType,
            };

            serviceBusClient = new ServiceBusClient(connectionString, sbcOptions);
        }
示例#29
0
        protected ServiceBusClient GetNoRetryClient()
        {
            var options =
                new ServiceBusClientOptions
            {
                RetryOptions = new ServiceBusRetryOptions
                {
                    TryTimeout = TimeSpan.FromSeconds(10),
                    MaxRetries = 0
                }
            };

            return(new ServiceBusClient(
                       TestEnvironment.ServiceBusConnectionString,
                       options));
        }
        public MessageServiceAzureServiceBus(ApplicationSettings applicationSettings)
        {
            _applicationSettings = applicationSettings;
            // Create a ServiceBusClient that will authenticate using a connection string
            string connectionString = _applicationSettings.QueueConnectionString;
            string queueName        = _applicationSettings.QueueName;
            // since ServiceBusClient implements IAsyncDisposable we create it with "await using"
            var options = new ServiceBusClientOptions {
                EnableCrossEntityTransactions = true
            };
            var client = new ServiceBusClient(connectionString, options);

            // Create the sender and receiver
            _sender   = client.CreateSender(queueName);
            _receiver = client.CreateReceiver(queueName);
        }