- Using Orchestration Service
var orchestrationTypes = new List<Type>();
orchestrationTypes.Add(typeof(<your orchestration>));
var activityTypes = new List<Type>();
activityTypes.Add(typeof(<your activity>));
var sqlConfig = new SqlServerConfiguration()
{
ConnectionString = <sql server ConnectionString>,
AutoCreate = true,
OrchestrationWorkerOptions = new maskx.OrchestrationService.Extensions.OrchestrationWorkerOptions()
{
GetBuildInOrchestrators = () => { return orchestrationTypes; },
GetBuildInTaskActivities = () => { return activityTypes; }
}
};
services.UsingOrchestration(sqlConfig);- Start your orchestration
var client =<IServiceProvider>.GetService<OrchestrationWorkerClient>();
client.JumpStartOrchestrationAsync(new Job
{
InstanceId = Guid.NewGuid().ToString("N"),
Orchestration = new OrchestrationSetting()
{
Creator = "DICreator",
Uri = typeof(<your orchestration>).FullName + "_"
},
Input = <your orchestration input>
})- Get Orchestration result
var client =<IServiceProvider>.GetService<OrchestrationWorkerClient>();
var result = client.WaitForOrchestrationAsync(instance, TimeSpan.FromSeconds(30)).Result;In ConfigureServices method:
- Add OrchestrationClient and OrchestrationService,
services.AddSingleton((sp) =>
{
return CreateOrchestrationClient();
});
services.AddSingleton((sp) =>
{
return CreateOrchestrationService();
});- Add your TaskOrchestration and TaskActivity
List<Type> orchestrationTypes = new List<Type>();
List<Type> activityTypes = new List<Type>();
orchestrationTypes.Add(typeof(AsyncRequestOrchestration));
activityTypes.Add(typeof(AsyncRequestActivity));
activityTypes.Add(typeof(HttpRequestActivity));
services.Configure<OrchestrationWorkerOptions>(options =>
{
options.GetBuildInOrchestrators = () => orchestrationTypes;
options.GetBuildInTaskActivities = () => activityTypes;
});- Add IOrchestrationCreatorFactory
- DefaultObjectCreator is DurableTask buildin Creator
- DICreator support Dependency Injection
services.AddSingleton<IOrchestrationCreatorFactory>((sp) =>
{
OrchestrationCreatorFactory orchestrationCreatorFactory = new OrchestrationCreatorFactory(sp);
orchestrationCreatorFactory.RegistCreator("DICreator", typeof(DICreator<TaskOrchestration>));
orchestrationCreatorFactory.RegistCreator("DefaultObjectCreator", typeof(DefaultObjectCreator<TaskOrchestration>));
return orchestrationCreatorFactory;
});- Add OrchestrationWorker
services.AddSingleton<OrchestrationWorker>();
services.AddSingleton<IHostedService>(p => p.GetService<OrchestrationWorker>());var orchestrationWorker = ServiceProvider.GetService<OrchestrationWorker>();
var instance = orchestrationWorker.JumpStartOrchestrationAsync(new Job()
{
InstanceId = Guid.NewGuid().ToString("N"),
Orchestration = new maskx.OrchestrationService.OrchestrationCreator.Orchestration()
{
Creator = "DICreator",
Uri = typeof(HttpOrchestration).FullName + "_"
},
Input = dataConverter.Serialize(request)
}).Result; services.AddSingleton<IJobProvider>(new JobProvider());- Add your CommunicationProcessor
services.AddSingleton<ICommunicationProcessor>(new MockCommunicationProcessor());- Configure CommunicationWorkerOptions
services.Configure<CommunicationWorkerOptions>((options) =>
{
options.HubName = communicationWorkerOptions.HubName;
options.MaxConcurrencyRequest = communicationWorkerOptions.MaxConcurrencyRequest;
options.SchemaName = communicationWorkerOptions.SchemaName;
});- Add CommunicationWorker
services.AddHostedService<CommunicationWorker>();In your TaskOrchestration, you should use AsyncRequestOrchestration send the request
var response = await context.CreateSubOrchestrationInstance<TaskResult>(
typeof(AsyncRequestOrchestration),
DataConverter.Deserialize<AsyncRequestInput>(input));Implement yourself ICommunicationProcessor to send the request to the target system
some system have concurrency request limitation, you can add FetchRule to control the concurrency request to the system