public static Configure AzureServiceBusMessageQueue(this Configure config)
        {
            var configSection = Configure.GetConfigSection <AzureServiceBusQueueConfig>();

            if (configSection == null)
            {
                throw new ConfigurationErrorsException("No AzureServiceBusQueueConfig configuration section found");
            }

            Address.InitializeAddressMode(AddressMode.Remote);

            var credentials     = TokenProvider.CreateSharedSecretTokenProvider(configSection.IssuerName, configSection.IssuerKey);
            var serviceUri      = ServiceBusEnvironment.CreateServiceUri("sb", configSection.ServiceNamespace, string.Empty);
            var namespaceClient = new NamespaceManager(serviceUri, credentials);
            var factory         = MessagingFactory.Create(serviceUri, credentials);

            Address.OverrideDefaultMachine(serviceUri.ToString());

            config.Configurer.RegisterSingleton <NamespaceManager>(namespaceClient);
            config.Configurer.RegisterSingleton <MessagingFactory>(factory);

            config.Configurer.ConfigureComponent <AzureServiceBusMessageQueue>(DependencyLifecycle.SingleInstance);

            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.LockDuration, TimeSpan.FromMilliseconds(configSection.LockDuration));
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.MaxSizeInMegabytes, configSection.MaxSizeInMegabytes);
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.RequiresDuplicateDetection, configSection.RequiresDuplicateDetection);
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.RequiresSession, configSection.RequiresSession);
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.DefaultMessageTimeToLive, TimeSpan.FromMilliseconds(configSection.DefaultMessageTimeToLive));
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.EnableDeadLetteringOnMessageExpiration, configSection.EnableDeadLetteringOnMessageExpiration);
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.DuplicateDetectionHistoryTimeWindow, TimeSpan.FromMilliseconds(configSection.DuplicateDetectionHistoryTimeWindow));
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.MaxDeliveryCount, configSection.MaxDeliveryCount);
            Configure.Instance.Configurer.ConfigureProperty <AzureServiceBusMessageQueue>(t => t.EnableBatchedOperations, configSection.EnableBatchedOperations);

            if (!string.IsNullOrEmpty(configSection.QueueName))
            {
                Configure.Instance.DefineEndpointName(configSection.QueuePerInstance
                                                          ? QueueIndividualizer.Individualize(configSection.QueueName)
                                                          : configSection.QueueName);
            }
            else if (RoleEnvironment.IsAvailable)
            {
                Configure.Instance.DefineEndpointName(RoleEnvironment.CurrentRoleInstance.Role.Name);
            }
            Address.InitializeLocalAddress(Configure.EndpointName);


            return(config);
        }
Beispiel #2
0
        public static Configure AzureMessageQueue(this Configure config)
        {
            CloudQueueClient queueClient;

            var configSection = Configure.GetConfigSection <AzureQueueConfig>();

            Address.InitializeAddressMode(AddressMode.Remote);

            if (configSection != null)
            {
                queueClient = CloudStorageAccount.Parse(configSection.ConnectionString).CreateCloudQueueClient();
                Address.OverrideDefaultMachine(configSection.ConnectionString);
            }
            else
            {
                queueClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient();
                Address.OverrideDefaultMachine(NServiceBus.Unicast.Queuing.Azure.AzureMessageQueue.DefaultConnectionString);
            }

            config.Configurer.RegisterSingleton <CloudQueueClient>(queueClient);

            config.Configurer.ConfigureComponent <AzureMessageQueue>(DependencyLifecycle.SingleInstance)
            .ConfigureProperty(p => p.PurgeOnStartup, ConfigurePurging.PurgeRequested);

            if (configSection != null)
            {
                Configure.Instance.Configurer.ConfigureProperty <AzureMessageQueue>(t => t.PurgeOnStartup, configSection.PurgeOnStartup);
                Configure.Instance.Configurer.ConfigureProperty <AzureMessageQueue>(t => t.MaximumWaitTimeWhenIdle, configSection.MaximumWaitTimeWhenIdle);
                Configure.Instance.Configurer.ConfigureProperty <AzureMessageQueue>(t => t.MessageInvisibleTime, configSection.MessageInvisibleTime);
                Configure.Instance.Configurer.ConfigureProperty <AzureMessageQueue>(t => t.PeekInterval, configSection.PeekInterval);
            }

            if (configSection != null && !string.IsNullOrEmpty(configSection.QueueName))
            {
                Configure.Instance.DefineEndpointName(configSection.QueuePerInstance
                                                          ? QueueIndividualizer.Individualize(configSection.QueueName)
                                                          : configSection.QueueName);
            }
            else if (RoleEnvironment.IsAvailable)
            {
                Configure.Instance.DefineEndpointName(RoleEnvironment.CurrentRoleInstance.Role.Name);
            }
            Address.InitializeLocalAddress(Configure.EndpointName);


            return(config);
        }
        public override void Initialize()
        {
            CloudQueueClient queueClient;

            var configSection = NServiceBus.Configure.GetConfigSection <AzureQueueConfig>();

            var connectionString = TryGetConnectionString(configSection);

            if (string.IsNullOrEmpty(connectionString))
            {
                queueClient = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient();
            }
            else
            {
                queueClient = CloudStorageAccount.Parse(connectionString).CreateCloudQueueClient();

                Address.OverrideDefaultMachine(connectionString);
            }

            NServiceBus.Configure.Instance.Configurer.RegisterSingleton <CloudQueueClient>(queueClient);

            NServiceBus.Configure.Component <AzureMessageQueueReceiver>(DependencyLifecycle.InstancePerCall)
            .ConfigureProperty(p => p.PurgeOnStartup, ConfigurePurging.PurgeRequested);
            NServiceBus.Configure.Component <AzureMessageQueueSender>(DependencyLifecycle.InstancePerCall);
            NServiceBus.Configure.Component <PollingDequeueStrategy>(DependencyLifecycle.InstancePerCall);
            NServiceBus.Configure.Component <AzureMessageQueueCreator>(DependencyLifecycle.InstancePerCall);


            SettingsHolder.ApplyTo <AzureMessageQueueReceiver>();

            if (configSection != null && !string.IsNullOrEmpty(configSection.QueueName))
            {
                var queueName = configSection.QueueName;

                if (SettingsHolder.GetOrDefault <bool>("AzureMessageQueueReceiver.QueuePerInstance"))
                {
                    queueName = QueueIndividualizer.Individualize(queueName);
                }

                NServiceBus.Configure.Instance.DefineEndpointName(queueName);
            }
            else if (IsRoleEnvironmentAvailable())
            {
                NServiceBus.Configure.Instance.DefineEndpointName(RoleEnvironment.CurrentRoleInstance.Role.Name);
            }
            Address.InitializeLocalAddress(NServiceBus.Configure.EndpointName);
        }
Beispiel #4
0
 /// <summary>
 /// Configures a queue per instance
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public static Configure QueuePerInstance(this Configure config)
 {
     Configure.Instance.DefineEndpointName(QueueIndividualizer.Individualize(Configure.EndpointName));
     Address.InitializeLocalAddress(Configure.EndpointName);
     return(config);
 }
        protected override void InternalConfigure(Configure config)
        {
            Categories.Serializers.SetDefault <JsonSerialization>();

            if (IsRoleEnvironmentAvailable())
            {
                EnableByDefault <QueueAutoCreation>();

                if (!IsHostedIn.ChildHostProcess())
                {
                    config.AzureConfigurationSource();
                }
            }

            var configSection = NServiceBus.Configure.GetConfigSection <AzureServiceBusQueueConfig>();

            if (configSection != null && !string.IsNullOrEmpty(configSection.QueueName))
            {
                NServiceBus.Configure.Instance.DefineEndpointName(configSection.QueuePerInstance ? QueueIndividualizer.Individualize(configSection.QueueName) : configSection.QueueName);
                Address.InitializeLocalAddress(NServiceBus.Configure.EndpointName);
            }
            else if (IsRoleEnvironmentAvailable())
            {
                NServiceBus.Configure.Instance.DefineEndpointName(RoleEnvironment.CurrentRoleInstance.Role.Name);
                Address.InitializeLocalAddress(NServiceBus.Configure.EndpointName);
            }

            var serverWaitTime = AzureServicebusDefaults.DefaultServerWaitTime;

            if (configSection != null)
            {
                serverWaitTime = configSection.ServerWaitTime;
            }

            // make sure the transaction stays open a little longer than the long poll.
            NServiceBus.Configure.Transactions.Advanced(settings => settings.DefaultTimeout(TimeSpan.FromSeconds(serverWaitTime * 1.1)).IsolationLevel(IsolationLevel.Serializable));


            Enable <AzureServiceBusTransport>();
            EnableByDefault <TimeoutManager>();
            AzureServiceBusPersistence.UseAsDefault();
        }