Beispiel #1
0
        public IdentifierMapperHost(GlobalOptions options, ISwapIdentifiers swapper = null)
            : base(options)
        {
            _consumerOptions = options.IdentifierMapperOptions;

            FansiImplementations.Load();

            if (swapper == null)
            {
                Logger.Info("Not passed a swapper, creating one of type " + options.IdentifierMapperOptions.SwapperType);
                _swapper = ObjectFactory.CreateInstance <ISwapIdentifiers>(options.IdentifierMapperOptions.SwapperType, typeof(ISwapIdentifiers).Assembly);
            }
            else
            {
                _swapper = swapper;
            }

            // If we want to use a Redis server to cache answers then wrap the mapper in a Redis caching swapper
            if (!string.IsNullOrWhiteSpace(options.IdentifierMapperOptions.RedisConnectionString))
            {
                try
                {
                    _swapper = new RedisSwapper(options.IdentifierMapperOptions.RedisConnectionString, _swapper);
                }
                catch (RedisConnectionException e)
                {
                    // NOTE(rkm 2020-03-30) Log & throw! I hate this, but if we don't log here using NLog, then the exception will bubble-up
                    //                      and only be printed to STDERR instead of to the log file and may be lost
                    Logger.Error(e, "Could not connect to Redis");
                    throw;
                }
            }

            _swapper.Setup(_consumerOptions);
            Logger.Info($"Swapper of type {_swapper.GetType()} created");

            // Batching now handled implicitly as backlog demands
            _producerModel = RabbitMqAdapter.SetupProducer(options.IdentifierMapperOptions.AnonImagesProducerOptions, isBatch: true);

            Consumer = new IdentifierMapperQueueConsumer(_producerModel, _swapper)
            {
                AllowRegexMatching = options.IdentifierMapperOptions.AllowRegexMatching
            };

            // Add our event handler for control messages
            AddControlHandler(new IdentifierMapperControlMessageHandler(_swapper));
        }
Beispiel #2
0
        public IdentifierMapperQueueConsumer(IProducerModel producer, ISwapIdentifiers swapper)
        {
            _producer = producer;
            _swapper  = swapper;
            acker     = new Thread(() =>
            {
                try
                {
                    while (true)
                    {
                        List <Tuple <IMessageHeader, ulong> > done = new List <Tuple <IMessageHeader, ulong> >();
                        Tuple <DicomFileMessage, IMessageHeader, ulong> t;
                        t = msgq.Take();

                        lock (_producer)
                        {
                            _producer.SendMessage(t.Item1, t.Item2, "");
                            done.Add(new Tuple <IMessageHeader, ulong>(t.Item2, t.Item3));
                            while (msgq.TryTake(out t))
                            {
                                _producer.SendMessage(t.Item1, t.Item2, "");
                                done.Add(new Tuple <IMessageHeader, ulong>(t.Item2, t.Item3));
                            }
                            _producer.WaitForConfirms();
                            foreach (var ack in done)
                            {
                                Ack(ack.Item1, ack.Item2);
                            }
                        }
                    }
                }
                catch (InvalidOperationException)
                {
                    // The BlockingCollection will throw this exception when closed by Shutdown()
                    return;
                }
            });
            acker.IsBackground = true;
            acker.Start();
        }
Beispiel #3
0
        public MapperSource([NotNull] GlobalOptions globalOptions, TriggerUpdatesFromMapperOptions cliOptions)
        {
            _cliOptions    = cliOptions;
            _globalOptions = globalOptions;

            FansiImplementations.Load();

            try
            {
                var objectFactory = new MicroserviceObjectFactory();
                _swapper = objectFactory.CreateInstance <ISwapIdentifiers>(globalOptions.IdentifierMapperOptions.SwapperType, typeof(ISwapIdentifiers).Assembly);
            }
            catch (System.Exception ex)
            {
                throw new System.Exception($"Could not create IdentifierMapper Swapper with SwapperType:{globalOptions.IdentifierMapperOptions?.SwapperType ?? "Null"}", ex);
            }

            if (_swapper == null)
            {
                throw new ArgumentException("No SwapperType has been specified in GlobalOptions.IdentifierMapperOptions");
            }
        }
Beispiel #4
0
 public IdentifierMapperControlMessageHandler(ISwapIdentifiers swapper)
 {
     _swapper = swapper;
     _logger  = LogManager.GetCurrentClassLogger();
 }
Beispiel #5
0
 public RedisSwapper(string redisHost, ISwapIdentifiers wrappedSwapper)
 {
     _logger        = LogManager.GetCurrentClassLogger();
     _redis         = ConnectionMultiplexer.Connect(redisHost);
     _hostedSwapper = wrappedSwapper;
 }