[docs]@dataclass(eq=True,frozen=True)classTopicId:""" TopicId defines the scope of a broadcast message. In essence, agent runtime implements a publish-subscribe model through its broadcast API: when publishing a message, the topic must be specified. See here for more information: :ref:`topic_and_subscription_topic` """type:str"""Type of the event that this topic_id contains. Adhere's to the cloud event spec. Must match the pattern: ^[\\w\\-\\.\\:\\=]+\\Z Learn more here: https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#type """source:str"""Identifies the context in which an event happened. Adhere's to the cloud event spec. Learn more here: https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#source-1 """def__post_init__(self)->None:ifis_valid_topic_type(self.type)isFalse:raiseValueError(f"Invalid topic type: {self.type}. Must match the pattern: ^[\\w\\-\\.\\:\\=]+\\Z")def__str__(self)->str:returnf"{self.type}/{self.source}"
[docs]@classmethoddeffrom_str(cls,topic_id:str)->Self:"""Convert a string of the format ``type/source`` into a TopicId"""items=topic_id.split("/",maxsplit=1)iflen(items)!=2:raiseValueError(f"Invalid topic id: {topic_id}")type,source=items[0],items[1]returncls(type,source)