public ConsumerService(IGateFactory gateFactory) { _gateFactory = gateFactory; _gateTemporaryConsumers = new ConcurrentDictionary <string, IGateConsumer>(); _consumerContexts = new ConcurrentDictionary <string, ConcurrentDictionary <Guid, HttpContext> >(); }
public void Initialize() { _gateFactory = A.Fake <IGateFactory>(); _fallbackService = A.Fake <IFallbackService>(); _httpClientFactory = A.Fake <IHttpClientFactory>(); var logger = A.Fake <ILogger <SubscriberService> >(); _toTest = new SubscriberService(_gateFactory, new List <IFallbackService> { _fallbackService }, _httpClientFactory, logger); }
public SubscriberService( IGateFactory gateFactory, IEnumerable <IFallbackService> fallbackServices, IHttpClientFactory httpClientFactory, ILogger <SubscriberService> logger) { _gateFactory = gateFactory; _fallbackServices = fallbackServices; _httpClientFactory = httpClientFactory; _logger = logger; _proxyConsumers = new ConcurrentDictionary <string, ProxyConsumer>(); }
public static IGateConsumer CreateConsumer <TMessage, TReply>( this IGateFactory brokerFactory, string serviceName, string topicName, Func <GateContext <TMessage, TReply>, CancellationToken, Task> messageHandler, Action abortedHandler, bool autoDelete, int maxConcurrentMessages) { serviceName = serviceName ?? throw new ArgumentNullException(nameof(serviceName)); topicName = topicName ?? throw new ArgumentNullException(nameof(topicName)); return(brokerFactory.CreateConsumer(serviceName, topicName, async(context, cancellationToken) => { var genericContext = new GateContext <TMessage, TReply>( message: Serializer.Deserialize <TMessage>(context.Message), isRequest: context.IsRequest ); await messageHandler(genericContext, cancellationToken); if (genericContext.IsRequest) { context.Reply = Serializer.Serialize(genericContext.Reply); } }, abortedHandler, autoDelete, maxConcurrentMessages)); }