Skip to content

Hosting activity

Gurmit Teotia edited this page Dec 10, 2019 · 6 revisions

You can host the activities in Guflow using Guflow.Worker.ActivityHost class. Following example shows how to host OrderActivity

//following code expect secret key and access code in application config file.
var domain = new Domain("domainName", RegionEndPoint.EUWEST1);
using(var host = domain.Host(new []{typeof(OrderActivity)})
{
   host.StartExecution();
   Console.WriteLine("Press a key to terminate the host");
}

In above example we're hosting one activity but you can host multiple activities. In above hosting approach Guflow.Worker.ActivityHost expect activities to have default constructor. However if your activity has parameterized constructor then you need to take control of creating the activity instances.

//following code expect secret key and access code in application config file.
var domain = new Domain("domainName", RegionEndPoint.EUWEST1);
using(var host = domain.Host(new []{typeof(OrderActivity)}, t=> serviceLocator.CreateInstance(t)))
{
   host.StartExecution();
   Console.WriteLine("Press a key to terminate the host");
}

Similar to workflow, hosting concept is very much specific to Guflow and not to Amazon SWF. In Guflow when you host the activity then host goes in execution loop and it executes following steps:

  • Poll for new activity task on Amazon SWF
  • Execute the returned activity task against correct activity and start heartbeat if enabled
  • Send the activity response back to Amazon SWF

In above example ActivityHost will poll for new activity task on "DefaultTaskList" which is provided on ActivityDescriptionAttribute, however you can specify the different task list to poll on by using other overloaded method:

host.StartExecution(new TaskQueue("DifferentQueue"))

Please look at Exception handling section on handling the exception

Clone this wiki locally