Exemple #1
0
 public AzureServiceBusConsumerClientFactory(
     ILoggerFactory loggerFactory,
     AzureServiceBusOptions asbOptions)
 {
     _loggerFactory = loggerFactory;
     _asbOptions    = asbOptions;
 }
Exemple #2
0
        // Both AzureServiceBusOptions and JasperOptions are registered services in your
        // Jasper application's IoC container, so are available to be injected into Startup.Configure()
        public void Configure(IApplicationBuilder app, IConfiguration config, AzureServiceBusOptions asb, JasperOptions jasper)
        {
            // This code will add a new Azure Service Bus connection named "azure"
            asb.Connections.Add("azure", config["AzureServiceBusConnectionString"]);

            // Listen for messages from the 'queue1' queue at the connection string
            // configured above
            jasper.ListenForMessagesFrom("azureservicebus://azure/queue/queue1");
        }
 public AzureServiceBusConsumerClient(
     ILogger logger,
     string subscriptionName,
     IOptions <AzureServiceBusOptions> options)
 {
     _logger           = logger;
     _subscriptionName = subscriptionName;
     _asbOptions       = options.Value ?? throw new ArgumentNullException(nameof(options));
 }
Exemple #4
0
        public void Get_WithValidConnectionString_ReturnsTopicClient(
            [CustomizeWith(typeof(AzureServiceBusOptionsCustomization), ValidConnectionString)] AzureServiceBusOptions options,
            string topicName,
            TopicClientProvider sut)
        {
            var topicClient = sut.Get(topicName);

            topicClient.TopicName.Should().Be(topicName);
        }
Exemple #5
0
        public void TopicClientProvider_WithInvalidConnectionString_ThrowsMessagingException(
            [CustomizeWith(typeof(AzureServiceBusOptionsCustomization), InvalidConnectionString)] AzureServiceBusOptions options,
            IFixture fixture)
        {
            Action action = () => fixture.Create <TopicClientProvider>();

            action.Should().Throw <ObjectCreationException>()
            .WithInnerException <TargetInvocationException>()
            .WithInnerException <MessagingException>()
            .WithMessage("The provided Azure Service Bus connection string is invalid.");
        }
        public AzureServiceBusConsumerClient(
            ILogger logger,
            string subscriptionName,
            AzureServiceBusOptions options)
        {
            _logger           = logger;
            _subscriptionName = subscriptionName;
            _asbOptions       = options ?? throw new ArgumentNullException(nameof(options));

            InitAzureServiceBusClient().GetAwaiter().GetResult();
        }
        public AzureServiceBusPublishMessageSender(
            ILogger <AzureServiceBusPublishMessageSender> logger,
            CapOptions options,
            AzureServiceBusOptions asbOptions,
            IStateChanger stateChanger,
            IStorageConnection connection)
            : base(logger, options, connection, stateChanger)
        {
            _logger        = logger;
            ServersAddress = asbOptions.ConnectionString;

            _topicClient = new TopicClient(
                ServersAddress,
                asbOptions.TopicPath,
                RetryPolicy.NoRetry);
        }
Exemple #8
0
        public void Configure(IApplicationBuilder app, AzureServiceBusOptions options)
        {
            // Configure a single endpoint
            options.ConfigureEndpoint("azureservicebus://azure/queue/incoming", endpoint =>
            {
                // modify the endpoint
            });

            // Configure all the endpoints related to a specific connection string
            options.ConfigureEndpoint("azure", endpoint =>
            {
                endpoint.ReceiveMode   = ReceiveMode.ReceiveAndDelete;
                endpoint.RetryPolicy   = RetryPolicy.NoRetry;
                endpoint.TokenProvider = new ManagedServiceIdentityTokenProvider();
                endpoint.TransportType = TransportType.AmqpWebSockets;
            });
        }
Exemple #9
0
        public static IServiceCollection AddAsbRegistration(this IServiceCollection services, AzureServiceBusOptions options)
        {
            services.AddSingleton <IEventBus, EventBusServiceBus>(sp =>
            {
                var serviceBusPersistentConnection = sp.GetRequiredService <IServiceBusPersistentConnection>();
                var lifetimeScope = sp.GetRequiredService <ILifetimeScope>();
                var eventBusSubscriptionsManager = sp.GetRequiredService <IEventBusSubscriptionManager>();

                var autofacScopeName       = options.AutofacScopeName;
                var subscriptionClientName = options.SubscriptionClientName;

                return(new EventBusServiceBus(serviceBusPersistentConnection,
                                              lifetimeScope,
                                              eventBusSubscriptionsManager,
                                              autofacScopeName,
                                              subscriptionClientName));
            });

            services.AddSingleton <IEventBusSubscriptionManager, InMemoryEventBusSubscriptionManager>();

            return(services);
        }
