Search code examples
c#.netazure-servicebus-queues

Serialization of Azure Service Bus BrokeredMessage


I have a stateless RESTful service that will Peek & Lock off of an Azure Service Bus queue. After it gets the message, it will forward the message on to a client who will process it. The client may take longer than the lock timeout to process the message.

The client cannot talk to the queue directly and I would prefer to not add any state to the service. Instead, I want to send enough information to the client such that they can send it back and the service can renew the lock on their behalf.

So, how do I serialize a BrokeredMessage such that I can renew the lock on it after deserializing it?

Alternatively, is there some way I can get a token for a BrokeredMessage such that I can renew the lock or delete the message from the queue using just that token (rather than the entire message)?


Solution

  • Per the Azure Service Bus REST API reference, the renew action requires the MessageId and the LockToken, both of which are available as properties on the BrokeredMessage object. You should be able to use those to fire off a REST request to renew your lock.