Exemplo n.º 1
0
        public void Test_ReceiverConfig_Validate()
        {
            // Arrange
            var setup = new ReceiverSetup();

            // Act/Assert
            Assert.Throws <ArgumentException>(() => setup.Validate());
            setup.EntityType = EntityType.Queue;
            setup.EntityName = "test";
            AssertExtensions.DoesNotThrow(() => setup.Validate());
            setup.EntityType = EntityType.Topic;
            Assert.Throws <ArgumentException>(() => setup.Validate());
            setup.EntitySubscriptionName = "test";
            AssertExtensions.DoesNotThrow(() => setup.Validate());
            setup.ToString().Should().NotBeNull();
            setup.EntityFilter = new KeyValuePair <string, string>("test", "test");
            setup.ToString().Should().NotBeNull();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add service bus singleton of type ServiceBusMessenger, using named properties (as opposed to passing MsiConfig/ServicePrincipleConfig etc).
 /// Will automatically use MsiConfiguration.
 /// </summary>
 /// <param name="services">Service collection to extend</param>
 /// <param name="key">Key to identify the named instance of the service bus singleton.</param>
 /// <param name="instanceName">Instance name of service bus.</param>
 /// <param name="tenantId">Tenant Id where service bus exists.</param>
 /// <param name="subscriptionId">Subscription within the tenancy to use for the service bus instance.</param>
 /// <param name="receiver">Receiver configuration (if any).</param>
 /// <param name="sender">Sender configuration (if any).</param>
 /// <param name="enableAutoBackoff">Back-off mechanism enabled (only works when both sender and receiver is configured).</param>
 /// <returns>Modified service collection with the ServiceBusMessenger and NamedInstanceFactory{ServiceBusMessenger} configured.</returns>
 public static IServiceCollection AddServiceBusSingletonNamed(this IServiceCollection services, string key, string instanceName, string tenantId, string subscriptionId, ReceiverSetup receiver = null, SenderSetup sender = null, bool enableAutoBackoff = false)
 {
     return(AddNamedInstance <ServiceBusMessenger>(services, key, new ServiceBusMessenger(new MsiConfig
     {
         InstanceName = instanceName,
         TenantId = tenantId,
         SubscriptionId = subscriptionId,
         Receiver = receiver,
         Sender = sender,
         EnableAutobackOff = enableAutoBackoff
     })));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add service bus singleton of type T, using named properties (as opposed to passing MsiConfig/ServicePrincipleConfig etc).
 /// Will automatically use MsiConfiguration.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="services">Service collection to extend</param>
 /// <param name="instanceName">Instance name of service bus.</param>
 /// <param name="tenantId">Tenant Id where service bus exists.</param>
 /// <param name="subscriptionId">Subscription within the tenancy to use for the service bus instance.</param>
 /// <param name="receiver">Receiver configuration (if any).</param>
 /// <param name="sender">Sender configuration (if any).</param>
 /// <param name="enableAutoBackoff">Back-off mechanism enabled (only works when both sender and receiver is configured).</param>
 /// <returns>Modified service collection with the IReactiveMessenger or IMessenger instance and NamedInstanceFactory{T} configured.</returns>
 public static IServiceCollection AddServiceBusSingleton <T>(this IServiceCollection services, string instanceName, string tenantId, string subscriptionId, ReceiverSetup receiver = null, SenderSetup sender = null, bool enableAutoBackoff = false)
     where T : IMessageOperations
 {
     return(services.AddServiceBusSingletonNamed <T>(null, instanceName, tenantId, subscriptionId, receiver, sender, enableAutoBackoff));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Add service bus singleton of type T, using named properties (as opposed to passing MsiConfig/ServicePrincipleConfig etc).
        /// Will automatically use MsiConfiguration.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="services">Service collection to extend</param>
        /// <param name="key">Key to identify the named instance of the service bus singleton.</param>
        /// <param name="instanceName">Instance name of service bus.</param>
        /// <param name="tenantId">Tenant Id where service bus exists.</param>
        /// <param name="subscriptionId">Subscription within the tenancy to use for the service bus instance.</param>
        /// <param name="receiver">Receiver configuration (if any).</param>
        /// <param name="sender">Sender configuration (if any).</param>
        /// <param name="enableAutoBackoff">Backoff mechanism enabled (only works when both sender and receiver is configured).</param>
        /// <returns>Modified service collection with the IReactiveMessenger, IMessenger and NamedInstanceFactory{T} configured.</returns>
        public static IServiceCollection AddServiceBusSingletonNamed <T>(this IServiceCollection services, string key, string instanceName, string tenantId, string subscriptionId, ReceiverSetup receiver = null, SenderSetup sender = null, bool enableAutoBackoff = false)
            where T : IMessageOperations
        {
            var serviceBusInstance = new ServiceBusMessenger(new MsiConfig
            {
                InstanceName      = instanceName,
                TenantId          = tenantId,
                SubscriptionId    = subscriptionId,
                Receiver          = receiver,
                Sender            = sender,
                EnableAutobackOff = enableAutoBackoff
            });

            if (!key.IsNullOrEmpty())
            {
                serviceBusInstance.Name = key;
            }

            services.AddSingleton(typeof(T), serviceBusInstance);
            services.AddFactoryIfNotAdded <IMessenger>();
            services.AddFactoryIfNotAdded <IReactiveMessenger>();
            return(services);
        }