Skip to content

Commit

Permalink
Restore the usage of AzureSpringBootRequestHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
milismsft committed Jul 18, 2019
1 parent 50b4415 commit d04bde1
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,33 @@
import com.microsoft.azure.functions.annotation.CosmosDBOutput;
import com.microsoft.azure.functions.annotation.EventHubTrigger;
import com.microsoft.azure.functions.annotation.FunctionName;
import org.json.JSONObject;

import java.util.UUID;
import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler;

/**
* Function for capturing a transaction into the CosmosDB database.
*
* TransactionEvent is a POJO representing the event data which is received as a JSON string and de-serialized into
* the object by the Azure Functions runtime.
* TransactionDocument is a POJO that represents the final document to be saved in the database collection
*/
public class AppendTransaction {
public class AppendTransaction extends AzureSpringBootRequestHandler<TransactionEvent, TransactionDocument> {
@FunctionName("Append-Transaction")
public void update(
@EventHubTrigger(name = "data", eventHubName = "%TRANSACTIONS_EVENT_HUB_NAME%",
connection = "TRANSACTIONS_EVENT_HUB_CONNECTION_STRING",
cardinality = Cardinality.ONE,
consumerGroup = "%TRANSACTIONS_EVENT_HUB_CONSUMER_GROUP_NAME%") String data,
consumerGroup = "%TRANSACTIONS_EVENT_HUB_CONSUMER_GROUP_NAME%") TransactionEvent data,
@CosmosDBOutput(name = "document", databaseName = "%TRANSACTIONS_COSMOSDB_DBNAME%",
collectionName = "%TRANSACTIONS_COSMOSDB_COLLECTION_NAME%",
connectionStringSetting = "TRANSACTIONS_COSMOSDB_CONNECTION_STRING",
createIfNotExists = true)
OutputBinding<String> document,
createIfNotExists = true) OutputBinding<TransactionDocument> document,
final ExecutionContext context) {

context.getLogger().info("Java Event Hub transaction trigger from "
+ System.getenv("APPEND_TRANSACTION_FUNCTION_APP_NAME")
+ "(" + System.getenv("APPEND_TRANSACTION_FUNCTION_APP_ID")
+ ") processed a request: " + data);
JSONObject eventHubMessage = new JSONObject(data);
eventHubMessage.put("id", UUID.randomUUID().toString());
context.getLogger().info("message: " + eventHubMessage.toString());
document.setValue(eventHubMessage.toString());
+ ") processed a request: " + data.getValue());
handleOutput(data, document, context);
}
}

0 comments on commit d04bde1

Please sign in to comment.