//subcribe to queue public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = _subsManager.GetEventKey <T>(); DoInternalSubscription(eventName); _subsManager.AddSubscription <T, TH>(); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = typeof(T).Name.Replace(INTEGRATION_EVENT_SUFIX, ""); var containsKey = _subscriptionManager.HasSubscriptionForEvent <T>(); if (!containsKey) { try { _subscriptionClient.AddRuleAsync(new RuleDescription { //CorrelationFilter - Holds a set of conditions that is evaluated in the ServiceBus service against the arriving messages' //user -defined properties and system properties. A match exists when an arriving message's value for a //property is equal to the value specified in the correlation filter. Filter = new CorrelationFilter { Label = eventName }, Name = eventName }).GetAwaiter().GetResult(); } catch (ServiceBusException) { _logger.LogInformation($"This messaging entity { eventName } already exist!!"); } } _subscriptionManager.AddSubscription <T, TH>(); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { _subsManager.AddSubscription <T, TH>(); _channelManager.CreateAsync <T>(ProcessEvent, _cts.Token).GetAwaiter().GetResult(); }
public void Subscribe <TIntegrationEvent, TIntegrationEventHandler>() where TIntegrationEvent : IIntegrationEvent where TIntegrationEventHandler : IIntegrationEventHandler <TIntegrationEvent> { var eventName = _subscriptionManager.GetEventName <TIntegrationEvent>(); var containsKey = _subscriptionManager.HasSubscriptionsForEvent(eventName); if (containsKey) { return; } if (!_persistentConnection.IsConnected) { _persistentConnection.TryConnect(); } using (var channel = _persistentConnection.CreateModel()) { channel.QueueBind ( routingKey: eventName, exchange: _brokerName, queue: _queueName ); } _subscriptionManager.AddSubscription <TIntegrationEvent, TIntegrationEventHandler>(); }
public async Task SubscribeAsync <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = typeof(T).Name; using (var consumer = _kafkaConnection.ConsumerBuilder <T>()) { //subscribe the handler to the event _subscriptionManager.AddSubscription <T, TH>(); consumer.Subscribe(eventName); //create a task to listen to the topic await Task.Run(async() => { while (true) { try { //_logger.LogInformation($"Consuming from topic {eventName}"); var consumerResult = consumer.Consume(); await ProcessEvent(consumerResult.Message.Value); } catch (ConsumeException e) { _logger.LogError($"Error `{e.Error.Reason}` occured during consuming the event from topic {eventName}"); _logger.LogError(e.Message + "\n" + e.StackTrace); } } }).ConfigureAwait(false); } }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = typeof(T).Name.Replace(IntegrationEventSuffix, ""); var containsKey = _subsManager.HasSubscriptionsForEvent <T>(); if (!containsKey) { try { _subscriptionClient.AddRuleAsync(new RuleDescription { Filter = new CorrelationFilter { Label = eventName }, Name = eventName }).GetAwaiter().GetResult(); } catch (ServiceBusException) { } } _subsManager.AddSubscription <T, TH>(); }
public void Subscribe <TEvent, THandler>(string keyOverride = null) where TEvent : IIntegrationEvent where THandler : IIntegrationEventHandler <TEvent> { var eventName = string.IsNullOrWhiteSpace(keyOverride) ? _busSubscriptionManager.GetEventKey <TEvent>() : keyOverride; _logger.LogInformation($"Socket subscription manager: subscribed to: {eventName}"); _busSubscriptionManager.AddSubscription <TEvent, THandler>(eventName); _subscriptionKeys.Add(eventName); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = subscriptionManager.GetEventKey <T>(); DoInternalSubscription(eventName); logger.LogTrace($"Subscribing for event {eventName}"); subscriptionManager.AddSubscription <T, TH>(); StartBasicConsume(); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = _subsManager.GetEventKey <T>(); DoInternalSubscription(eventName); _logger.LogInformation("Subscribing to event {EventName} with {EventHandler}", eventName, typeof(TH).GetGenericTypeName()); _subsManager.AddSubscription <T, TH>(); StartBasicConsume(); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = _subscriptionManager.GetEventKey <T>(); DoInternalSubscription(eventName); _logger.LogInformation($"Assinando o evento {eventName} com {typeof(TH).GetGenericTypeName()}"); _subscriptionManager.AddSubscription <T, TH>(); StartBasicConsume(); }
public void Subscribe <TE, TH>() where TE : IntegrationEvent where TH : IIntegrationEventHandler <TE> { string routingKey = typeof(TE).Name; _subsManager.AddSubscription <TE, TH>(); var handler = _subsManager.GetHandlerType(routingKey); //internalSubscription, bu routing Key'deki mesajlarla ilgileniyorum, queue'ma gelsin. this._consumerChannel.QueueBind(this._queueName, this.exchange_Name, routingKey, null); _logger.LogInformation(" [x] Queue {0} subscribed for routingKey: {1} with eventHandler: {2}", this._queueName, routingKey, typeof(TH).Name); }
public void Subscribe <T, TH>() where T : IntegrationEvent where TH : IIntegrationEventHandler <T> { var eventName = _subsManager.GetEventKey <T>(); var containsKey = _subsManager.HasSubscriptionsForEvent(eventName); if (!containsKey) { using (var channel = _persistentConnection.CreateModel()) { channel.QueueBind(queue: _queueName, exchange: _brokerName, routingKey: eventName, arguments: null); } } _subsManager.AddSubscription <T, TH>(); }
public void Subscribe <E, EH>() where E : IntegrationEvent where EH : IIntegrationEventHandler <E> { if (!_connection.IsConnected) { if (!_connection.Connect()) { var msg = $"No open connection. Event {typeof(E)} will be not published."; _logger.LogWarning(msg); throw new InvalidOperationException(msg); } } _subscriptionManager.AddSubscription <E, EH>(); using (var ch = _connection.CreateModel()) { ch.QueueBind(_queueName, _exchangeName, routingKey: _subscriptionManager.GetEventKey <E>()); } StartConsume(); }
public void Subscribe <TEvent, TEventHandler>() where TEvent : IntegrationEventBase where TEventHandler : IIntegrationEventHandler <TEvent> { EnsureConnected(); var subscriptionAdded = _eventBusSubscriptionManager.AddSubscription <TEvent, TEventHandler>(); if (!subscriptionAdded) { return; } using (var channel = _persistentRabbitMqConnection.CreateChannel()) { EnsureExchangeDeclared(channel); EnsureQueueDeclared(channel); var eventName = typeof(TEvent).Name; BindQueueToRoutingKey(channel, eventName); } }
public void Subscribe <TEvent, THandler>() where TEvent : Event where THandler : IEventHandler <TEvent> { _evSubscriptionManager.AddSubscription <TEvent, THandler>(); }