Hi guys,
I'm trying to work on the following scenario:
1) API retrieve next available session, and consume first message of that session. This is a trigger on a logic app.
2) Logic App would process the message and if successful, complete the message at the end.
My code looks like this:
Retrieve API (just the queue handling for brevity):
var queueClient = QueueClient.Create(queuename, ReceiveMode.PeekLock); if (queueClient.GetMessageSessions().Count() > 0) { var nextSession = queueClient.AcceptMessageSession(); var sessionId = nextSession.SessionId; BrokeredMessage message = null; message = nextSession.Receive(TimeSpan.FromSeconds(5)); if (message != null) { result = new ServiceBusBasicMessage(message); } nextSession.Close(); // do stuff here. } queueClient.Close();
ServiceBusBasicMessage have some of the properties of a brokeredmessage that I might need to use later.
So when I'm trying to complete the message I'm doing this:
var queueClient = QueueClient.Create(queuename); var session = queueClient.AcceptMessageSession(message.SessionId); session.Complete(message.LockToken); session.Close(); queueClient.Close();
Everytime I run this I got the following error:
The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.
I have the lock duration set at 5 minutes (so I could rule this out). But when I look at the message.LockedUntilUTC it seems like the value is more or less 30 seconds in the future. The session.LockedUntilUTC is set to five minutes in the future. I've tried to RenewLock on the message but it doesn't help.
Is there anything I'm missing at my code? If not, is there any way for the message to share the session lock tim? Or the kind of scenario I'm looking at is not possible?
Thanks in advance, Wagner.