async Task CompleteOnPeekedMessagesShouldThrowTest()
        {
            var connection = new ServiceBusNamespaceConnection(TestUtility.NamespaceConnectionString);
            var receiver   = connection.CreateMessageReceiver(TestConstants.NonPartitionedQueueName, ReceiveMode.ReceiveAndDelete);
            var sender     = connection.CreateMessageSender(TestConstants.NonPartitionedQueueName);

            try
            {
                await TestUtility.SendMessagesAsync(sender, 1);

                var message = await receiver.PeekAsync();

                Assert.NotNull(message);
                await
                Assert.ThrowsAsync <InvalidOperationException>(
                    async() => await receiver.CompleteAsync(message.SystemProperties.LockToken));

                message = await receiver.ReceiveAsync();

                Assert.NotNull((object)message);
            }
            finally
            {
                await sender.CloseAsync().ConfigureAwait(false);

                await receiver.CloseAsync().ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
 QueueClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy)
     : base($"{nameof(QueueClient)}{ClientEntity.GetNextId()}({entityPath})", retryPolicy)
 {
     this.QueueName   = entityPath;
     this.ReceiveMode = receiveMode;
     this.InnerClient = new AmqpClient(serviceBusConnection, entityPath, MessagingEntityType.Queue, retryPolicy, receiveMode);
 }
 SubscriptionClient(ServiceBusNamespaceConnection serviceBusConnection, string topicPath, string subscriptionName, ReceiveMode receiveMode, RetryPolicy retryPolicy)
     : base($"{nameof(SubscriptionClient)}{ClientEntity.GetNextId()}({subscriptionName})", retryPolicy)
 {
     this.TopicPath               = topicPath;
     this.SubscriptionName        = subscriptionName;
     this.Path                    = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
     this.ReceiveMode             = receiveMode;
     this.InnerSubscriptionClient = new AmqpSubscriptionClient(serviceBusConnection, this.Path, MessagingEntityType.Subscriber, retryPolicy, receiveMode);
 }
Exemplo n.º 4
0
        TopicClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy)
            : base(nameof(TopicClient), entityPath, retryPolicy)
        {
            MessagingEventSource.Log.TopicClientCreateStart(serviceBusConnection?.Endpoint.Authority, entityPath);

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.syncLock             = new object();
            this.TopicName            = entityPath;

            MessagingEventSource.Log.TopicClientCreateStop(serviceBusConnection.Endpoint.Authority, entityPath, this.ClientId);
        }
Exemplo n.º 5
0
 TopicClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy)
     : base($"{nameof(TopicClient)}{GetNextId()}({entityPath})", retryPolicy)
 {
     this.syncLock             = new object();
     this.TopicName            = entityPath;
     this.ServiceBusConnection = serviceBusConnection;
     this.TokenProvider        = TokenProvider.CreateSharedAccessSignatureTokenProvider(
         serviceBusConnection.SasKeyName,
         serviceBusConnection.SasKey);
     this.CbsTokenProvider = new TokenProviderAdapter(this.TokenProvider, serviceBusConnection.OperationTimeout);
 }
        QueueClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(nameof(QueueClient), entityPath, retryPolicy)
        {
            MessagingEventSource.Log.QueueClientCreateStart(serviceBusConnection?.Endpoint.Authority, entityPath, receiveMode.ToString());

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.syncLock             = new object();
            this.QueueName            = entityPath;
            this.ReceiveMode          = receiveMode;

            MessagingEventSource.Log.QueueClientCreateStop(serviceBusConnection.Endpoint.Authority, entityPath, this.ClientId);
        }
