The convinient RoleManager.WriteToLog static method provides way to write event logs for your clouded application. In the reference:
http://msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.writetolog.aspx
you will find that the allowed values for "eventLogName" are:
Critical, Error, Warning, Information, Verbose
It's a good idea to have them handy :)
Here is a complete How-to guide for writing and reading logs:
http://blog.benday.com/archive/2008/11/07/23201.aspx
I will just add that there is a great tool at CodePlex: http://azurestorageexplorer.codeplex.com/
Which is visual storage explorer. Something that I missed is that account configuration requires restart of the application (at least for me). If you are going to wander how to configure your cloud storage - just enter your cloud storage account name (without http://, and without blob.core.windows.net, or queue.core.windows.net, etc.) and your primary or secondary key - it works with both keys.
Sunday, August 30, 2009
Azure Worker Roles
Have you tried it yet ?
It is a background worker process, jsut like a windows service. So you can create your background working processes just like you used with Windows Service. It is very simple to implement:
public class WorkerRole : RoleEntryPoint
{
public override void Start()
{
// This is a sample worker implementation. Replace with your logic.
RoleManager.WriteToLog("Information", "Worker Process entry point called");
while (true)
{
Thread.Sleep(10000);
RoleManager.WriteToLog("Information", "Working");
}
}
public override RoleStatus GetHealthStatus()
{
// This is a sample worker implementation. Replace with your logic.
return RoleStatus.Healthy;
}
}
As simple as that. Of course you can have your System.Timers.Timer instance or more and schedule your processing logic to start up at regular periods.
It is a background worker process, jsut like a windows service. So you can create your background working processes just like you used with Windows Service. It is very simple to implement:
public class WorkerRole : RoleEntryPoint
{
public override void Start()
{
// This is a sample worker implementation. Replace with your logic.
RoleManager.WriteToLog("Information", "Worker Process entry point called");
while (true)
{
Thread.Sleep(10000);
RoleManager.WriteToLog("Information", "Working");
}
}
public override RoleStatus GetHealthStatus()
{
// This is a sample worker implementation. Replace with your logic.
return RoleStatus.Healthy;
}
}
As simple as that. Of course you can have your System.Timers.Timer instance or more and schedule your processing logic to start up at regular periods.
Labels:
Windows Azure,
worker role
Azure WebRole and Custom Error Handlers
A useful article on how to use custom handlers in the cloud:
http://www.shanmcarthur.net/cloud-services/azure-tips/custom-error-handlers
The main idea is that Azure is runnin on IIS7, so you have the power to plug-in into the integrated pipline mode.
In short:
<>
< errormode="Custom">
< statuscode="404">
< statuscode="404" responsemode="ExecuteURL" path="/page-not-found.aspx">
< /httpErrors >
< /system.webServer >
Put the configuration in system.webServer, insted of in system.web.
I would also add a handler for 400 status code. This is if you are making some custom http handlers.
http://www.shanmcarthur.net/cloud-services/azure-tips/custom-error-handlers
The main idea is that Azure is runnin on IIS7, so you have the power to plug-in into the integrated pipline mode.
In short:
<>
< errormode="Custom">
< statuscode="404">
< statuscode="404" responsemode="ExecuteURL" path="/page-not-found.aspx">
< /httpErrors >
< /system.webServer >
Put the configuration in system.webServer, insted of in system.web.
I would also add a handler for 400 status code. This is if you are making some custom http handlers.
Labels:
custom error handlers,
web role,
Windows Azure
How to use SQL Azure
Well,
If you want to play with SQL Azure it is little tricky. You cannot use SQL Server management Studio. However you can connect using ADO.NET. One option is to develop small app that does basic things like listing tables, enables editing tables etc, which actually is not that hard - to cover basic functionality.
Until then, the smoothest way I found is usign the SQLCmd tool.
Better described here: http://english.zachskylesowens.net/2009/08/18/connecting-to-sql-azure/
However this is the "quick-start":
sqlcmd -S MY_SERVER_NAME.ctp.database.windows.net -U MY_USERNAME@MY_SERVER_NAME -d DATABASE_NAME
The key here is that you must use MY_USERNAME@MY_SERVER_NAME !
For example, if your server name is h38ssfjeiwh201, your username is admin and connecting to sample_db your connection would be.
sqlcmd -S h38ssfjeiwh201.ctp.database.windows.net -U admin@h38ssfjeiwh201 -d sample_db
Also good point is that you must explicitly specify DataBase name to use, since AzureSQL CTP still does not support USE DataBaseName command.
Good luck and happy times with Sql Azure!
If you want to play with SQL Azure it is little tricky. You cannot use SQL Server management Studio. However you can connect using ADO.NET. One option is to develop small app that does basic things like listing tables, enables editing tables etc, which actually is not that hard - to cover basic functionality.
Until then, the smoothest way I found is usign the SQLCmd tool.
Better described here: http://english.zachskylesowens.net/2009/08/18/connecting-to-sql-azure/
However this is the "quick-start":
sqlcmd -S MY_SERVER_NAME.ctp.database.windows.net -U MY_USERNAME@MY_SERVER_NAME -d DATABASE_NAME
The key here is that you must use MY_USERNAME@MY_SERVER_NAME !
For example, if your server name is h38ssfjeiwh201, your username is admin and connecting to sample_db your connection would be.
sqlcmd -S h38ssfjeiwh201.ctp.database.windows.net -U admin@h38ssfjeiwh201 -d sample_db
Also good point is that you must explicitly specify DataBase name to use, since AzureSQL CTP still does not support USE DataBaseName command.
Good luck and happy times with Sql Azure!
Labels:
SqlAzure,
Windows Azure
Azure Worker Role config settings app.config
Recently playing with Azure July CTP I stumbled upon an issue which appeared to be known.
The thing that might drive you crazy is that the Publishing wizard does not apply settings from App.Config file. So basically your deployed worker process will have no idea about configuration settings.
It seemed to be a known issue and there are some discussions over here:
solution: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/cc11be6e-097a-499c-96c7-5089d01e2e08
other thread: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/604384f0-9d20-4be6-a02c-24ba1ff1bf82
The solution is trivial:
You have to add an environment variable to your user account:
Key: AddAppConfigToBuildOutputs
Value: true
And you need to restart Visual Studio for the change to take place.
The thing that might drive you crazy is that the Publishing wizard does not apply settings from App.Config file. So basically your deployed worker process will have no idea about configuration settings.
It seemed to be a known issue and there are some discussions over here:
solution: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/cc11be6e-097a-499c-96c7-5089d01e2e08
other thread: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/604384f0-9d20-4be6-a02c-24ba1ff1bf82
The solution is trivial:
You have to add an environment variable to your user account:
Key: AddAppConfigToBuildOutputs
Value: true
And you need to restart Visual Studio for the change to take place.
Labels:
Windows Azure,
worker role
Subscribe to:
Posts (Atom)