Azure samples version and code adjustments

This commit is contained in:
Christian Tzolov
2023-07-20 10:52:16 +02:00
parent 2e5b38ccfd
commit 787d0f8c50
13 changed files with 80 additions and 63 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.7</version>
<version>3.1.1</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
@@ -16,8 +16,8 @@
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<spring-cloud-function-dependencies.version>4.0.4</spring-cloud-function-dependencies.version>
<azure.functions.java.core.version>3.0.0</azure.functions.java.core.version>
<spring-cloud-function-dependencies.version>4.0.5-SNAPSHOT</spring-cloud-function-dependencies.version>
<spring-boot-thin-layout.version>1.0.28.RELEASE</spring-boot-thin-layout.version>
<start-class>example.KafkaTriggerDemoApplication</start-class>
@@ -33,28 +33,14 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-context</artifactId>
<version>${spring-cloud-function-dependencies.version}</version>
</dependency>
<dependency>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-azure</artifactId>
<version>${spring-cloud-function-dependencies.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-dependencies</artifactId>
<version>${spring-cloud-function-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>${azure.functions.java.core.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
@@ -104,10 +90,17 @@
</executions>
</plugin>
<!-- <plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> -->
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${spring-boot-thin-layout.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@@ -18,7 +18,6 @@ package example;
import java.util.Map;
import java.util.function.Function;
import com.microsoft.azure.functions.ExecutionContext;
import example.entity.KafkaEntity;
import org.springframework.boot.SpringApplication;

View File

@@ -16,6 +16,8 @@
package example;
import java.util.function.Function;
import com.microsoft.azure.functions.BrokerAuthenticationMode;
import com.microsoft.azure.functions.BrokerProtocol;
import com.microsoft.azure.functions.ExecutionContext;
@@ -24,35 +26,39 @@ import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.KafkaOutput;
import com.microsoft.azure.functions.annotation.KafkaTrigger;
import org.springframework.cloud.function.adapter.azure.FunctionInvoker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
public class UppercaseHandler extends FunctionInvoker<Message<String>, String> {
@Component
public class UppercaseHandler {
@Autowired
private Function<Message<String>, String> uppercase;
@FunctionName("KafkaTrigger")
public void execute(
@KafkaTrigger(
name = "KafkaTrigger",
topic = "%TriggerKafkaTopic%",
brokerList = "%BrokerList%",
consumerGroup = "$Default",
username = "%ConfluentCloudUsername%",
password = "%ConfluentCloudPassword%",
authenticationMode = BrokerAuthenticationMode.PLAIN,
name = "KafkaTrigger",
topic = "%TriggerKafkaTopic%",
brokerList = "%BrokerList%",
consumerGroup = "$Default",
username = "%ConfluentCloudUsername%",
password = "%ConfluentCloudPassword%",
authenticationMode = BrokerAuthenticationMode.PLAIN,
protocol = BrokerProtocol.PLAINTEXT,
// protocol = BrokerProtocol.SASLSSL,
// sslCaLocation = "confluent_cloud_cacert.pem", // Enable this line for windows.
dataType = "string") String kafkaEventData,
@KafkaOutput(
name = "kafkaOutput",
topic = "output",
topic = "output",
brokerList="%BrokerList%",
username = "%ConfluentCloudUsername%",
username = "%ConfluentCloudUsername%",
password = "%ConfluentCloudPassword%",
authenticationMode = BrokerAuthenticationMode.PLAIN,
// sslCaLocation = "confluent_cloud_cacert.pem", // Enable this line for windows.
// sslCaLocation = "confluent_cloud_cacert.pem", // Enable this line for windows.
protocol = BrokerProtocol.PLAINTEXT
// protocol = BrokerProtocol.SASLSSL
) OutputBinding<String> output,
@@ -62,7 +68,7 @@ public class UppercaseHandler extends FunctionInvoker<Message<String>, String> {
Message<String> message = MessageBuilder.withPayload(kafkaEventData).build();
String response = handleRequest(message, context);
String response = uppercase.apply(message);
output.setValue(response);
}