-
Notifications
You must be signed in to change notification settings - Fork 35
/
SendMessageToKafka.java
30 lines (27 loc) · 1.16 KB
/
SendMessageToKafka.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
package com.function;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.OutputBinding;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.dapr.annotation.DaprBindingOutput;
import com.microsoft.azure.functions.dapr.annotation.DaprServiceInvocationTrigger;
public class SendMessageToKafka {
/**
* This function gets invoked by dapr runtime:
* dapr invoke --app-id functionapp --method SendMessageToKafka --data '{"data":{"message": "hello!" }}'
* Once this function gets invoked, it will send a message to Kafka.
*/
@FunctionName("SendMessageToKafka")
public String run(
@DaprServiceInvocationTrigger(
methodName = "SendMessageToKafka")
String payload,
@DaprBindingOutput(
bindingName = "%KafkaBindingName%",
operation = "create")
OutputBinding<String> product,
final ExecutionContext context) {
context.getLogger().info("Java function processed a SendMessageToKafka request.");
product.setValue(payload);
return payload;
}
}