c# - Azure ServiceBus OnMessage Blocking Call or Not? -
we utilizing azure servicebus queues process high volumes of client requests. however, onmessage
call seems blocking call, blocking on call incredibly inconsistent if indeed blocking call.
what attempting accomplish watch queue on permanent basis web service application (to allow metrics mined running application)
i creating subscription below:
protected virtual void subscribe(string queuename, func<queuerequest, bool> callback) { var client = getclient(queuename, pollingtimeout); var transformcallback = new action<brokeredmessage>((message) => { try { var request = message.toqueuerequest(); if (callback(request)) { message.complete(); } else { message.abandon(); } } catch (exception ex) { //todo: log error message.abandon(); } }); var options = new onmessageoptions { maxconcurrentcalls = _config.getint("maxthreadsperqueue"), autocomplete = false }; options.exceptionreceived += onmessageerror; client.onmessage(transformcallback, options); }
if have subscription called once, application stops watching queue , stops processing messages. however, if place while loop around subscribe call. great hesitation wrote below snippet resubscribe if onmessage
completed.
protected void monitorqueue() { isrunning = true; while (isrunning) { try { log.info("monitoringthread: onmessage beginning logging {0}", queuename); queueclient.subscribe(queuename, processor); log.info("monitoringthread: onmessage ended logging {0}", queuename); } catch (exception ex) { isrunning = false; log.error("monitoringthread: error in subscription {0}: ", ex, queuename); } if (sleepbeforereinit > 0 && isrunning) { thread.sleep(sleepbeforereinit); } } }
this fixed problem of messages expiring dead letter due not being picked up, caused other problems.
with onmessage being billable operation concerned when see log file telling me queue beginning , ending less second apart , size of log file increases very rapidly.
i have messagingfactory
set have operationtimeout
of 1 day, yet not seem impact frequency of subscriptions open / close status expect.
i have seen plenty of samples doing worker role, not accomplish trying do. wiring global.asax.cs of our web application. advice appreciated!
onmessage , onmessageasync not blocking calls. these need instantiated single time , continue subscribing queue until application terminated.
see related post further details: azure service bus, determine if onmessage stops processing
Comments
Post a Comment