forked from Azure-Samples/azure-functions-samples-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KafkaTriggerFunction.java
53 lines (46 loc) · 2.2 KB
/
KafkaTriggerFunction.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
52
53
package com.functions;
import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.util.Optional;
public class KafkaTriggerFunction {
@FunctionName("HttpTriggerAndKafkaOutput")
public HttpResponseMessage HttpTriggerAndKafkaOutput(
@HttpTrigger(name = "req", methods = {HttpMethod.GET}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@KafkaOutput(
name = "httpTriggerAndKafkaOutput",
topic = "ci",
brokerList = "%BrokerList%",
username = "%ConfluentCloudUsername%",
password = "%ConfluentCloudPassword%",
authenticationMode = BrokerAuthenticationMode.PLAIN,
sslCaLocation = "confluent_cloud_cacert.pem",
protocol = BrokerProtocol.SASLSSL
) OutputBinding<String> output,
final ExecutionContext context) {
String message = request.getQueryParameters().get("message");
message = request.getBody().orElse(message);
context.getLogger().info("Java Http trigger received Message:" + message + " messages for Kafka Output");
output.setValue(message);
return request.createResponseBuilder(HttpStatus.OK).body(message).build();
}
@FunctionName("KafkaTriggerAndKafkaOutput")
public void KafkaTriggerAndKafkaOutput(
@KafkaTrigger(
name = "kafkaTriggerAndKafkaOutput",
topic = "ci",
brokerList = "%BrokerList%",
consumerGroup = "$Default",
username = "%ConfluentCloudUsername%",
password = "%ConfluentCloudPassword%",
authenticationMode = BrokerAuthenticationMode.PLAIN,
protocol = BrokerProtocol.SASLSSL,
sslCaLocation = "confluent_cloud_cacert.pem",
dataType = "string"
) String message,
@QueueOutput(name = "output", queueName = "test-kafka-output-cardinality-one-java", connection = "AzureWebJobsStorage") OutputBinding<String> output,
final ExecutionContext context) {
context.getLogger().info("Java Kafka Output function processed a message: " + message);
output.setValue(message);
}
}