Create a deferred worker
The following sample deferred worker uses the xConnect Client API to create a known contact. The worker accepts a custom worker options dictionary (SampleDeferredWorkerOptionsDictionary) which defines:
-
An identifier and an identifier source to use for the contact
-
The fully qualified name of the worker
Create deferred worker options dictionary
Create deferred worker options dictionary
You can use the DistributedWorkerOptionsDictionary class to register a task for a custom deferred 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 create custom worker options dictionary for all deferred workers. To create a worker options dictionary:
-
Create a class named
SampleDeferredWorkerOptionsDictionarythat inheritsDeferredWorkerOptionsDictionaryas shown:
When creating a deferred 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."
Create deferred worker class
Create deferred worker class
To create a deferred worker:
-
Create a class named
SampleDeferredWorkerthat implementsIDeferredWorkeras shown:
When creating a deferred 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 Cortex Processing Engine. This is required to register changes in configuration.
Use custom deferred worker
Use custom deferred worker
To use the custom worker in a core role environment (such as Content Management):
-
Register a deferred task using the
SampleDeferredWorkerOptionsDictionaryclass as shown: