-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add sample code Java * Add sample for Rust
- Loading branch information
1 parent
fbd1c9d
commit 623bf7b
Showing
24 changed files
with
1,163 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"bindings" : [ { | ||
"type" : "blobTrigger", | ||
"direction" : "in", | ||
"name" : "triggerBlob", | ||
"path" : "test-triggerinput-httpworker/{name}", | ||
"dataType" : "binary", | ||
"connection" : "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"type" : "blob", | ||
"direction" : "out", | ||
"name" : "$return", | ||
"path" : "test-output-httpworker/{name}", | ||
"dataType" : "binary", | ||
"connection" : "AzureWebJobsStorage" | ||
} ] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
}, | ||
{ | ||
"name": "$return", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output-node", | ||
"connection": "AzureWebJobsStorage" | ||
} | ||
] | ||
} |
26 changes: 26 additions & 0 deletions
26
Java/HttpTriggerWithOutputs/HttpTriggerStringReturnValue/function.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
}, | ||
{ | ||
"name": "$return", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output-node", | ||
"connection": "AzureWebJobsStorage" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
}, | ||
{ | ||
"name": "$return", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output-node", | ||
"connection": "AzureWebJobsStorage" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "myQueueItem", | ||
"type": "queueTrigger", | ||
"direction": "in", | ||
"queueName": "test-input-node", | ||
"connection": "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"name": "$return", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output-node", | ||
"connection": "AzureWebJobsStorage" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "myQueueItem", | ||
"type": "queueTrigger", | ||
"direction": "in", | ||
"queueName": "test-inputmultiout-node", | ||
"connection": "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"name": "$return", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output-node", | ||
"connection": "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"name": "output1", | ||
"type": "queue", | ||
"direction": "out", | ||
"queueName": "test-output1-node", | ||
"connection": "AzureWebJobsStorage" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Azure Functions Http Worker - Java API Sample | ||
|
||
## Pre-reqs | ||
- Java 8 | ||
- Maven (for packaging) | ||
|
||
## Build + Run the Java API standalone | ||
- Use the following configuration in your `launch.json` to run the Java API: | ||
```json | ||
"configurations": [ | ||
{ | ||
"type": "java", | ||
"name": "Debug (Launch)", | ||
"request": "launch", | ||
"mainClass": "", | ||
"env": { | ||
"FUNCTIONS_HTTPWORKER_PORT": 5000 | ||
} | ||
}, | ||
``` | ||
- Hit the endpoints at `http://localhost:5000/SimpleHttpTrigger` | ||
|
||
## Run with Functions | ||
- Package the Java api into a jar file: | ||
```bash | ||
mvn package -f "java/com.java/pom.xml" | ||
``` | ||
- In a terminal, `cd` to the `functions` directory and run: | ||
```bash | ||
func start | ||
``` | ||
> All being well you should see the Spring ascii logo, where the functions runtime has started the proces. | ||
|
||
- Hit the endpoints at `http://localhost:7071/api/SimpleHttpTrigger` | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "anonymous", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"bindings": [{ | ||
"type": "httpTrigger", | ||
"authLevel": "anonymous", | ||
"direction": "in", | ||
"methods": ["GET", | ||
"POST"], | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
}] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.java</groupId> | ||
<artifactId>com.java</artifactId> | ||
<version>1.0</version> | ||
|
||
<name>com.java</name> | ||
<url></url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.9.RELEASE</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.java; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.java; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.java.models.*; | ||
|
||
@RestController | ||
public class JavaAPI { | ||
|
||
@PostMapping("/QueueTrigger") | ||
public InvokeResponse QueueTriggerHandler(@RequestBody InvokeRequest request){ | ||
System.out.println("Java queue trigger handler"); | ||
InvokeResponse resp = new InvokeResponse(); | ||
resp.Logs.add("Java: test log1"); | ||
resp.Logs.add("Java: test log2"); | ||
resp.ReturnValue = "HelloWorld"; | ||
return resp; | ||
} | ||
|
||
@PostMapping("/QueueTriggerWithOutputs") | ||
public InvokeResponse QueueTriggerWithOutputsHandler(@RequestBody InvokeRequest request){ | ||
System.out.println("Java queue trigger handler"); | ||
InvokeResponse resp = new InvokeResponse(); | ||
resp.Logs.add("Java: test log1"); | ||
resp.Logs.add("Java: test log2"); | ||
resp.Outputs.put("output1", "output from Java"); | ||
resp.ReturnValue = 100; | ||
return resp; | ||
} | ||
|
||
@PostMapping("/BlobTrigger") | ||
public InvokeResponse BlobTriggerHandler(@RequestBody InvokeRequest request){ | ||
InvokeResponse resp = new InvokeResponse(); | ||
resp.Logs.add("Java: test log1"); | ||
resp.Logs.add("Java: test log2"); | ||
resp.ReturnValue = request.Data; | ||
return resp; | ||
} | ||
|
||
@RequestMapping(value = {"/SimpleHttpTrigger", "/SimpleHttpTriggerWithReturn"}) | ||
public Map<String, String> SimpleHttpTrigger(){ | ||
System.out.println("Java: Simple Http Trigger"); | ||
|
||
Map<String, String> dynOutput = new HashMap<String, String>(); | ||
dynOutput.put("home", "123-456-789"); | ||
dynOutput.put("office", "987-654-321"); | ||
|
||
return dynOutput; | ||
} | ||
|
||
@PostMapping(value = {"/HttpTriggerWithOutputs", "/HttpTriggerStringReturnValue"}) | ||
public InvokeResponse HttpTriggerWithOutputs(){ | ||
System.out.println("Java: Http Trigger with Outputs"); | ||
InvokeResponse resp = new InvokeResponse(); | ||
resp.ReturnValue = "return val"; | ||
|
||
Map<String, String> dynOutput = new HashMap<String, String>(); | ||
dynOutput.put("home", "123-456-789"); | ||
dynOutput.put("office", "987-654-321"); | ||
|
||
resp.Outputs.put("output1", "Mark Taylor"); | ||
resp.Outputs.put("output2", dynOutput); | ||
|
||
Map<String, Object> headers = new HashMap<String, Object>(); | ||
headers.put("header1", "header1Val"); | ||
headers.put("header2", "header2Val"); | ||
|
||
Map<String, Object> httpRes = new HashMap<String,Object>(); | ||
httpRes.put("statusCode", "201"); | ||
httpRes.put("body", "my world"); | ||
httpRes.put("headers", headers); | ||
|
||
resp.Outputs.put("res", httpRes); | ||
return resp; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.java; | ||
|
||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ServletConfig { | ||
@Bean | ||
public EmbeddedServletContainerCustomizer containerCustomizer() { | ||
return (container -> { | ||
int portNumber = Integer.parseInt(System.getenv("FUNCTIONS_HTTPWORKER_PORT")); | ||
container.setPort(portNumber); | ||
}); | ||
} | ||
} |
Oops, something went wrong.