1

We are using IMessageQueueClient to push messages onto a Redis queue and pick them up via the registerhandler method. https://docs.servicestack.net/redis-mq#redis

This is working great, no complaints.

However, IMessageQueueClient.Publish() has an overload to set the queue name. Through experimentation, this changes the redis list key from mq:objectname.inq to whatever string you pass in as the client name.

We wish to be able to handle the same object type using a different/prefixed/suffixed channel using the registerhandler method. We are trying to achieve this as we have multiple servers triggering the methods that raise these messages and wish to have these servers process their own messages.

Is this possible to do or will we need to use separate redis servers/separate redis databases?

Barry
  • 357
  • 1
  • 11

1 Answers1

1

I have worked out a way to achieve this. If there is a more elegant way to achieve this, please let me know. Added here for reference for anyone wishing to achieve the same

var redisConnection = "localhost:6379";
        var a = new Test() {
            Id = Guid.NewGuid()
        };

        var b = new Test() {
            Id = Guid.NewGuid()
        };
        var redisFactory = new PooledRedisClientManager(redisConnection);
        var mqHost = new RedisMqServer(redisFactory, retryCount: 5);
        mqHost.RegisterHandler<TestA>(model =>
        {
            Test d = model.Body as Test;
            Debug.Assert(a.Id == d.Id);
            return "A";
        });
        mqHost.RegisterHandler<TestB>(model =>
        {
            Test d = model.Body as Test;
            Debug.Assert(b.Id == d.Id);
            return "B";
        });
        mqHost.Start();
        var client = mqHost.CreateMessageQueueClient();
        var data = MessageFactory.Create(a);
        client.Publish($"mq:{typeof(Test).Name}A.inq", data ); 
        var dataB = MessageFactory.Create(a);
        client.Publish($"mq:{typeof(Test).Name}B.inq", data);
        
       while (true) { }
...
       public class TestA : Test { }
       public class TestB : Test { }
       public class  Test {
           public Guid Id { get; set; }
       }
Barry
  • 357
  • 1
  • 11
  • 1
    FYI the `QueueNames` API lets you [change the queue names used](https://docs.servicestack.net/messaging#flexible-queue-name-strategies), e.g. you can change the prefixes with `QueueNames.SetQueuePrefix("site1.")` (needs to be configured on both client + server). – mythz Nov 19 '21 at 17:54