Azure WorkerRole API Calls async/await
I have an Azure worker role that reads messages from a service bus queue using the `Client.OnMessage()` message pump directive.

Here is a sample code:

   
public override void Run(){         
     Client.OnMessage((receivedMessage) =>   {             
           var APIResponse = Call3rdPartyAPIUsingMessageData(receivedMessage);         
  }, options);    
}



The issue is that the 3rd party API call takes a long time. It seems silly to sit there and wait for the API call to complete synchronously.

What I would like is to take advantage of `async/await` to save the thread. 
Meaning, I want the worker role to "pause this message" and process the next message in the queue. When the 3rd Party API call completes, then jump back in and complete the operation.

Looking at other answers on stackoverflow, it seems that using `async/await` in the worker role is not a good idea.

What are my options?


  • Edited by sorcerdon2 Thursday, March 26, 2015 4:53 PM
March 26th, 2015 4:51pm

Hi,

You might want consider using the RoleEntryPoint Class. It provides methods to run code when a role instance is initialized, run, and stopped.

Suggest you to follow the below article which emphasizes about RoleEntryPoint Methods

https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.aspx

Hope this helps !

Regards,

Sowmya

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 11:47am

Hi,

You might want consider using the RoleEntryPoint Class. It provides methods to run code when a role instance is initialized, run, and stopped.

Suggest you to follow the below article which emphasizes about RoleEntryPoint Methods

https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.aspx

Hope this helps !

Regards,

Sowmya

March 30th, 2015 11:47am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics