-
Notifications
You must be signed in to change notification settings - Fork 78
/
ServiceBusTopicTriggerFunction.java
60 lines (52 loc) · 3.17 KB
/
ServiceBusTopicTriggerFunction.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
54
55
56
57
58
59
60
package com.functions;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
import java.util.*;
/**
* Azure Functions with Azure Service Bus Topic.
* https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=java
*/
public class ServiceBusTopicTriggerFunction {
@FunctionName("ServiceBusTopicTrigger")
public void serviceBusTopicTrigger(
@ServiceBusTopicTrigger(name = "message", topicName = "SBTopicNameSingle", subscriptionName = "SBTopicNameSingleSubName", connection = "AzureWebJobsServiceBus") String message,
@QueueOutput(name = "output", queueName = "test-servicebustopicbatch-java", connection = "AzureWebJobsStorage") OutputBinding<String> output,
final ExecutionContext context
) {
context.getLogger().info("Java Service Bus Topic trigger function processed a message: " + message);
output.setValue(message);
}
@FunctionName("ServiceBusTopicTriggerMetadata")
public void serviceBusTopicTriggerMetadata(
@ServiceBusTopicTrigger(name = "message", topicName = "SBTopicNameMetadata", subscriptionName = "SBTopicNameMetadataSubName", connection = "AzureWebJobsServiceBus") String message,
@BindingName("UserProperties") Map<String, Object> properties,
@BindingName("CorrelationId") String correlationId,
final ExecutionContext context
) {
context.getLogger().info("Java Service Bus Topic trigger function processed a message: " + message);
context.getLogger().info("Custom message properties = " + properties);
context.getLogger().info("CorrelationId = " + correlationId);
}
@FunctionName("ServiceBusTopicBatchTrigger")
public void serviceBusTopicBatchTrigger(
@ServiceBusTopicTrigger(name = "message", topicName = "SBTopicNameBatch", subscriptionName = "SBTopicNameBatchSubName", connection = "AzureWebJobsServiceBus", cardinality = Cardinality.MANY, dataType = "String") List<String> messages,
@QueueOutput(name = "output", queueName = "test-servicebustopicbatch-java", connection = "AzureWebJobsStorage") OutputBinding<String> output,
final ExecutionContext context
) {
context.getLogger().info("Java Service Bus Topic trigger function processed a message: " + messages.get(0));
output.setValue(messages.get(0));
}
/**
* This function will be invoked when a http request is received. The message contents are provided as output to this function.
*/
@FunctionName("ServiceBusTopicOutput")
public void serviceBusTopicOutput(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@ServiceBusTopicOutput(name = "message", topicName = "%SBTopicName%", subscriptionName = "%SBTopicSubName%", connection = "AzureWebJobsServiceBus") OutputBinding<String> output,
final ExecutionContext context
) {
String message = request.getBody().orElse("default message");
output.setValue(message);
context.getLogger().info("Java Service Bus Topic output function got a message: " + message);
}
}