イベントサブスクリプションの宛先として「イベントグリッドトリガ」ベースのAzure関数を使用している場合、サブスクリプションの検証は自動的に処理されます。 2018-01-01 APIバージョンを開始すると、(イベントサブスクリプションの作成時に宛先エンドポイントとして)「HTTPトリガー」ベースの機能を使用している場合は、コード内でこの検証を処理する必要があります。これはhttps://docs.microsoft.com/en-us/azure/event-grid/overviewに記載されています。
ステップ1:Microsoft.Azure.EventGridへの依存関係を追加:あなたAzureの機能で「ファイルの表示」リンクをクリックして、これを行うには を(右ここ
は、C#でのいくつかのサンプルコードですAzure関数ポータルのほとんどのペイン)を開き、project.jsonというファイルを作成します。 project.jsonファイルに次の内容を追加して、それを保存します。
{
"frameworks": {
"net46": {
"dependencies": {
"Microsoft.Azure.EventGrid": "1.1.0-preview"
}
}
}
}
ステップ2:サブスクリプションの検証イベントを処理:
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Microsoft.Azure.EventGrid.Models;
class SubscriptionValidationEventData
{
public string ValidationCode { get; set; }
}
class SubscriptionValidationResponseData
{
public string ValidationResponse { get; set; }
}
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
string response = string.Empty;
const string SubscriptionValidationEvent = "Microsoft.EventGrid.SubscriptionValidationEvent";
string requestContent = await req.Content.ReadAsStringAsync();
EventGridEvent[] eventGridEvents = JsonConvert.DeserializeObject<EventGridEvent[]>(requestContent);
foreach (EventGridEvent eventGridEvent in eventGridEvents)
{
JObject dataObject = eventGridEvent.Data as JObject;
// Deserialize the event data into the appropriate type based on event type
if (string.Equals(eventGridEvent.EventType, SubscriptionValidationEvent, StringComparison.OrdinalIgnoreCase))
{
var eventData = dataObject.ToObject<SubscriptionValidationEventData>();
log.Info($"Got SubscriptionValidation event data, validation code {eventData.ValidationCode}, topic={eventGridEvent.Topic}");
// Do any additional validation (as required) and then return back the below response
var responseData = new SubscriptionValidationResponseData();
responseData.ValidationResponse = eventData.ValidationCode;
return req.CreateResponse(HttpStatusCode.OK, responseData);
}
}
return req.CreateResponse(HttpStatusCode.OK, response);
}
あなたはrequestb.inでこれをテストしていますか?それともカスタムエンドポイントですか? –
@PacodelaCruzカスタムエンドポイントです。私はテストするためにrequestb.inは必要ありません。 azure関数を作成し、サブスクリプションエンドポイントとして追加し、すべての着信要求を記録します。 – Mikhail
私はプロダクトチームから、requestb.inでの動作がホワイトリストに載っているとしか期待してはいけないと言われました。これはプレビューである可能性があります。彼らは現在のアプローチが面倒であり、改善に取り組んでいることを知っています。 –