Azure Event Grid 이벤트에 대한 이벤트 처리기로서의 Service Bus 큐 및 토픽

이벤트 처리기는 Event Grid를 통해 이벤트 원본에서 이벤트를 수신하고 해당 이벤트를 처리합니다. Azure Service Bus를 비롯해 Azure 서비스의 몇 가지 인스턴스를 사용하여 이벤트를 처리할 수 있습니다. 이 문서에서는 Event Grid의 이벤트에 대한 처리기로 Service Bus 큐 또는 토픽을 사용하는 방법을 보여줍니다.

Service Bus 큐

엔터프라이즈 애플리케이션의 버퍼링 또는 명령 및 제어 시나리오에서 사용하기 위해 Event Grid의 이벤트를 Service Bus 큐에 직접 라우팅할 수 있습니다.

Azure Portal 사용

Azure Portal에서 이벤트 구독을 만드는 동안 Service Bus 큐를 엔드포인트 유형으로 선택한 다음, 엔드포인트 선택을 클릭하여 Service Bus 큐를 선택합니다.

Screenshot showing the configuration of a Service Bus queue handler.

참고 항목

세션 지원 큐는 Azure Event Grid 이벤트에 대한 이벤트 처리기로 지원되지 않습니다.

Azure CLI 사용

servicebusqueue로 설정된 --endpoint-type/subscriptions/{AZURE SUBSCRIPTION}/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<NAMESPACE NAME>/queues/<QUEUE NAME>으로 설정된 --endpoint와 함께 az eventgrid event-subscription create 명령을 사용합니다. 예를 들면 다음과 같습니다.

az eventgrid event-subscription create \
    --name <my-event-subscription> \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
    --endpoint-type servicebusqueue \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1

사용자 지정 토픽에 az eventgrid topic event-subscription 명령, 시스템 토픽에 az eventgrid system-topic event-subscription 명령, 파트너 토픽에 az eventgrid partner topic event-subscription create 명령을 사용할 수도 있습니다.

Azure PowerShell 사용

servicebusqueue으로 설정된 -EndpointType/subscriptions/{AZURE SUBSCRIPTION}/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<NAMESPACE NAME>/queues/<QUEUE NAME>으로 설정된 -Endpoint와 함께 New-AzEventGridSubscription 명령을 사용합니다. 예를 들면 다음과 같습니다.

New-AzEventGridSubscription -ResourceGroup MyResourceGroup `
            -TopicName Topic1 `
            -EndpointType servicebusqueue `
            -Endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/queues/queue1 `
            -EventSubscriptionName EventSubscription1

시스템 토픽에 New-AzEventGridSystemTopicEventSubscription 명령과 파트너 토픽에 New-AzEventGridPartnerTopicEventSubscription 명령을 사용할 수도 있습니다.

Service Bus 토픽

Event Grid의 이벤트를 Service Bus 토픽으로 직접 라우팅하여 명령 및 제어 메시징 시나리오에서 사용할 수 있습니다.

Azure Portal 사용

Azure Portal에서 이벤트 구독을 만들 때 Service Bus 토픽을 엔드포인트 유형으로 선택한 다음, 선택 및 엔드포인트를 클릭하여 Service Bus 토픽을 선택합니다.

Screenshot showing the configuration of a Service Bus topic handler.

Azure CLI 사용

servicebustopic로 설정된 --endpoint-type/subscriptions/{AZURE SUBSCRIPTION}/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<NAMESPACE NAME>/topics/<TOPIC NAME>으로 설정된 --endpoint와 함께 az eventgrid event-subscription create 명령을 사용합니다. 예를 들면 다음과 같습니다.

az eventgrid event-subscription create \
    --name <my-event-subscription> \
    --source-resource-id /subscriptions/{SubID}/resourceGroups/{RG}/providers/Microsoft.EventGrid/topics/topic1 \
    --endpoint-type servicebustopic \
    --endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/topics/topic1

사용자 지정 토픽에 az eventgrid topic event-subscription 명령, 시스템 토픽에 az eventgrid system-topic event-subscription 명령, 파트너 토픽에 az eventgrid partner topic event-subscription create 명령을 사용할 수도 있습니다.

Azure PowerShell 사용

servicebustopic으로 설정된 -EndpointType/subscriptions/{AZURE SUBSCRIPTION}/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<NAMESPACE NAME>/topics/<TOPIC NAME>으로 설정된 -Endpoint와 함께 New-AzEventGridSubscription 명령을 사용합니다. 예를 들면 다음과 같습니다.

New-AzEventGridSubscription -ResourceGroup MyResourceGroup `
            -TopicName Topic1 `
            -EndpointType servicebustopic `
            -Endpoint /subscriptions/{SubID}/resourceGroups/TestRG/providers/Microsoft.ServiceBus/namespaces/ns1/topics/topic1 `
            -EventSubscriptionName EventSubscription1

