azure - Service Bus MessageSession accepted but Receive returns null -
we use azure service bus queue, , receive messages using acceptmessagesession (code below).
accepting messagesession succeeds, when call receive on messagesession, null returned.
this doesn't happen time, rather after time since creation of queue. verified queue isn't empty when happens. when close messagesession see queue shorten (in correct number of messages!) hadn't received messages...
the code use:
public ienumerable<t> receivebatch<t>(timespan waittime) { messagesession sessionreceiver = null; ienumerable<t> retval; queueclient queueclient = getqueueclient<t>(); try { sessionreceiver = queueclient.acceptmessagesession(waittime); retval = receivesessionmessages<t>(sessionreceiver); } { if (sessionreceiver != null) sessionreceiver.close(); } return retval; } private ienumerable<t> receivesessionmessages<t>(messagesession receiver) { receiver.prefetchcount = 10; brokeredmessage message; var retval = new list<t>(); while ((message = receiver.receive()) != null) { var item = message.getbody<t>(); if (!equals(item, default(t))) retval.add(item); } return retval; }
update:
i have suspicion while messages of session have expired, session remains , accepted no messages received.
couple of items consider here, using prefetchcount
implicit batching, instead can use recievebatch
apis explicitly getting set of messages. see code sample below.
private ienumerable<t> receivesessionmessages<t>(messagesession receiver) { var retval = new list<t>(); var messages = receiver.receivebatch(10); foreach(brokeredmessage message in messages) { var item = message.getbody<t>(); if (!equals(item, default(t))) retval.add(item); } return retval; }
also in case messagesession
no messages can elaborate if may have expired? setting timetolive
value or messages deadlettered after maxdeliverycount
reached.
Comments
Post a Comment