Example #1
0
        public ConsumerService(IGateFactory gateFactory)
        {
            _gateFactory = gateFactory;

            _gateTemporaryConsumers = new ConcurrentDictionary <string, IGateConsumer>();
            _consumerContexts       = new ConcurrentDictionary <string, ConcurrentDictionary <Guid, HttpContext> >();
        }
Example #2
0
        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);
        }
Example #3
0
        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>();
        }
Example #4
0
        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));
        }