Exemplo n.º 1
0
        protected RedisMessagesConsumerManager CreaterConsumerManager(
            string taskQueue,
            string processingQueuePrefix,
            TestDtoHandler[] testDtoHandlers,
            string deadLetterQueue      = "deadletter",
            int instanceCount           = 1,
            int lookupDelayMilliseconds = 1,
            ITestOutputHelper output    = null)
        {
            var logger = output != null
                ? new TestOutputLogger <RedisMessagesConsumerManager>(output)
                : (ILogger <RedisMessagesConsumerManager>)NullLogger <RedisMessagesConsumerManager> .Instance;

            var consumeManager = new RedisMessagesConsumerManager(
                logger,
                ConnectionString,
                new RedisMQSettings
            {
                TasksQueueName          = taskQueue,
                DeadLetterQueue         = deadLetterQueue,
                InstancesCount          = instanceCount,
                LookupDelayMilliseconds = lookupDelayMilliseconds,
                ProcessingQueuePrefix   = processingQueuePrefix
            },
                new DefaultRedisMessageKeyBuilder());

            foreach (var handler in testDtoHandlers)
            {
                consumeManager.RegisterMessageHandler(handler);
            }

            return(consumeManager);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var connectionString = "127.0.0.1:6379,abortConnect=false";

            _multiplexer = ConnectionMultiplexer.Connect(connectionString);
            _uniqPrefix  = Guid.NewGuid().ToString("N");

            _tasksQueue            = _uniqPrefix + "_TaskQueue";
            _processingQueuePrefix = _uniqPrefix + "_ProcessingQueue_";

            var consumer1 = new RedisMessagesConsumerManager(
                NullLogger <RedisMessagesConsumerManager> .Instance,
                connectionString,
                new RedisMQSettings()
            {
                DeadLetterQueue         = "ddd",
                InstancesCount          = 2,
                LookupDelayMilliseconds = 2 * 1000,
                ProcessingQueuePrefix   = _processingQueuePrefix,
                TasksQueueName          = _tasksQueue
            });

            var consumer2 = new RedisMessagesConsumerManager(
                NullLogger <RedisMessagesConsumerManager> .Instance,
                connectionString,
                new RedisMQSettings()
            {
                DeadLetterQueue         = "ddd",
                InstancesCount          = 2,
                LookupDelayMilliseconds = 2 * 1000,
                ProcessingQueuePrefix   = _processingQueuePrefix,
                TasksQueueName          = _tasksQueue
            });

            Console.WriteLine("registering");
            consumer2.RegisterMessageHandler(new ConsoleOuputHanlder("2", NullLogger.Instance));
            consumer1.RegisterMessageHandler(new ConsoleOuputHanlder("1", NullLogger.Instance));

            Console.WriteLine("starting");
            consumer1.Start();
            consumer2.Start();

            Console.WriteLine("started");
            var redisMessageSender = new RedisMessageSender(_tasksQueue);

            RunPressure(redisMessageSender);

            Console.ReadLine();
        }