Exemple #10
0
        public static IServiceCollection AddAsbConnection(this IServiceCollection services, AzureServiceBusOptions options)
        {
            if (string.IsNullOrEmpty(options.ConnectionString))
            {
                throw new NullReferenceException("ConnectionString is null or empty.");
            }

            services.AddSingleton <IServiceBusPersistentConnection>(sp =>
            {
                var serviceBusConnection = new ServiceBusConnectionStringBuilder(options.ConnectionString);

                return(new DefaultServiceBusPersistentConnection(serviceBusConnection));
            });

            return(services);
        }
Exemple #11
0
 protected override void Configure(IHostingEnvironment contextHostingEnvironment, IConfiguration configuration,
                                   AzureServiceBusOptions options)
 {
     options.Connections.Add("jasper", end_to_end.ConnectionString);
 }
Exemple #12
0
 private static IServiceCollection AddAzureServiceBusReceiver <TKey, TValue>(this IServiceCollection services, AzureServiceBusOptions options)
 {
     services.AddTransient <IMessageReceiver <TKey, TValue> >(x => new AzureServiceBusReceiver <TKey, TValue>(
                                                                  options.ConnectionString,
                                                                  options.QueueName));
     return(services);
 }
Exemple #13
0
        public static IServiceCollection AddAzureServiceBus(this IServiceCollection services, AzureServiceBusOptions options = null)
        {
            options = options ?? new AzureServiceBusOptions();
            services.AddTransient <IServiceBusPersistentConnection>(sp =>
            {
                var logger = sp.GetRequiredService <ILogger <DefaultServiceBusPersistentConnection> >();

                var serviceBusConnection = new ServiceBusConnectionStringBuilder(options.ConnectionString);

                return(new DefaultServiceBusPersistentConnection(serviceBusConnection, logger));
            });
            services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
            services.AddSingleton <IEventPublisher>(sp =>
            {
                return(new AzureServiceBusEventPublisher(
                           sp.GetRequiredService <IServiceBusPersistentConnection>(),
                           sp.GetRequiredService <ILogger <AzureServiceBusEventPublisher> >()
                           ));
            });
            services.AddSingleton <IEventSubscriber>(sp =>
            {
                return(new AzureServiceBusEventSubscriber(
                           sp.GetRequiredService <IServiceBusPersistentConnection>(),
                           sp.GetRequiredService <ILogger <AzureServiceBusEventSubscriber> >(),
                           options.SubscriptionName
                           ));
            });
            services.AddSingleton <IEventBus>(sp =>
            {
                return(new DefaultEventBus(
                           sp.GetRequiredService <IEventPublisher>(),
                           sp.GetRequiredService <IEventSubscriber>(),
                           sp.GetRequiredService <IEventBusSubscriptionsManager>(),
                           sp,
                           sp.GetRequiredService <ILoggerFactory>().CreateLogger("AzureServiceBus")
                           ));
            });
            return(services);
        }
 public AzureServiceBusPublisher(string name, AzureServiceBusOptions config)
 {
     _config = config;
     _name   = name;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TopicClientProvider"/> class.
        /// </summary>
        /// <param name="options">The Azure Service Bus options</param>
        public TopicClientProvider(AzureServiceBusOptions options)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));

            ValidateServiceBusConnectionString(options.ConnectionString);
        }
 public AzureServiceBusClient(IOptions <AzureServiceBusOptions> config,
                              ILogger <AzureServiceBusClient> logger)
 {
     _logger = logger;
     _config = config.Value;
 }
 public static IServiceCollection AddAzureServiceBusSender <T>(this IServiceCollection services, AzureServiceBusOptions options)
 {
     services.AddSingleton <IMessageSender <T> >(new AzureServiceBusSender <T>(
                                                     options.ConnectionString,
                                                     options.QueueNames[typeof(T).Name]));
     return(services);
 }
 public static IServiceCollection AddAzureServiceBusReceiver <T>(this IServiceCollection services, AzureServiceBusOptions options)
 {
     services.AddTransient <IMessageReceiver <T> >(x => new AzureServiceBusReceiver <T>(
                                                       options.ConnectionString,
                                                       options.QueueNames[typeof(T).Name]));
     return(services);
 }
Exemple #19
0
 private static IServiceCollection AddAzureServiceBusSender <TKey, TValue>(this IServiceCollection services, AzureServiceBusOptions options)
 {
     services.AddSingleton <IMessageSender <TKey, TValue> >(new AzureServiceBusSender <TKey, TValue>(
                                                                options.ConnectionString,
                                                                options.QueueName));
     return(services);
 }