Arian Kulp
Arian Kulp

Reputation: 833

Override visibility time for queued message [ServiceStack]

For long-running message-based requests, we can set the visibility timeout at the queue level, but there doesn't appear to be a way to override it at the message level. I'd like to be able to extend the time for long-running operations without just setting a queue-wide extra long timeout. The underlying SQS service provides the ChangeMessageVisibility function but it's not exposed. From what I can tell, RedisMQ doesn't support the concept at all.

  1. Is there effectively ever a timeout and retry for RedisMQ?
  2. Is it possible to expose the ability to extend visibility time from within a service? A long-running operation could then call it periodically to get enough time.

Upvotes: 1

Views: 202

Answers (1)

mythz
mythz

Reputation: 143349

Redis MQ is not related to Amazon SQS or ServiceStack's Amazon SQS MQ other than they're different concrete implementations of ServiceStack's Messaging APIs but a ServiceStack AppHost can only have 1 IMessageService registered so I don't understand how using Redis MQ is relevant to your use of Amazon SQS?

Redis MQ is built on top of Redis's List and Pub/Sub primitives and doesn't contain any such MQ customizations.

If you're just referring to Amazon SQS MQ then there's a RegisterHandler overload that lets you specify the visibilityTimeoutSeconds per message Type so you could have long-running requests executed with a different Request DTO Type which would be my recommendation to keep them isolated. ServiceStack's Auto Mapping makes it easy to convert between Request DTOs with the same schema, e.g:

public object Any(MyRequest request) { ... }
public object Any(LongRunning request) => Any(request.ConvertTo<MyRequest>());

The SqsMqServer does have RequestFilter and ResponseFilter you can use to inspect the IMessage<T> that's returned by ServiceStack MQ which can be used to change the metadata sent in the SQS Message but not any of its custom message-level properties.

To enable fine-grained access to SQS I've added the following filters to SqsMqServer, SqsMqMessageFactory and SqsMqClient in this commit which will allow you to intercept and customize the requests going to and coming from Amazon SQS:

Action<SendMessageRequest,IMessage> SendMessageRequestFilter { get; set; }
Action<ReceiveMessageRequest> ReceiveMessageRequestFilter { get; set; }
Action<Amazon.SQS.Model.Message, IMessage> ReceiveMessageResponseFilter { get; set; }
Action<DeleteMessageRequest> DeleteMessageRequestFilter { get; set; }
Action<ChangeMessageVisibilityRequest> ChangeMessageVisibilityRequestFilter { get; set; }

This change is available from v5.4.1 that's now available on MyGet.

Upvotes: 1

Related Questions