Table of Contents

Class CommandInvoker<TReq, TResp>

Namespace
Azure.Iot.Operations.Protocol.RPC
Assembly
Azure.Iot.Operations.Protocol.dll
public abstract class CommandInvoker<TReq, TResp> : IAsyncDisposable where TReq : class where TResp : class

Type Parameters

TReq
TResp
Inheritance
CommandInvoker<TReq, TResp>
Implements
Derived
Inherited Members

Constructors

CommandInvoker(ApplicationContext, IMqttPubSubClient, string, IPayloadSerializer)

public CommandInvoker(ApplicationContext applicationContext, IMqttPubSubClient mqttClient, string commandName, IPayloadSerializer serializer)

Parameters

applicationContext ApplicationContext
mqttClient IMqttPubSubClient
commandName string
serializer IPayloadSerializer

Properties

RequestTopicPattern

public string RequestTopicPattern { get; init; }

Property Value

string

ResponseTopicPattern

If provided, this topic pattern will be used for command response topic.

public string? ResponseTopicPattern { get; set; }

Property Value

string

Remarks

If not provided, and no value is provided for ResponseTopicPrefix or ResponseTopicSuffix, the default pattern used will be clients/{mqtt client id}/{request topic pattern}.

ResponseTopicPrefix

The prefix to use in the command response topic. This value is ignored if ResponseTopicPattern is set.

public string? ResponseTopicPrefix { get; set; }

Property Value

string

Remarks

If no prefix or suffix is specified, and no value is provided in ResponseTopicPattern, then this value will default to "clients/{invokerClientId}" for security purposes.

If a prefix and/or suffix are provided, then the response topic will use the format: {prefix}/{command request topic}/{suffix}.

ResponseTopicSuffix

The suffix to use in the command response topic. This value is ignored if ResponseTopicPattern is set.

public string? ResponseTopicSuffix { get; set; }

Property Value

string

Remarks

If no suffix is specified, then the command response topic won't include a suffix.

If a prefix and/or suffix are provided, then the response topic will use the format: {prefix}/{command request topic}/{suffix}.

TopicNamespace

public string? TopicNamespace { get; set; }

Property Value

string

TopicTokenMap

The topic token replacement map that this command invoker will use by default. Generally, this will include the token values for topic tokens such as "modelId" which should be the same for the duration of this command invoker's lifetime.

public Dictionary<string, string> TopicTokenMap { get; protected set; }

Property Value

Dictionary<string, string>

Remarks

Tokens replacement values can also be specified per-method invocation by specifying the additionalTopicToken map in InvokeCommandAsync(TReq, CommandRequestMetadata?, Dictionary<string, string>?, TimeSpan?, CancellationToken).

Methods

DisposeAsync()

Dispose this object and the underlying mqtt client.

public ValueTask DisposeAsync()

Returns

ValueTask

Remarks

To avoid disposing the underlying mqtt client, use DisposeAsync(bool).

DisposeAsync(bool)

Dispose this object and choose whether to dispose the underlying mqtt client as well.

public ValueTask DisposeAsync(bool disposing)

Parameters

disposing bool

If true, this call will dispose the underlying mqtt client. If false, this call will not dispose the underlying mqtt client.

Returns

ValueTask

DisposeAsyncCore(bool)

protected virtual ValueTask DisposeAsyncCore(bool disposing)

Parameters

disposing bool

Returns

ValueTask

InvokeCommandAsync(TReq, CommandRequestMetadata?, Dictionary<string, string>?, TimeSpan?, CancellationToken)

Invoke the specified command.

public Task<ExtendedResponse<TResp>> InvokeCommandAsync(TReq request, CommandRequestMetadata? metadata = null, Dictionary<string, string>? additionalTopicTokenMap = null, TimeSpan? commandTimeout = null, CancellationToken cancellationToken = default)

Parameters

request TReq

The payload of command request.

metadata CommandRequestMetadata

The metadata of the command request.

additionalTopicTokenMap Dictionary<string, string>

The topic token replacement map to use in addition to TopicTokenMap. If this map contains any keys that TopicTokenMap also has, then values specified in this map will take precedence.

commandTimeout TimeSpan?

How long the command will be available on the broker for an executor to receive.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<ExtendedResponse<TResp>>

The command response including the command response metadata