Exemple #1
0
        /// <summary>
        /// Creates a new instance of the Subscription client on a given <see cref="ServiceBusConnection"/>
        /// </summary>
        /// <param name="serviceBusConnection">Connection object to the service bus namespace.</param>
        /// <param name="topicPath">Topic path.</param>
        /// <param name="subscriptionName">Subscription name.</param>
        /// <param name="receiveMode">Mode of receive of messages. Defaults to <see cref="ReceiveMode"/>.PeekLock.</param>
        /// <param name="retryPolicy">Retry policy for subscription operations. Defaults to <see cref="RetryPolicy.Default"/></param>
        public SubscriptionClient(ServiceBusConnection serviceBusConnection, string topicPath, string subscriptionName, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(nameof(SubscriptionClient), $"{topicPath}/{subscriptionName}", retryPolicy)
        {
            if (string.IsNullOrWhiteSpace(topicPath))
            {
                throw Fx.Exception.ArgumentNullOrWhiteSpace(topicPath);
            }
            if (string.IsNullOrWhiteSpace(subscriptionName))
            {
                throw Fx.Exception.ArgumentNullOrWhiteSpace(subscriptionName);
            }

            MessagingEventSource.Log.SubscriptionClientCreateStart(serviceBusConnection?.Endpoint.Authority, topicPath, subscriptionName, receiveMode.ToString());

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.syncLock             = new object();
            this.TopicPath            = topicPath;
            this.SubscriptionName     = subscriptionName;
            this.Path             = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.SubscriptionName);
            this.ReceiveMode      = receiveMode;
            this.diagnosticSource = new ServiceBusDiagnosticSource(this.Path, serviceBusConnection.Endpoint);
            this.OwnsConnection   = false;
            this.ServiceBusConnection.ThrowIfClosed();

            if (this.ServiceBusConnection.TokenProvider != null)
            {
                this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
            }
            else
            {
                throw new ArgumentNullException($"{nameof(ServiceBusConnection)} doesn't have a valid token provider");
            }

            MessagingEventSource.Log.SubscriptionClientCreateStop(serviceBusConnection.Endpoint.Authority, topicPath, subscriptionName, this.ClientId);
        }
        internal SessionClient(
            string clientTypeName,
            string entityPath,
            MessagingEntityType?entityType,
            ReceiveMode receiveMode,
            int prefetchCount,
            ServiceBusConnection serviceBusConnection,
            ITokenProvider tokenProvider,
            ICbsTokenProvider cbsTokenProvider,
            RetryPolicy retryPolicy,
            IList <ServiceBusPlugin> registeredPlugins)
            : base(clientTypeName, entityPath, retryPolicy ?? RetryPolicy.Default)
        {
            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.EntityPath           = entityPath;
            this.EntityType           = entityType;
            this.ReceiveMode          = receiveMode;
            this.PrefetchCount        = prefetchCount;
            tokenProvider             = tokenProvider ?? this.ServiceBusConnection.CreateTokenProvider();
            this.CbsTokenProvider     = cbsTokenProvider ?? new TokenProviderAdapter(tokenProvider, this.ServiceBusConnection.OperationTimeout);
            this.diagnosticSource     = new ServiceBusDiagnosticSource(entityPath, serviceBusConnection.Endpoint);

            // Register plugins on the message session.
            if (registeredPlugins != null)
            {
                foreach (var serviceBusPlugin in registeredPlugins)
                {
                    this.RegisterPlugin(serviceBusPlugin);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of the Queue client on a given <see cref="ServiceBusConnection"/>
        /// </summary>
        /// <param name="serviceBusConnection">Connection object to the service bus namespace.</param>
        /// <param name="entityPath">Queue path.</param>
        /// <param name="receiveMode">Mode of receive of messages. Default to <see cref="ReceiveMode"/>.PeekLock.</param>
        /// <param name="retryPolicy">Retry policy for queue operations. Defaults to <see cref="RetryPolicy.Default"/></param>
        public QueueClient(ServiceBusConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy)
            : base(nameof(QueueClient), entityPath, retryPolicy)
        {
            MessagingEventSource.Log.QueueClientCreateStart(serviceBusConnection?.Endpoint.Authority, entityPath, receiveMode.ToString());

            if (string.IsNullOrWhiteSpace(entityPath))
            {
                throw Fx.Exception.ArgumentNullOrWhiteSpace(entityPath);
            }

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.syncLock             = new object();
            this.QueueName            = entityPath;
            this.ReceiveMode          = receiveMode;
            this.ownsConnection       = false;
            if (this.ServiceBusConnection.TokenProvider != null)
            {
                this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
            }
            else
            {
                throw new ArgumentNullException($"{nameof(ServiceBusConnection)} doesn't have a valid token provider");
            }

            MessagingEventSource.Log.QueueClientCreateStop(serviceBusConnection.Endpoint.Authority, entityPath, this.ClientId);
        }
Exemple #4
0
 protected QueueClient(ServiceBusConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode)
     : base($"{nameof(QueueClient)}{ClientEntity.GetNextId()}({entityPath})")
 {
     this.ServiceBusConnection = serviceBusConnection;
     this.QueueName            = entityPath;
     this.Mode = receiveMode;
 }
        internal SessionClient(
            string clientTypeName,
            string entityPath,
            MessagingEntityType?entityType,
            ReceiveMode receiveMode,
            int prefetchCount,
            ServiceBusConnection serviceBusConnection,
            RetryPolicy retryPolicy,
            IList <ServiceBusPlugin> registeredPlugins)
            : base(clientTypeName, entityPath, retryPolicy ?? RetryPolicy.Default)
        {
            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.OperationTimeout     = this.ServiceBusConnection.OperationTimeout;
            this.EntityPath           = entityPath;
            this.EntityType           = entityType;
            this.ReceiveMode          = receiveMode;
            this.PrefetchCount        = prefetchCount;

            // Register plugins on the message session.
            if (registeredPlugins != null)
            {
                foreach (var serviceBusPlugin in registeredPlugins)
                {
                    this.RegisterPlugin(serviceBusPlugin);
                }
            }
        }
Exemple #6
0
 protected SubscriptionClient(ServiceBusConnection serviceBusConnection, string topicPath, string name, ReceiveMode receiveMode)
     : base($"{nameof(SubscriptionClient)}{ClientEntity.GetNextId()}({name})")
 {
     this.ServiceBusConnection = serviceBusConnection;
     this.TopicPath            = topicPath;
     this.Name             = name;
     this.SubscriptionPath = EntityNameHelper.FormatSubscriptionPath(this.TopicPath, this.Name);
     this.Mode             = receiveMode;
 }
 public MessageSession(
     string entityPath,
     MessagingEntityType?entityType,
     ReceiveMode receiveMode,
     ServiceBusConnection serviceBusConnection,
     RetryPolicy retryPolicy,
     int prefetchCount      = Constants.DefaultClientPrefetchCount,
     string sessionId       = null,
     bool isSessionReceiver = false)
     : base(entityPath, entityType, receiveMode, serviceBusConnection, retryPolicy, prefetchCount, sessionId, isSessionReceiver)
 {
 }
Exemple #8
0
 public MessageSession(
     string entityPath,
     MessagingEntityType?entityType,
     ReceiveMode receiveMode,
     ServiceBusConnection serviceBusConnection,
     ICbsTokenProvider cbsTokenProvider,
     RetryPolicy retryPolicy,
     int prefetchCount      = Constants.DefaultClientPrefetchCount,
     string sessionId       = null,
     bool isSessionReceiver = false)
     : base(entityPath, entityType, receiveMode, serviceBusConnection, cbsTokenProvider, retryPolicy, prefetchCount, sessionId, isSessionReceiver)
 {
     this.diagnosticSource = new ServiceBusDiagnosticSource(entityPath, serviceBusConnection.Endpoint);
 }
Exemple #9
0
        internal SessionClient(
            string clientTypeName,
            string entityPath,
            MessagingEntityType?entityType,
            ReceiveMode receiveMode,
            int prefetchCount,
            ServiceBusConnection serviceBusConnection,
            ICbsTokenProvider cbsTokenProvider,
            RetryPolicy retryPolicy,
            IList <ServiceBusPlugin> registeredPlugins)
            : base(clientTypeName, entityPath, retryPolicy ?? RetryPolicy.Default)
        {
            if (string.IsNullOrWhiteSpace(entityPath))
            {
                throw Fx.Exception.ArgumentNullOrWhiteSpace(entityPath);
            }

            this.ServiceBusConnection = serviceBusConnection ?? throw new ArgumentNullException(nameof(serviceBusConnection));
            this.EntityPath           = entityPath;
            this.EntityType           = entityType;
            this.ReceiveMode          = receiveMode;
            this.PrefetchCount        = prefetchCount;
            this.ServiceBusConnection.ThrowIfClosed();

            if (cbsTokenProvider != null)
            {
                this.CbsTokenProvider = cbsTokenProvider;
            }
            else if (this.ServiceBusConnection.TokenProvider != null)
            {
                this.CbsTokenProvider = new TokenProviderAdapter(this.ServiceBusConnection.TokenProvider, this.ServiceBusConnection.OperationTimeout);
            }
            else
            {
                throw new ArgumentNullException($"{nameof(ServiceBusConnection)} doesn't have a valid token provider");
            }

            this.diagnosticSource = new ServiceBusDiagnosticSource(entityPath, serviceBusConnection.Endpoint);

            // Register plugins on the message session.
            if (registeredPlugins != null)
            {
                foreach (var serviceBusPlugin in registeredPlugins)
                {
                    this.RegisterPlugin(serviceBusPlugin);
                }
            }
        }
Exemple #10
0
 /// <summary>
 /// Creates a new SessionClient on a given <see cref="ServiceBusConnection"/>
 /// </summary>
 /// <param name="serviceBusConnection">Connection object to the service bus namespace.</param>
 /// <param name="entityPath">The path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the full path.</param>
 /// <param name="receiveMode">The <see cref="ReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param>
 /// <param name="retryPolicy">The <see cref="RetryPolicy"/> that will be used when communicating with ServiceBus. Defaults to <see cref="RetryPolicy.Default"/></param>
 /// <param name="prefetchCount">The <see cref="PrefetchCount"/> that specifies the upper limit of messages the session object
 /// will actively receive regardless of whether a receive operation is pending. Defaults to 0.</param>
 public SessionClient(
     ServiceBusConnection serviceBusConnection,
     string entityPath,
     ReceiveMode receiveMode,
     RetryPolicy retryPolicy = null,
     int prefetchCount       = DefaultPrefetchCount)
     : this(nameof(SessionClient),
            entityPath,
            null,
            receiveMode,
            prefetchCount,
            serviceBusConnection,
            null,
            retryPolicy,
            null)
 {
     this.OwnsConnection = false;
 }
Exemple #11
0
 protected TopicClient(ServiceBusConnection serviceBusConnection, string entityPath)
     : base($"{nameof(TopicClient)}{ClientEntity.GetNextId()}({entityPath})")
 {
     this.ServiceBusConnection = serviceBusConnection;
     this.TopicName            = entityPath;
 }