Class CommandWorker<T>
- Namespace
- Virtufin.Worker.DevKit
- Assembly
- Virtufin.Worker.DevKit.dll
JSON convenience overload of
CommandWorker<TInput, TOutput, TCommand>. Wires the
JsonCloudEventCodec automatically and adds the JSON-specific
Response(command, success, id, message) convenience that today's
workers expect.
public abstract class CommandWorker<T> : CommandWorker<JsonNode, JsonObject, T>, IWorker where T : struct, Enum
Type Parameters
TThe command enum (see CommandWorker<TInput, TOutput, TCommand>).
- Inheritance
-
CommandWorker<T>
- Implements
-
IWorker
- Derived
- Inherited Members
Constructors
CommandWorker(string)
A JSON command worker of type workerType, named by the naming library (see WorkerTypeNames).
protected CommandWorker(string workerType)
Parameters
workerTypestring
CommandWorker(Uri, string)
protected CommandWorker(Uri source, string responseEventType)
Parameters
Fields
DefaultApiPort
Default gRPC port of the API Gateway.
public const int DefaultApiPort = 5002
Field Value
FieldApiHost
JSON field name of the API host in the command JSON.
public const string FieldApiHost = "api_host"
Field Value
Properties
Gateway
The gateway call surface for this worker. Routes backend
service calls through either the managed gRPC proxy (when
loaded by DotNetDllEngine) or the host's C-ABI gateway
callback (when loaded by NativeDllEngine). Worker
handlers consume Virtufin.Worker.Host.IGatewayClient via this
property — they never construct an adapter directly.
protected virtual IGatewayClient Gateway { get; }
Property Value
- IGatewayClient
Remarks
Concrete subclasses must override:
- ApiCommandWorker<T> returns
ManagedGatewayAdapter(Api!.Gateway). - An AOT
CommandWorker<T>subclass returnsAotGatewayAdapter(AotNative<Self>.CurrentContext!).
The default here throws if a subclass neither overrides nor sets Gateway itself; workers that never call the gateway inherit this default and never trip the exception.
Methods
ErrorPayload(string)
JSON error payload: {"command":"error","success":false,"message":"..."}.
Mirrors the success-payload shape produced by Response(CloudEvent, string, bool, string?, string?).
protected override JsonObject? ErrorPayload(string message)
Parameters
messagestring
Returns
ExtractCommand(JsonNode)
Subclasses override to extract the command string from the typed
input payload. Default: not implemented. Override must read the
payload in a payload-format-specific way (JSON: node["command"],
Protobuf: dedicated field, etc.).
protected override string? ExtractCommand(JsonNode payload)
Parameters
payloadJsonNode
Returns
Response(CloudEvent, string, bool, string?, string?)
Convenience: build a JSON-shaped success/failure response CloudEvent
envelope with the canonical {command, success, id?, message?}
payload. Returns a JsonObject that the base class
encodes via the codec.
protected JsonObject Response(CloudEvent input, string command, bool success, string? id = null, string? message = null)
Parameters
inputCloudEventcommandstringsuccessboolidstringmessagestring