Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopicSender"/> class, 
        /// automatically creating the given topic if it does not exist.
        /// </summary>
        protected TopicSender(ServiceBusSettings settings, string topic, RetryStrategy retryStrategy)
        {
            this.settings = settings;
            this.topic = topic;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            // TODO: This could be injected.
            this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
            this.retryPolicy.Retrying +=
                (s, e) =>
                {
                    var handler = this.Retrying;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }

                    Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount);
                };

            var factory = MessagingFactory.Create(this.serviceUri, this.tokenProvider);
            this.topicClient = factory.CreateTopicClient(this.topic);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopicSender"/> class,
        /// automatically creating the given topic if it does not exist.
        /// </summary>
        protected TopicSender(ServiceBusSettings settings, string topic, RetryStrategy retryStrategy)
        {
            this.settings = settings;
            this.topic    = topic;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri    = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            // TODO: This could be injected.
            this.retryPolicy           = new RetryPolicy <ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
            this.retryPolicy.Retrying +=
                (s, e) =>
            {
                var handler = this.Retrying;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }

                Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount);
            };

            var factory = MessagingFactory.Create(this.serviceUri, this.tokenProvider);

            this.topicClient = factory.CreateTopicClient(this.topic);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class, 
 /// automatically creating the topic and subscription if they don't exist.
 /// </summary>
 public SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription)
     : this(
         settings,
         topic,
         subscription,
         new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 4
0
 public SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ISessionSubscriptionReceiverInstrumentation instrumentation)
     : this(settings,
         topic,
         subscription,
         requiresSequentialProcessing,
         instrumentation,
         new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class, 
 /// automatically creating the topic and subscription if they don't exist.
 /// </summary>
 public SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ISubscriptionReceiverInstrumentation instrumentation)
     : this(
         settings,
         topic,
         subscription,
         processInParallel,
         instrumentation,
         new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 6
0
 public SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ISessionSubscriptionReceiverInstrumentation instrumentation)
     : this(
         settings,
         topic,
         subscription,
         requiresSequentialProcessing,
         instrumentation,
         new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class,
 /// automatically creating the topic and subscription if they don't exist.
 /// </summary>
 public SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ISubscriptionReceiverInstrumentation instrumentation)
     : this(
         settings,
         topic,
         subscription,
         processInParallel,
         instrumentation,
         new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 8
0
        public void CreateV3ReadModelSubscriptions(ServiceBusSettings serviceBusSettings)
        {
            var commandsTopic = serviceBusSettings.Topics.First(t => !t.IsEventBus);
            serviceBusSettings.Topics.Remove(commandsTopic);

            var eventsTopic = serviceBusSettings.Topics.First();
            eventsTopic.MigrationSupport.Clear();
            var v3Subs = eventsTopic.Subscriptions.Where(s => s.Name.EndsWith("V3")).ToArray();
            eventsTopic.Subscriptions.Clear();
            eventsTopic.Subscriptions.AddRange(v3Subs);

            var config = new ServiceBusConfig(serviceBusSettings);
            config.Initialize();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionReceiver"/> class, 
        /// automatically creating the topic and subscription if they don't exist.
        /// </summary>
        protected SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, RetryStrategy backgroundRetryStrategy)
        {
            this.settings = settings;
            this.topic = topic;
            this.subscription = subscription;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            var messagingFactory = MessagingFactory.Create(this.serviceUri, tokenProvider);
            this.client = messagingFactory.CreateSubscriptionClient(topic, subscription);

            this.receiveRetryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy);
            this.receiveRetryPolicy.Retrying +=
                (s, e) =>
                {
                    Trace.TraceError("An error occurred in attempt number {1} to receive a message: {0}", e.LastException.Message, e.CurrentRetryCount);
                };
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionSubscriptionReceiver"/> class,
        /// automatically creating the topic and subscription if they don't exist.
        /// </summary>
        protected SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ISessionSubscriptionReceiverInstrumentation instrumentation, RetryStrategy backgroundRetryStrategy)
        {
            this.settings     = settings;
            this.topic        = topic;
            this.subscription = subscription;
            this.requiresSequentialProcessing = requiresSequentialProcessing;
            this.instrumentation = instrumentation;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri    = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            var messagingFactory = MessagingFactory.Create(this.serviceUri, tokenProvider);

            this.client = messagingFactory.CreateSubscriptionClient(topic, subscription);
            if (this.requiresSequentialProcessing)
            {
                this.client.PrefetchCount = 10;
            }
            else
            {
                this.client.PrefetchCount = 15;
            }

            this.dynamicThrottling =
                new DynamicThrottling(
                    maxDegreeOfParallelism: 160,
                    minDegreeOfParallelism: 30,
                    penaltyAmount: 3,
                    workFailedPenaltyAmount: 5,
                    workCompletedParallelismGain: 1,
                    intervalForRestoringDegreeOfParallelism: 10000);
            this.receiveRetryPolicy           = new RetryPolicy <ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy);
            this.receiveRetryPolicy.Retrying += (s, e) =>
            {
                this.dynamicThrottling.Penalize();
                Trace.TraceWarning(
                    "An error occurred in attempt number {1} to receive a message from subscription {2}: {0}",
                    e.LastException.Message,
                    e.CurrentRetryCount,
                    this.subscription);
            };
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SubscriptionReceiver" /> class,
        ///     automatically creating the topic and subscription if they don't exist.
        /// </summary>
        protected SubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool processInParallel, ISubscriptionReceiverInstrumentation instrumentation,
                                       RetryStrategy backgroundRetryStrategy)
        {
            this.settings          = settings;
            this.topic             = topic;
            this.subscription      = subscription;
            this.processInParallel = processInParallel;
            this.instrumentation   = instrumentation;

            tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            serviceUri    = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            var messagingFactory = MessagingFactory.Create(serviceUri, tokenProvider);

            client = messagingFactory.CreateSubscriptionClient(topic, subscription);
            if (this.processInParallel)
            {
                client.PrefetchCount = 18;
            }
            else
            {
                client.PrefetchCount = 14;
            }

            dynamicThrottling =
                new DynamicThrottling(
                    100,
                    50,
                    3,
                    5,
                    1,
                    8000);
            receiveRetryPolicy           = new RetryPolicy <ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy);
            receiveRetryPolicy.Retrying += (s, e) => {
                dynamicThrottling.Penalize();
                Trace.TraceWarning(
                    "An error occurred in attempt number {1} to receive a message from subscription {2}: {0}",
                    e.LastException.Message,
                    e.CurrentRetryCount,
                    this.subscription);
            };
        }
Exemplo n.º 12
0
        public given_service_bus_config()
        {
            System.Diagnostics.Trace.Listeners.Clear();
            this.settings = InfrastructureSettings.Read("Settings.xml").ServiceBus;
            foreach (var topic in this.settings.Topics)
            {
                topic.Path = topic.Path + Guid.NewGuid().ToString();
            }

            var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(this.settings.TokenIssuer, this.settings.TokenAccessKey);
            var serviceUri = ServiceBusEnvironment.CreateServiceUri(this.settings.ServiceUriScheme, this.settings.ServiceNamespace, this.settings.ServicePath);
            this.namespaceManager = new NamespaceManager(serviceUri, tokenProvider);

            var retryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
            this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);

            this.sut = new ServiceBusConfig(this.settings);

            Cleanup();
        }
 public ServiceBusConfig(ServiceBusSettings settings)
 {
     this.settings = settings;
 }
 public TestableTopicSender(ServiceBusSettings settings, string topic, RetryStrategy retryStrategy)
     : base(settings, topic, retryStrategy)
 {
     this.DoBeginSendMessageDelegate = base.DoBeginSendMessage;
     this.DoEndSendMessageDelegate = base.DoEndSendMessage;
 }
 public TestableSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, RetryStrategy background)
     : base(settings, topic, subscription, background)
 {
     this.DoReceiveMessageDelegate = base.DoReceiveMessage;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionSubscriptionReceiver"/> class, 
        /// automatically creating the topic and subscription if they don't exist.
        /// </summary>
        protected SessionSubscriptionReceiver(ServiceBusSettings settings, string topic, string subscription, bool requiresSequentialProcessing, ISessionSubscriptionReceiverInstrumentation instrumentation, RetryStrategy backgroundRetryStrategy)
        {
            this.settings = settings;
            this.topic = topic;
            this.subscription = subscription;
            this.requiresSequentialProcessing = requiresSequentialProcessing;
            this.instrumentation = instrumentation;

            this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
            this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);

            var messagingFactory = MessagingFactory.Create(this.serviceUri, tokenProvider);
            this.client = messagingFactory.CreateSubscriptionClient(topic, subscription);
            if (this.requiresSequentialProcessing)
            {
                this.client.PrefetchCount = 10;
            }
            else
            {
                this.client.PrefetchCount = 15;
            }

            this.dynamicThrottling =
                new DynamicThrottling(
                    maxDegreeOfParallelism: 160,
                    minDegreeOfParallelism: 30,
                    penaltyAmount: 3,
                    workFailedPenaltyAmount: 5,
                    workCompletedParallelismGain: 1,
                    intervalForRestoringDegreeOfParallelism: 10000);
            this.receiveRetryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(backgroundRetryStrategy);
            this.receiveRetryPolicy.Retrying += (s, e) =>
                {
                    this.dynamicThrottling.Penalize();
                    Trace.TraceWarning(
                        "An error occurred in attempt number {1} to receive a message from subscription {2}: {0}",
                        e.LastException.Message,
                        e.CurrentRetryCount,
                        this.subscription);
                };
        }
Exemplo n.º 17
0
 public TopicSender(ServiceBusSettings settings, string topic)
 {
     retryPolicy = new RetryPolicy <ServiceBusTransientErrorDetectionStrategy>(RetryStrategy.DefaultFixed);
     topicClient = TopicClient.CreateFromConnectionString(settings.ConnectionString, topic);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopicSender"/> class,
 /// automatically creating the given topic if it does not exist.
 /// </summary>
 public TopicSender(ServiceBusSettings settings, string topic)
     : this(settings, topic, new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }
Exemplo n.º 19
0
 public ServiceBusConfig(ServiceBusSettings settings)
 {
     this.settings = settings;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopicSender"/> class, 
 /// automatically creating the given topic if it does not exist.
 /// </summary>
 public TopicSender(ServiceBusSettings settings, string topic)
     : this(settings, topic, new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1)))
 {
 }