Table of Contents

Struct TopicId

Namespace
Microsoft.AutoGen.Contracts
Assembly
Microsoft.AutoGen.Contracts.dll

Represents a topic identifier that defines the scope of a broadcast message. The agent runtime implements a publish-subscribe model through its broadcast API, where messages must be published with a specific topic.

See the Python equivalent: CloudEvents Type Specification.

public struct TopicId
Inherited Members

Constructors

TopicId(string, string)

Initializes a new instance of the TopicId struct.

public TopicId(string type, string source = "default")

Parameters

type string

The type of the topic.

source string

The source of the event. Defaults to DefaultSource if not specified.

TopicId((string Type, string Source))

Initializes a new instance of the TopicId struct from a tuple.

public TopicId((string Type, string Source) kvPair)

Parameters

kvPair (string Type, string Key)

A tuple containing the topic type and source.

Fields

DefaultSource

The default source value used when no source is explicitly provided.

public const string DefaultSource = "default"

Field Value

string

Properties

Source

Gets the source that identifies the context in which an event happened. This adheres to the CloudEvents specification.

Learn more here: CloudEvents Source.

public readonly string Source { get; }

Property Value

string

Type

Gets the type of the event that this TopicId represents. This adheres to the CloudEvents specification.

Must match the pattern: ^[\w-.:=]+$.

Learn more here: CloudEvents Type.

public readonly string Type { get; }

Property Value

string

Methods

Equals(object?)

Determines whether the specified object is equal to the current TopicId.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if the specified object is equal to the current TopicId; otherwise, false.

FromStr(string)

Converts a string in the format "type/source" into a TopicId.

public static TopicId FromStr(string maybeTopicId)

Parameters

maybeTopicId string

The topic ID string.

Returns

TopicId

An instance of TopicId.

Exceptions

FormatException

Thrown when the string is not in the valid "type/source" format.

GetHashCode()

Returns a hash code for this TopicId.

public override int GetHashCode()

Returns

int

A hash code for the current instance.

IsWildcardMatch(TopicId)

Determines whether the given TopicId matches another topic.

public bool IsWildcardMatch(TopicId other)

Parameters

other TopicId

The topic ID to compare against.

Returns

bool

true if the topic types are equal; otherwise, false.

ToString()

Returns the string representation of the TopicId.

public override string ToString()

Returns

string

A string in the format "type/source".

Operators

explicit operator TopicId(string)

Explicitly converts a string to a TopicId.

public static explicit operator TopicId(string id)

Parameters

id string

The string representation of a topic ID.

Returns

TopicId

An instance of TopicId.