Exemplo n.º 7
0
        public static SubscriptionClient Create(ServiceBusNamespaceConnection namespaceConnection, string topicPath, string subscriptionName, ReceiveMode mode)
        {
            if (namespaceConnection == null)
            {
                throw Fx.Exception.Argument(nameof(namespaceConnection), "Namespace Connection is null. Create a connection using the NamespaceConnection class");
            }

            if (string.IsNullOrWhiteSpace(topicPath))
            {
                throw Fx.Exception.Argument(nameof(namespaceConnection), "Topic Path is null");
            }

            return(namespaceConnection.CreateSubscriptionClient(topicPath, subscriptionName, mode));
        }
 SubscriptionClient(ServiceBusNamespaceConnection serviceBusConnection, string topicPath, string subscriptionName, ReceiveMode receiveMode, RetryPolicy retryPolicy)
     : base($"{nameof(SubscriptionClient)}{ClientEntity.GetNextId()}({subscriptionName})", retryPolicy)
 {
     this.syncLock             = new object();
     this.TopicPath            = topicPath;
     this.ServiceBusConnection = serviceBusConnection;
     this.SubscriptionName     = subscriptionName;
     this.Path          = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
     this.ReceiveMode   = receiveMode;
     this.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
         serviceBusConnection.SasKeyName,
         serviceBusConnection.SasKey);
     this.CbsTokenProvider = new TokenProviderAdapter(this.TokenProvider, serviceBusConnection.OperationTimeout);
 }
        TopicClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy)
            : base(nameof(TopicClient), entityPath, retryPolicy)
        {
            MessagingEventSource.Log.TopicClientCreateStart(serviceBusConnection?.Endpoint.Authority, entityPath);

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.syncLock             = new object();
            this.TopicName            = entityPath;
            this.TokenProvider        = this.ServiceBusConnection.CreateTokenProvider();
            this.CbsTokenProvider     = new TokenProviderAdapter(this.TokenProvider, serviceBusConnection.OperationTimeout);

            MessagingEventSource.Log.TopicClientCreateStop(serviceBusConnection?.Endpoint.Authority, entityPath, this.ClientId);
        }
Exemplo n.º 10
0
        public static QueueClient Create(ServiceBusNamespaceConnection namespaceConnection, string entityPath, ReceiveMode mode)
        {
            if (namespaceConnection == null)
            {
                throw Fx.Exception.Argument(nameof(namespaceConnection), "Namespace Connection is null. Create a connection using the NamespaceConnection class");
            }

            if (string.IsNullOrWhiteSpace(entityPath))
            {
                throw Fx.Exception.Argument(nameof(namespaceConnection), "Entity Path is null");
            }

            return(namespaceConnection.CreateQueueClient(entityPath, mode));
        }
        SubscriptionClient(ServiceBusNamespaceConnection serviceBusConnection, string topicPath, string subscriptionName, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(nameof(SubscriptionClient), $"{topicPath}/{subscriptionName}", retryPolicy)
        {
            MessagingEventSource.Log.SubscriptionClientCreateStart(serviceBusConnection?.Endpoint.Authority, topicPath, subscriptionName, receiveMode.ToString());

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.syncLock             = new object();
            this.TopicPath            = topicPath;
            this.SubscriptionName     = subscriptionName;
            this.Path        = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
            this.ReceiveMode = receiveMode;

            MessagingEventSource.Log.SubscriptionClientCreateStop(serviceBusConnection.Endpoint.Authority, topicPath, subscriptionName, this.ClientId);
        }
Exemplo n.º 12
0
        QueueClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(ClientEntity.GenerateClientId(nameof(QueueClient), entityPath), retryPolicy)
        {
            MessagingEventSource.Log.QueueClientCreateStart(serviceBusConnection?.Endpoint.Authority, entityPath, receiveMode.ToString());

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.syncLock             = new object();
            this.QueueName            = entityPath;
            this.ReceiveMode          = receiveMode;
            this.TokenProvider        = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                serviceBusConnection.SasKeyName,
                serviceBusConnection.SasKey);
            this.CbsTokenProvider = new TokenProviderAdapter(this.TokenProvider, serviceBusConnection.OperationTimeout);

            MessagingEventSource.Log.QueueClientCreateStop(serviceBusConnection.Endpoint.Authority, entityPath, this.ClientId);
        }
        async Task MessageReceiverAndMessageSenderCreationWorksAsExpected(string queueName, int messageCount = 10)
        {
            var connection = new ServiceBusNamespaceConnection(TestUtility.NamespaceConnectionString);
            var receiver   = connection.CreateMessageReceiver(queueName, ReceiveMode.PeekLock);
            var sender     = connection.CreateMessageSender(queueName);

            try
            {
                await this.PeekLockTestCase(sender, receiver, messageCount);
            }
            finally
            {
                await sender.CloseAsync().ConfigureAwait(false);

                await receiver.CloseAsync().ConfigureAwait(false);
            }
        }
        async Task ReceiveShouldReturnNoLaterThanServerWaitTimeTest(string queueName, int messageCount = 1)
        {
            var connection = new ServiceBusNamespaceConnection(TestUtility.NamespaceConnectionString);
            var receiver   = connection.CreateMessageReceiver(queueName, ReceiveMode.ReceiveAndDelete);
            var sender     = connection.CreateMessageSender(queueName);

            try
            {
                await this.ReceiveShouldReturnNoLaterThanServerWaitTimeTestCase(sender, receiver, messageCount);
            }
            finally
            {
                await sender.CloseAsync().ConfigureAwait(false);

                await receiver.CloseAsync().ConfigureAwait(false);
            }
        }
Exemplo n.º 15
0
        SubscriptionClient(ServiceBusNamespaceConnection serviceBusConnection, string topicPath, string subscriptionName, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(ClientEntity.GenerateClientId(nameof(SubscriptionClient), $"{topicPath}/{subscriptionName}"), retryPolicy)
        {
            MessagingEventSource.Log.SubscriptionClientCreateStart(serviceBusConnection?.Endpoint.Authority, topicPath, subscriptionName, receiveMode.ToString());

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.syncLock             = new object();
            this.TopicPath            = topicPath;
            this.SubscriptionName     = subscriptionName;
            this.Path          = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
            this.ReceiveMode   = receiveMode;
            this.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                serviceBusConnection.SasKeyName,
                serviceBusConnection.SasKey);
            this.CbsTokenProvider = new TokenProviderAdapter(this.TokenProvider, serviceBusConnection.OperationTimeout);

            MessagingEventSource.Log.SubscriptionClientCreateStop(serviceBusConnection.Endpoint.Authority, topicPath, subscriptionName, this.ClientId);
        }
        async Task MessageLockLostExceptionTest()
        {
            const int messageCount = 2;
            var       connection   = new ServiceBusNamespaceConnection(TestUtility.NamespaceConnectionString);
            var       receiver     = connection.CreateMessageReceiver(TestConstants.NonPartitionedQueueName, ReceiveMode.PeekLock);
            var       sender       = connection.CreateMessageSender(TestConstants.NonPartitionedQueueName);

            try
            {
                await TestUtility.SendMessagesAsync(sender, messageCount);

                var receivedMessages = await TestUtility.ReceiveMessagesAsync(receiver, messageCount);

                Assert.True(receivedMessages.Count() == messageCount);

                // Let the messages expire
                await Task.Delay(TimeSpan.FromMinutes(1));

                // Complete should throw
                await
                Assert.ThrowsAsync <MessageLockLostException>(
                    async() => await TestUtility.CompleteMessagesAsync(receiver, receivedMessages));

                receivedMessages = await TestUtility.ReceiveMessagesAsync(receiver, messageCount);

                Assert.True(receivedMessages.Count() == messageCount);

                await TestUtility.CompleteMessagesAsync(receiver, receivedMessages);
            }
            finally
            {
                await sender.CloseAsync().ConfigureAwait(false);

                await receiver.CloseAsync().ConfigureAwait(false);
            }
        }
Exemplo n.º 17
0
        public void Returns_transport_type_websockets()
        {
            var namespaceConnection = new ServiceBusNamespaceConnection(WebSocketsNamespaceConnectionString);

            Assert.Equal(TransportType.AmqpWebSockets, namespaceConnection.TransportType);
        }
        public void Returns_shared_access_key()
        {
            var namespaceConnection = new ServiceBusNamespaceConnection(NamespaceConnectionString);

            Assert.Equal(SasKey, namespaceConnection.SasKey);
        }
        public void Returns_endpoint_with_proper_uri_scheme()
        {
            var namespaceConnection = new ServiceBusNamespaceConnection(NamespaceConnectionString);

            Assert.Equal(Endpoint, namespaceConnection.Endpoint.Authority);
        }
Exemplo n.º 20
0
 public static SubscriptionClient Create(ServiceBusNamespaceConnection namespaceConnection, string topicPath, string subscriptionName)
 {
     return(SubscriptionClient.Create(namespaceConnection, topicPath, subscriptionName, ReceiveMode.PeekLock));
 }
Exemplo n.º 21
0
 TopicClient(ServiceBusNamespaceConnection serviceBusConnection, string entityPath, RetryPolicy retryPolicy)
     : base($"{nameof(TopicClient)}{GetNextId()}({entityPath})", retryPolicy)
 {
     this.TopicName   = entityPath;
     this.InnerClient = new AmqpClient(serviceBusConnection, entityPath, MessagingEntityType.Topic, retryPolicy);
 }
Exemplo n.º 22
0
        public void Returns_default_transport_type()
        {
            var namespaceConnection = new ServiceBusNamespaceConnection(NamespaceConnectionString);

            Assert.Equal(TransportType.Amqp, namespaceConnection.TransportType);
        }
Exemplo n.º 23
0
 public static QueueClient Create(ServiceBusNamespaceConnection namespaceConnection, string entityPath)
 {
     return(QueueClient.Create(namespaceConnection, entityPath, ReceiveMode.PeekLock));
 }