所以我现在在 Azure 门户中看到了这个 UI。您只需在域上添加事件订阅,其中一个选项是按主题归档,您可以在其中添加主题。
https://docs.microsoft.com/bs-latn-ba/azure/event-grid/how-to-event-domains?tabs=azurecli#create-topics-and-subscriptions
这里很清楚“在域中创建主题没有单独的步骤。”。
其次,我能够为 Cloud Events v1.0 设置 source = topic 并分离出主题。这是我的 CloudEvent 泛型类:
public class CloudEvent<T> where T : class
{
[JsonProperty("id")]
public string EventId
{
protected set { }
get => Guid.NewGuid().ToString();
}
[JsonProperty("specversion")]
public string CloudEventVersion
{
protected set { }
get => "1.0";
}
[JsonProperty("type")]
public string EventType { get; set; }
[JsonProperty("eventTypeVersion")]
public string EventTypeVersion
{
protected set { }
get => "1.0";
}
[JsonProperty("source")]
public string Source { get; set; }
[JsonProperty("subject")]
public string Subject { get; set; }
[JsonProperty("time")]
public string Time
{
protected set { }
get => DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
}
[JsonProperty("data")]
public T Data { get; set; }
}
我的主题(设置为云事件的源属性)是:
/resourceGroups/{rgname}/providers/Microsoft.EventGrid/domains/{domainname}/topics/{topic}
我认为这也将根据此模式正确设置主题。
https://docs.microsoft.com/en-us/azure/event-grid/cloudevents-schema