-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathTableFunction.java
52 lines (45 loc) · 2.13 KB
/
TableFunction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.functions;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.util.*;
/**
* Azure Functions with Azure Storage table.
* https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table-output?tabs=java
*/
public class TableFunction {
/**
* This function will be invoked when a new queue message is received.
*/
@FunctionName("TableInput")
public void tableInputJava(
@QueueTrigger(name = "message", queueName = "mytablequeue", connection = "AzureWebJobsStorage") String message,
@TableInput(name = "personEntity", tableName = "Person", rowKey = "{queueTrigger}", partitionKey = "firstPartition", connection = "AzureWebJobsStorage") String personEntity,
final ExecutionContext context
) {
context.getLogger().info("Java Queue trigger function processed a new message: " + message);
context.getLogger().info("Java Table Input function processed a Person entity:" + personEntity);
}
/**
* This function will be invoked when a new http request is received at the specified path.
*/
@FunctionName("TableOutput")
public void tableOutputJava(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@TableOutput(name = "myOutputTable", tableName = "Person", connection = "AzureWebJobsStorage") OutputBinding<Person> myOutputTable,
final ExecutionContext context
) {
String httpbody = request.getBody().orElse("default");
myOutputTable.setValue(new Person(httpbody + "Partition", httpbody + "Row", httpbody + "Name"));
context.getLogger().info("Java Table Output function write a new entity into table Person with name: " + httpbody + "Name");
}
public static class Person {
public String PartitionKey;
public String RowKey;
public String Name;
public Person(String p, String r, String n) {
this.PartitionKey = p;
this.RowKey = r;
this.Name = n;
}
}
}