Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate from Azure webjob to Azure webapp?

I'm running an Azure webjob alongside an Azure webapp. The job runs periodically and the result of the job is needed in the webapp. How do I get the result there?

I tried with a WCF netNamedPipeBinding but since there are no startup tasks for Azure webapps I cannot add a net.pipe binding to the IIS website nor can I enable the net.pipe protocol.

I have it working now with a basicHttpBinding but this binding is exposed to the entire internet which I absolutely do not want. I simply want machine-local communication between a webjob and webapp running on the same machine.

CORRECTION: I thought I had it working on Azure but that is not the case. When running on Azure I get an error from the webjob: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:80 (using basicHttpBinding). Probably the webapp has an internal port number I don't know.

like image 892
Ronald Wildenberg Avatar asked Jun 29 '15 11:06

Ronald Wildenberg


2 Answers

You have a few options:

  1. Use the file system to pass messages
  2. Use Azure Storage Queues to pass messages between the two
  3. Use Azure Service Bus Queue to pass messages
  4. Use any shared storage (database, Azure Storage, etc) to pass messages

The benefit of all these approaches is that it makes your message passing async and thus more resilient to one of the two services (web app or web job) going down for some time.

like image 126
Zain Rizvi Avatar answered Oct 11 '22 07:10

Zain Rizvi


You can use the file-system to communicate between the WebJob and the Websites. It is shared between them and between all of your instances.

Simply write a file from the WebJob and use a file system watcher in your webapp to recognize when a file is created or changed.

Note you cannot communicate through localhost in Azure Websites (or WebJobs) and cannot listen on a port that is not 80/443.

like image 25
Amit Apple Avatar answered Oct 11 '22 09:10

Amit Apple