시스템 토픽에 New-AzEventGridSystemTopicEventSubscription 명령과 파트너 토픽에 New-AzEventGridPartnerTopicEventSubscription 명령을 사용할 수도 있습니다.

메시지 헤더

다음은 메시지 헤더에서 수신되는 속성입니다.

Property name 설명
aeg-subscription-name 이벤트 구독의 이름입니다.
aeg-delivery-count 이벤트를 시도한 횟수입니다.
aeg-event-type

이벤트의 유형입니다.

다음 값 중 하나일 수 있습니다.

  • SubscriptionValidation
  • 알림
  • SubscriptionDeletion
aeg-metadata-version

이벤트의 메타데이터 버전입니다.

Event Grid 이벤트 스키마의 경우 이 속성은 메타데이터 버전을 나타내고 클라우드 이벤트 스키마의 경우 사양 버전을 나타냅니다.

aeg-data-version

이벤트의 데이터 버전입니다.

Event Grid 이벤트 스키마의 경우 이 속성은 데이터 버전을 나타내고 클라우드 이벤트 스키마에 대해서는 적용되지 않습니다.

aeg-output-event-id Event Grid 이벤트의 ID입니다.

조정된 메시지로 Service Bus 큐 또는 토픽으로 이벤트를 보낼 때 조정된 메시지의 messageid는 내부 시스템 ID입니다.

이벤트를 다시 전달하는 동안 메시지의 내부 시스템 ID가 유지되므로 Service Bus 엔터티에서 중복 검색을 설정하여 중복 전달 문제를 방지할 수 있습니다. Service Bus 엔터티에서 중복 검색 기간을 이벤트의 TTL(Time-to-Live) 또는 최대 다시 시도 기간 중 더 긴 기간으로 설정하는 것이 좋습니다.

배달 속성

이벤트 구독을 사용하면 배달된 이벤트에 포함 되는 HTTP 헤더를 설정할 수 있습니다. 이 기능을 사용하면 대상에 필요한 사용자 지정 헤더를 설정할 수 있습니다. Azure Service Bus 큐 및 토픽에 배달되는 이벤트에서 사용자 지정 헤더를 설정할 수 있습니다.

Azure Service Bus에서는 단일 메시지를 보낼 때 다음 메시지 속성을 사용하도록 지원합니다.

헤더 이름 헤더 형식
MessageId 동적
PartitionKey 정적 또는 동적
SessionId 정적 또는 동적
CorrelationId 정적 또는 동적
Label 정적 또는 동적
ReplyTo 정적 또는 동적
ReplyToSessionId 정적 또는 동적
To 정적 또는 동적
ViaPartitionKey 정적 또는 동적

참고 항목

  • MessageId의 기본값은 Event Grid 이벤트의 내부 ID입니다. 이를 재정의할 수 있습니다. 예: data.field.
  • SessionId 또는 MessageId만 설정할 수 있습니다.

자세한 내용은 사용자 지정 배달 속성을 참조하세요.

REST 예제(PUT의 경우)

Service Bus 큐

{
    "properties": 
    {
        "destination": 
        {
			"endpointType": "ServiceBusQueue",
            "properties": 
            {
				"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/queues/<SERVICE BUS QUEUE NAME>"
			}
		},
		"eventDeliverySchema": "EventGridSchema"
	}
}

Service Bus 쿼리 - 관리 ID로 전달

{
	"properties": {
        "deliveryWithResourceIdentity": 
        {
            "identity": 
            {
				"type": "SystemAssigned"
			},
            "destination": 
            {
				"endpointType": "ServiceBusQueue",
                "properties": 
                {
					"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/queues/<SERVICE BUS QUEUE NAME>"
				}
			}
		},
		"eventDeliverySchema": "EventGridSchema"
	}
}

Service Bus 토픽

{
    "properties": 
    {
        "destination": 
        {
			"endpointType": "ServiceBusTopic",
            "properties": 
            {
				"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/topics/<SERVICE BUS TOPIC NAME>"
			}
		},
		"eventDeliverySchema": "EventGridSchema"
	}
}

Service Bus 토픽 - 관리 ID로 전달

{
    "properties": 
    {
        "deliveryWithResourceIdentity": 
        {
            "identity": 
            {
				"type": "SystemAssigned"
			},
            "destination": 
            {
				"endpointType": "ServiceBusTopic",
                "properties": 
                {
					"resourceId": "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.ServiceBus/namespaces/<SERVICE BUS NAMESPACE NAME>/topics/<SERVICE BUS TOPIC NAME>"
				}
			}
		},
		"eventDeliverySchema": "EventGridSchema"
	}
}

참고 항목

Geo-DR을 사용하도록 설정된 Service Bus 네임스페이스에 대해 장애 조치(failover)가 발생하면 보조 네임스페이스는 Event Grid에 이벤트를 내보내지 않습니다. 보조 네임스페이스에 대한 Event Grid 구독을 수동으로 추가해야 합니다.

다음 단계

지원되는 이벤트 처리기 목록은 이벤트 처리기 문서를 참조하세요.