public KafkaEventBus( ProducerConfig producerConfig, ConsumerConfig consumeConfig, AdminClientConfig adminClientConfig, ILogger <KafkaEventBus> logger, IEventBusSubscriptionManager subscriptionManager, IServiceProvider serviceProvider ) { _logger = logger; _consumeConfig = consumeConfig; _serviceProvider = serviceProvider; _adminClientConfig = adminClientConfig; _subscriptionManager = subscriptionManager; _subscriptionManager.OnSubscribe += async(s, e) => { await MakeSureTopicExists(e.EvenType.FullName); var consumer = new PollingBasedConsumer(_consumeConfig); var eventName = e.EvenType.FullName; consumer.OnConsume = async consumeResult => { await Task.WhenAll(ProcessEvent(consumeResult)); consumer.Ack(consumeResult); }; consumer.StartPolling(eventName); }; _producer = BuildProducer <string, byte[]>(producerConfig, builder => { builder.SetKeySerializer(Serializers.Utf8); builder.SetValueSerializer(Serializers.ByteArray); builder.SetErrorHandler((producer, error) => _logger.LogError("ErrorCode={0},Reason={1},IsFatal={2}", error.Code, error.Reason, error.IsFatal)); }); }
public KafkaEventBus(IEventBusSubscriptionManager subscriptionManager, ILogger <KafkaEventBus> logger, KafkaConnection kafkaConnection, IServiceProvider serviceProvider) { this._subscriptionManager = subscriptionManager ?? throw new ArgumentNullException(nameof(subscriptionManager)); this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._kafkaConnection = kafkaConnection ?? throw new ArgumentNullException(nameof(kafkaConnection)); _serviceScopeFactory = serviceProvider?.GetRequiredService <IServiceScopeFactory>() ?? throw new ArgumentException($"Cannot resolve IServiceScopeFactory from {nameof(serviceProvider)}"); }
public EventBusRabbitMq(IPersistentRabbitMqConnection persistentRabbitMqConnection, IEventBusSubscriptionManager eventBusSubscriptionManager, IOptionsMonitor <RabbitMqConfig> rabbitMqConfig, IIntegrationEventProcessor integrationEventProcessor, ILogger <EventBusRabbitMq> logger) { _persistentRabbitMqConnection = persistentRabbitMqConnection ?? throw new ArgumentNullException(nameof(persistentRabbitMqConnection)); _eventBusSubscriptionManager = eventBusSubscriptionManager ?? throw new ArgumentNullException(nameof(eventBusSubscriptionManager)); _integrationEventProcessor = integrationEventProcessor ?? throw new ArgumentNullException(nameof(integrationEventProcessor)); _rabbitMqConfig = rabbitMqConfig?.CurrentValue ?? throw new ArgumentNullException(nameof(rabbitMqConfig)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public void Ctor_OneOfParameterIsNull_ThrowsArgumentNullException( IEventBusSubscriptionManager subsManager, IChanneslManager channelManager, IServiceScopeFactory scopeFactory) { // Act // Assert Assert.Throws <ArgumentNullException>(() => new EventBusInProcess(subsManager, channelManager, scopeFactory)); }
private readonly int _retryCount; //消息重试次数 public RabbitMQEventBus(IRabbitMQPersistentConnection persistentConnection, IEventBusSubscriptionManager subscriptionManager, ILogger <RabbitMQEventBus> logger, IServiceProvider serviceProvider, string exchangeName, string queueName, int retryCount = 5) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(IConnectionFactory)); _subscriptionManager = subscriptionManager ?? throw new ArgumentNullException(nameof(IEventBusSubscriptionManager)); _subscriptionManager.OnSubscribe += (s, e) => StartBasicConsume(e.EvenType.FullName); _subscriptionManager.OnUnsubscribe += (s, e) => UnbindQueue(e.EvenType.FullName); _logger = logger ?? throw new ArgumentNullException(nameof(ILogger <RabbitMQEventBus>)); _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(IServiceProvider)); _exchangeName = exchangeName ?? "rabbitmq-eventbus"; _retryCount = retryCount; }
public EventBusServiceBus(IServiceBusPersistentConnection persistentConnection, ILifetimeScope autofac, IEventBusSubscriptionManager subsManager, string autofacScopeName, string subscriptionClientName = null) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _subsManager = subsManager ?? new InMemoryEventBusSubscriptionManager(); _autofac = autofac ?? throw new ArgumentNullException(nameof(autofac)); _subscriptionClient = new SubscriptionClient(persistentConnection.ServiceBusConnectionStringBuilder, subscriptionClientName); _autofacScopeName = autofacScopeName; RemoveDefaultRule(); RegisterSubscriptionClientMessageHandler(); }
public EventBusRabbitMQ(IRabbitMQPersistentConnection persistentConnection, ILogger <EventBusRabbitMQ> logger, ILifetimeScope autofac, IEventBusSubscriptionManager subsManager, string queueName = null, int retryCount = 5) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _subsManager = subsManager ?? new EventBusSubscriptionManager(); _queueName = queueName; _consumerChannel = CreateConsumerChannel(); _autofac = autofac; _retryCount = retryCount; _subsManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public RabbitMQEventBus(IEventBusSubscriptionManager subscriptionManager, IPersistentConnection connection, string exchangeName, string queueName, ILogger <RabbitMQEventBus> logger, IServiceProvider services) { _subscriptionManager = subscriptionManager; _subscriptionManager.OnEventRemoved += SubscriptionManager_OnEventRemoved; _connection = connection; _exchangeName = exchangeName; _queueName = queueName; _logger = logger; _consumerChannel = CreateConsumerChannel(); _serviceProvider = services; }
public EventBusRabbitMQ(IRabbitMQPersistentConnection persistentConnection, ILogger <EventBusRabbitMQ> logger, IEventBusSubscriptionManager subscriptionManager, ILifetimeScope autofac, string queueName = null, int retryCount = 4) { this.persistentConnection = persistentConnection; this.subscriptionManager = subscriptionManager; this.logger = logger; this.retryCount = retryCount; this.queueName = queueName; this.autofac = autofac; consumerChannel = CreateConsumerChannel(); subscriptionManager.OnEventRemoved += OnEventRemoved; }
public EventBusRabbitMQ(IRabbitMQPersistentConnection persistentConnection, IEventBusSubscriptionManager subscriptionManager, ILifetimeScope scope, ILogger logger, int retryCount, string queueName) { _scope = scope; _persistentConnection = persistentConnection; _subscriptionManager = subscriptionManager ?? new InMemoryEventBusSubscriptionManager(); _logger = logger; _scope = scope; _retryCount = retryCount; _queueName = queueName; _consumerChannel = CreateConsumerChannel(); }
public MyEventBusRabbitMQ(IRabbitMQPersistentConnection persistentConnection, ILogger <MyEventBusRabbitMQ> logger, IServiceScopeFactory scopeFactory, IEventBusSubscriptionManager subsManager, string queueName = null, int retryCount = 5) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory)); _subsManager = subsManager ?? new InMemoryEventBusSubscriptionsManager(); _queueName = queueName; _retryCount = retryCount; _consumerChannel = CreateConsumerChannel(); _subsManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public EventBusRabbitMQ(IRabbitMQConnection persistedConnection, ILogger <EventBusRabbitMQ> logger, ILifetimeScope autofac, IEventBusSubscriptionManager subsManager, string queueName = null, int retryCount = 5) { _connection = persistedConnection; _logger = logger; _subsManager = subsManager; _autofac = autofac; _retryCount = retryCount; _queueName = queueName; _consumerChannel = CreateConsumerChannel(); _subsManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public EventBusInProcess( IEventBusSubscriptionManager subsManager, IChanneslManager channelManager, IServiceScopeFactory scopeFactory) { _subsManager = subsManager ?? throw new ArgumentNullException(nameof(subsManager)); _channelManager = channelManager ?? throw new ArgumentNullException(nameof(subsManager)); _scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory)); _cts = new CancellationTokenSource(); }
public EventBusRabbitMQ(IEventBusSubscriptionManager subsManager, IServiceProvider services) { _subsManager = subsManager; _services = services; _consumerChannel = CreateConsumerChannel(); var factory = new ConnectionFactory() { HostName = _connectionString }; _persistentConnection = factory.CreateConnection(); }
public SocketEventBus(ISocketClient socketClient, ILogger <SocketEventBus> logger, IEventBusSubscriptionManager busSubscriptionManager, ILifetimeScope autofac) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _busSubscriptionManager = busSubscriptionManager ?? throw new ArgumentNullException(nameof(busSubscriptionManager)); _autofac = autofac ?? throw new ArgumentNullException(nameof(autofac)); _subscriptionKeys = new List <string>(); _socketClient = socketClient ?? throw new ArgumentNullException(nameof(socketClient)); _socketClient.MessageReceived += async(s, e) => await ProcessEvent(e?.Envelope); _socketClient.Connected += (s, e) => SendUpdatedSubscriptionList(); }
public RabbitMqEventBus ( IServiceProvider serviceProvider, IEventBusSubscriptionManager subscriptionManager, IRabbitMqPersistentConnection persistentConnection, string queueName, int retryCount = 5 ) { _queueName = queueName; _retryCount = retryCount; _serviceProvider = serviceProvider; _subscriptionManager = subscriptionManager; _persistentConnection = persistentConnection; _subscriptionManager.OnEventRemoved += SubscriptionManager_OnEventRemoved; }
//https://github.com/Azure/azure-service-bus/tree/master/samples/DotNet/GettingStarted/Microsoft.Azure.ServiceBus/TopicSubscriptionWithRuleOperationsSample public ServiceBusEventBus(IServiceBusPersistedConnection serviceBusPersistedConnection, ILogger <ServiceBusEventBus> logger, IEventBusSubscriptionManager subscriptionManager, string subscriptionClientName, ILifetimeScope autofacScope) { _serviceBusPersistedConnection = serviceBusPersistedConnection; _logger = logger; _subscriptionManager = subscriptionManager ?? new InMemoryEventBusSubscriptionsManager(); _autofacScope = autofacScope; _subscriptionClient = new SubscriptionClient(serviceBusPersistedConnection.ServiceBusConnectionStringBuilder, subscriptionClientName); RemoveDefaultRule(); RegisterSubscriptionClientMessageHandler(); }
public EventBusRabbitMq(IRabbitMqPersistentConnection persistentConnection, ILifetimeScope autofac, IEventBusSubscriptionManager subsManager, string brokerName, string autofacScopeName, string queueName = null, int retryCount = 5) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _subsManager = subsManager ?? new InMemoryEventBusSubscriptionManager(); _autofac = autofac ?? throw new ArgumentNullException(nameof(autofac)); _brokerName = brokerName; _autofacScopeName = autofacScopeName; _queueName = queueName; _retryCount = retryCount; _consumerChannel = CreateConsumerChannel(); _subsManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public static IServiceCollection AddEventBus(this IServiceCollection services) { ProducerConfig producerConfiguration = new ProducerConfig { BootstrapServers = "localhost:9092" }; SchemaRegistryConfig schemaRegistryConfiguration = new SchemaRegistryConfig { SchemaRegistryUrl = "localhost:8081", SchemaRegistryRequestTimeoutMs = 5000, SchemaRegistryMaxCachedSchemas = 10 }; AvroSerializerConfig avroSerializerConfiguration = new AvroSerializerConfig { // optional Avro serializer properties: // BufferBytes = 100, AutoRegisterSchemas = true, }; ConsumerConfig consumerConfiguration = new ConsumerConfig { BootstrapServers = "localhost:9092", GroupId = Assembly.GetExecutingAssembly().GetName().Name }; //Set up the event bus services.AddSingleton <KafkaConnection>(new KafkaConnection( producerConfiguration , consumerConfiguration , schemaRegistryConfiguration , avroSerializerConfiguration)); services.AddSingleton <IEventBusSubscriptionManager, EventBusSubscriptionManager>(); services.AddSingleton <IEventBus, KafkaEventBus.KafkaEventBus>(sp => { KafkaConnection kafkaConnection = sp.GetRequiredService <KafkaConnection>(); ILogger <KafkaEventBus.KafkaEventBus> logger = sp.GetRequiredService <ILogger <KafkaEventBus.KafkaEventBus> >(); IEventBusSubscriptionManager eventBusSubcriptionsManager = sp.GetRequiredService <IEventBusSubscriptionManager>(); return(new KafkaEventBus.KafkaEventBus(eventBusSubcriptionsManager, logger, kafkaConnection, sp)); }); return(services); }
public EventBusRabbitMQ(string queueName, IEventBusSubscriptionManager subsManager, ILifetimeScope autoFac, string rabbitMqServer = "eventbus", ILogger <EventBusRabbitMQ> logger = null) { this._logger = logger; this._subsManager = subsManager; this._autofac = autoFac; this.rabbitMQ_hostName = rabbitMqServer; if (logger == null) { this._logger = NullLogger <EventBusRabbitMQ> .Instance; } _logger.LogInformation(" [X] INFO FROM EventBusRabbitMQ:" + "Created new EventBusRabbitMQ instance. for queue: {0}", queueName); _queueName = queueName; }
public AzureServiceBusEventBus( IServiceProvider provider, IAzureServiceBusPersistentConnection <ITopicClient> persitentConnection, string subscriptionName ) { var loggerFactory = new LoggerFactory(); _logger = loggerFactory.CreateLogger <AzureServiceBusEventBus>(); _provider = provider; _persistentConnection = persitentConnection; _evSubscriptionManager = new EventBusSubscriptionManager(); _evSubscriptionManager.OnEventAdded += OnEventAdded; _evSubscriptionManager.OnEventRemoved += OnEventRemoved; _subscriptionClient = new SubscriptionClient(persitentConnection.ConnectionStringBuilder, subscriptionName); _subscriptionClient.PrefetchCount = 300; RegisterMessageListener(); }
public EventBusRabbitMQ( IServiceProvider serviceProvider, string queueName, int retryCount = 5) { _persister = serviceProvider.GetRequiredService <IRabbitMQPersisterConnection>() ?? throw new ArgumentNullException(nameof(_persister)); _logger = serviceProvider.GetRequiredService <ILogger <EventBusRabbitMQ> >() ?? throw new ArgumentNullException(nameof(_logger)); _subscriptionManager = serviceProvider.GetRequiredService <IEventBusSubscriptionManager>() ?? new InMemoryEventBusSubscriptionsManager(); _serviceProvider = serviceProvider; _queueName = queueName; _retryCount = retryCount; _consumerChannel = CreateConsumerChannel(_queueName); _subscriptionManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public IntegrationEventProcessor(IEventBusSubscriptionManager eventBusSubscriptionManager, ILifetimeScope lifetimeScope, ILogger <IIntegrationEventProcessor> logger) { _eventBusSubscriptionManager = eventBusSubscriptionManager ?? throw new ArgumentNullException(nameof(eventBusSubscriptionManager)); _lifetimeScope = lifetimeScope ?? throw new ArgumentNullException(nameof(lifetimeScope)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }