Create a distributed worker
The following sample distributed worker uses the xConnect Client API to remove identifiers with a particular source from batches of contacts. The worker accepts a custom worker options dictionary (SampleDistributedWorkerOptionsDictionary) which defines:
-
The identifier source of the identifiers to be removed
-
The fully qualified name of the worker
Create distributed worker options dictionary
Create distributed worker options dictionary
You can use the DistributedWorkerOptionsDictionary class to register a task for a custom distributed worker. However, you must know the fully qualified name of the worker and correct name and format of each dictionary entry. To reduce the risk of error, it is recommended that you createa custom worker options dictionary for all distributed workers.
To create a custom worker options dictionary:
-
Create a class named
SampleDistributedWorkerOptionsDictionarythat inheritsDistributedWorkerOptionsDictionaryas shown:
When creating a distributed worker options dictionary:
-
You must include a constructor that accepts a
IDictionary<string, string>parameter. The constructor must be decorated with the[JsonConstructor]attribute. Without this constructor, the Processing Engine will throw the following error when it tries to execute the worker: "System.FormatException: Could not deserialize JSON text." -
It is recommended that you create helper methods that can:
-
Convert an
IReadOnlyDictionary<string, string>into an options dictionary (CreateDictionary()) -
Convert an options dictionary into an
IReadOnlyDictionary<string, string>(Parse())
-
Create distributed worker class
Create distributed worker class
To create a distributed worker:
-
Create a class named
SampleDistributedWorkerthat implementsIDistributedWorkeras shown:
When creating a distributed worker:
-
You must have constructor that accepts an
IReadOnlyDictionary<string, string>parameter. If you do not include this constructor, the Processing Engine will not start and you will get the following error: "System.InvalidOperationException: A suitable constructor for type could not be located."
Register worker in configuration
Register worker in configuration
To register the worker in the Cortex Processing Engine:
-
Create a file named
C:\<PathToxConnect>\App_data\jobs\continuous\ProcessingEngine\App_Data\Config\Global\Processing\sc.Processing.Documentation.Examples.xmland add the following configuration: -
Restart the Processing Engine. This is required to register changes in configuration.
Use custom distributed worker
Use custom distributed worker
To use the custom worker in a core role environment (such as Content Management):
-
Register a distributed task using the
SampleDistributedWorkerOptionsDictionaryclass as shown: