MQ and Responding

I have a few questions about the MQ process and specifically for ServiceStack.Azure.

First, the documentation states that Messages with Responses are published to the Response .inq
Often message handlers will just return a POCO response after it processes a message, e.g:

mqServer.RegisterHandler<Hello>(m =>
new HelloResponse { Result = "Hello, {0}!".Fmt(m.GetBody().Name) });

I’ve been testing the Azure MQ provider and what I don’t understand is that there is no HelloResponse queue created in service bus in my example.

mqServer.RegisterHandler<Hello>(o=>ServiceController.ExecuteMessage(o), noOfThreads:10);

Q1: Should there be a separate queue created in this case? The ExecuteMessage returns a HelloResponse in the code above so I assume it should be put into that queue and I could register a handler for it?

Q2: Is there a way to bypass the .outq if the message is void and we don’t want to notify any other processes? (edit: I see I asked this a while ago and there is a DisablePublishingResponse for an optin for this which I’ll test). If not then I assume we have to empty it ourselves?

See the MqServerIntroTests.cs tests for examples of reading responses from the Response .inq.

Both PublishResponsesWhitelist and DisablePublishingResponses lets you opt-in to specify which Responses you want published.

I’ve also added a DisableNotifyMessages option you can use to disable messages being sent to the .outq. This change is available from v5.1.1 that’s now available on MyGet.

mythz, it looks like you added the DisableNotifyMessages only to the ServiceBus Host. Can that option be added to the redis one as well? Also, I thought if I set PublishResponsesWhitelist to string[]{} it wouldn’t publish those to the outq? Is that a wrong assumption?

Also, should I register an IMessageProducer as transient?

The snippet below, should it publish to the outq after the handler executes?

 var redisFactory = new PooledRedisClientManager(Parameters.GetRedis());
    
 var mqHost = new RedisMqServer(redisFactory, retryCount: 2);
 mqHost.RegisterHandler<TrackLinkDTO>(x=> base.ExecuteMessage(x), 2 );
        
 mqHost.PublishResponsesWhitelist = new string[]{};


    public void Any(TrackLinkDTO req)
    {
        return;
    }

The .outq in Redis is a Pub/Sub topic not a queue, there’s no reason not to publish to it as it’s not persistent and only sends messages to active subscribers who are actively listening for notifications.

No don’t register the IMessageProducer at all, the IMessageService or IMessageFactory are already registered as singletons in ServiceStack. For client (i.e. non ServiceStack client applications) you can register the IMessageFactory as a singleton, e.g:

container.Register<IMessageFactory>(c => 
    new RedisMessageFactory(c.Resolve<IRedisClientsManager>()));

Which you can use either from an injected IMessageFactory or directly from the IOC with:

using (var producer = container.Resolve<IMessageFactory>().CreateMessageProducer())
{
    producer.Publish(...);
}

You don’t need to do this in ServiceStack since IMessageService and IMessageFactory are already registered. Also in Services the recommendation to publish messages is to use the PublishMessage() API, e.g:

public void Any(TrackLinkDTO req)
{
    base.PublishMessage(...);
}
1 Like