|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for |
| 4 | + * license information. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.microsoft.azure.functions.annotation; |
| 8 | + |
| 9 | +import java.lang.annotation.ElementType; |
| 10 | +import java.lang.annotation.Retention; |
| 11 | +import java.lang.annotation.RetentionPolicy; |
| 12 | +import java.lang.annotation.Target; |
| 13 | + |
| 14 | +/** |
| 15 | + * <p> |
| 16 | + * Place this on a parameter whose value would come from EventGrid, and causing the method to run when an event is |
| 17 | + * arrived. The parameter type can be one of the following:</p> |
| 18 | + * |
| 19 | + * <ul> |
| 20 | + * <li>Any native Java types such as String, byte[]</li> |
| 21 | + * <li>Nullable values using Optional<T></li> |
| 22 | + * <li>Any POJO type</li> |
| 23 | + * </ul> |
| 24 | + * |
| 25 | + * <p>The following example shows a Java function that prints out an event and then sends an event to a |
| 26 | + * custom eventGrid topic:</p> |
| 27 | + * |
| 28 | + * <pre>{@literal @}FunctionName("eventGridMonitor") |
| 29 | + * public void logEvent( |
| 30 | + * {@literal @}EventGridTrigger(name = "event") String content, |
| 31 | + * {@literal @}EventGridOutput(name = "outputEvent", topicEndpointUri = "MyEventGridTopicUriSetting", |
| 32 | + * topicKeySetting = "MyEventGridTopicKeySetting") |
| 33 | + * OutputBinding<String> outputEvent |
| 34 | + * final ExecutionContext context |
| 35 | + * ) { |
| 36 | + * context.getLogger().info(content); |
| 37 | + * final String eventGridOutputDocument = "{\"id\": \"100\", \"eventType\":\"recordInserted\", |
| 38 | + * \"subject\": \"myapp/test/java\", \"eventTime\":\"2017-08-10T21:03:07+00:00\", |
| 39 | + * \"data\": {\"tag1\": \"value1\",\"tag2\":\"value2\"}, \"dataVersion\": \"1.0\"}"; |
| 40 | + * outputEvent.setValue(eventGridOutputDocument); |
| 41 | + * }</pre> |
| 42 | + * |
| 43 | + * @since 1.3.1 |
| 44 | + */ |
| 45 | +@Retention(RetentionPolicy.RUNTIME) |
| 46 | +@Target({ElementType.PARAMETER, ElementType.METHOD}) |
| 47 | +public @interface EventGridOutput { |
| 48 | + /** |
| 49 | + * The variable name used in function.json. |
| 50 | + * @return The variable name used in function.json. |
| 51 | + */ |
| 52 | + String name(); |
| 53 | + |
| 54 | + /** |
| 55 | + * <p>Defines how Functions runtime should treat the parameter value. Possible values are:</p> |
| 56 | + * <ul> |
| 57 | + * <li>"" or string: treat it as a string whose value is serialized from the parameter</li> |
| 58 | + * <li>binary: treat it as a binary data whose value comes from for example OutputBinding<byte[]></li> |
| 59 | + * </ul> |
| 60 | + * @return The dataType which will be used by the Functions runtime. |
| 61 | + */ |
| 62 | + String dataType() default ""; |
| 63 | + |
| 64 | + /** |
| 65 | + * Gets or sets the Topic Key setting. You can find information on getting the Key for a topic |
| 66 | + * here: https://docs.microsoft.com/en-us/azure/event-grid/custom-event-quickstart#send-an-event-to-your-topic |
| 67 | + * @return The topic key setting of the eventGrid topic. |
| 68 | + */ |
| 69 | + String topicKeySetting(); |
| 70 | + |
| 71 | + /** |
| 72 | + * Gets or sets the topic events endpoint URI. Eg: https://topic1.westus2-1.eventgrid.azure.net/api/events |
| 73 | + * This is found in the Event Grid Topic's definition. You can find information on getting the Url for a topic |
| 74 | + * here: https://docs.microsoft.com/en-us/azure/event-grid/custom-event-quickstart#send-an-event-to-your-topic |
| 75 | + * @return The topic events endpoint URI of the eventGrid topic. |
| 76 | + */ |
| 77 | + String topicEndpointUri(); |
| 78 | +} |
0 commit comments