Last active
August 4, 2019 04:14
-
-
Save tsaeki/41f9b915852529f4caae30298fe9c626 to your computer and use it in GitHub Desktop.
Sample Azure Functions with Timer trigger and SendGrid output binding for Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"bindings": [ | |
{ | |
"type": "timerTrigger", | |
"name": "keepAliveTrigger", | |
"direction": "in", | |
"schedule": "0 * * * * *" | |
}, | |
{ | |
"type": "sendGrid", | |
"name": "$return", | |
"direction": "out", | |
"apiKey": "SendGridAttribute.ApiKey" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.functions; | |
import java.time.*; | |
import com.microsoft.azure.functions.annotation.*; | |
import com.microsoft.azure.functions.*; | |
/** | |
* Azure Functions with HTTP Trigger. | |
*/ | |
public class Function { | |
@FunctionName("keepAlive") | |
public void keepAlive( | |
@TimerTrigger(name = "keepAliveTrigger", schedule = "0 * * * * *") String timerInfo, | |
final ExecutionContext context, | |
@SendGridOutput( | |
name = "email", dataType = "String", apiKey = "SendGridAttribute.ApiKey", to = "<to mail address>", from = "<from mail address>", | |
subject= "Sending with SendGrid", text = "Hello from Azure Functions" | |
) OutputBinding<String> email | |
) | |
{ | |
String name = "test"; | |
final String emailBody = "{\"personalizations\":" + | |
"[{\"to\":[{\"email\":\"<to mail address>\"}]," + | |
"\"subject\":\"Sending with SendGrid\"}]," + | |
"\"from\":{\"email\":\"<from mail address>\"}," + | |
"\"content\":[{\"type\":\"text/plain\",\"value\": \"Hello" + name + "\"}]}"; | |
email.setValue(emailBody); | |
context.getLogger().info("Java Timer trigger function executed at: " + LocalDateTime.now()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "2.0", | |
"extensionBundle": { | |
"id": "Microsoft.Azure.Functions.ExtensionBundle", | |
"version": "[1.*, 2.0.0)" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"IsEncrypted": false, | |
"Values": { | |
"AzureWebJobsStorage": "", | |
"FUNCTIONS_WORKER_RUNTIME": "java", | |
"SendGridAttribute.ApiKey": "<SendGrid ApiKey>" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
概要
事前に
プロジェクト作成
参考