public static async Task <ActivityResponse> QueryOutputToEventGridActivity( [ActivityTrigger] DurableActivityContext context, Binder outputBinder, ILogger log) { ActivityResponse ret = new ActivityResponse() { FunctionName = "QueryOutputToEventGridActivity" }; #region Logging if (null != log) { log.LogDebug($"Output in {ret.FunctionName} "); } #endregion // Read the results QueryOutputRecord <object> results = context.GetInput <QueryOutputRecord <object> >(); if (null != results) { EventGridAttribute egAttribute = EventGridAttributeFromTarget(results.Target, results.QueryName, results.QueryUniqueIdentifier); if (null != egAttribute) { // split the target string into an event grid attribute Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent = new Microsoft.Azure.EventGrid.Models.EventGridEvent() { Subject = results.QueryUniqueIdentifier.ToString(), Data = results.Results }; IAsyncCollector <EventGridEvent> eventCollector = outputBinder.Bind <IAsyncCollector <EventGridEvent> >(egAttribute); if (null != eventCollector) { await eventCollector.AddAsync(eventGridEvent); await eventCollector.FlushAsync(); } } else { ret.Message = $"Unable to determine the event grid target from {results.Target}"; } } else { ret.Message = $"Unable to get query output record to send to event grid"; } return(ret); }
public static async Task <ActivityResponse> RunCustomEventGridTopicNotificationActivity( [ActivityTrigger] DurableActivityContext context, Binder outputBinder, ILogger log) { ActivityResponse response = new ActivityResponse() { FunctionName = "RunCustomEventGridTopicNotificationActivity" }; Command_Notification_Request notifyRequest = context.GetInput <Command_Notification_Request>(); if (null != notifyRequest) { EventGridAttribute egAttribute = EventGridAttributeFromNotifyRequest(notifyRequest.HookAddress, notifyRequest.CommandName); if (null != egAttribute) { // split the target string into an event grid attribute Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent = new Microsoft.Azure.EventGrid.Models.EventGridEvent() { Subject = $"/{EventStream.MakeEventStreamName(notifyRequest.ImpactedEntity.EntityType)}/{EventStream.MakeEventStreamName(notifyRequest.ImpactedEntity.InstanceUniqueIdentifier)}", Data = notifyRequest }; IAsyncCollector <EventGridEvent> eventCollector = outputBinder.Bind <IAsyncCollector <EventGridEvent> >(egAttribute); if (null != eventCollector) { await eventCollector.AddAsync(eventGridEvent); await eventCollector.FlushAsync(); } response.Message = $"Sent notification to {egAttribute.TopicEndpointUri} for {notifyRequest.ImpactedEntity.EntityType}:{notifyRequest.ImpactedEntity.InstanceUniqueIdentifier } "; } else { response.StepFailure = true; response.Message = "Unable to create an event grid attribute to send the notification to"; } } else { response.StepFailure = true; response.Message = "Unable to read command notification request from context"; } return(response); }
public static void Run([EventGridTrigger] Microsoft.Azure.EventGrid.Models.EventGridEvent eventGridEvent, TraceWriter log) { log.Info(eventGridEvent.Data.ToString()); var eventData = eventGridEvent.Data as CustomData; var customEvent = CustomEvent <CustomData> .CreateCustomEvent(eventData); }