-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
original version of spring-cloud-stream-dapr
- Loading branch information
Showing
54 changed files
with
1,403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-dapr-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<parent> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-build</artifactId> | ||
<version>3.1.3</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<dapr-java-sdk.version>1.6.0</dapr-java-sdk.version> | ||
</properties> | ||
<modules> | ||
<module>spring-cloud-stream-dapr</module> | ||
</modules> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.dapr</groupId> | ||
<artifactId>dapr-sdk</artifactId> | ||
<version>${dapr-java-sdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dapr</groupId> | ||
<artifactId>dapr-sdk-springboot</artifactId> | ||
<version>${dapr-java-sdk.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
<plugins> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-dapr-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<parent> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-dapr-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<properties> | ||
<spring-cloud-stream.version>3.2.4</spring-cloud-stream.version> | ||
<grpc-netty-shaded.version>1.42.2</grpc-netty-shaded.version> | ||
<grpc-server-spring-boot-starter.version>2.13.1.RELEASE</grpc-server-spring-boot-starter.version> | ||
</properties> | ||
<modules> | ||
<module>spring-cloud-starter-stream-dapr-grpc</module> | ||
<module>spring-cloud-stream-binder-dapr-grpc</module> | ||
<module>spring-cloud-stream-binder-dapr-common</module> | ||
<module>samples</module> | ||
</modules> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-stream</artifactId> | ||
<version>${spring-cloud-stream.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.grpc</groupId> | ||
<artifactId>grpc-netty-shaded</artifactId> | ||
<version>${grpc-netty-shaded.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.devh</groupId> | ||
<artifactId>grpc-server-spring-boot-starter</artifactId> | ||
<version>${grpc-server-spring-boot-starter.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-binder-dapr-grpc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
<plugins> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# How to run demo | ||
|
||
## preparation | ||
|
||
Before running this demo, please ensure that you have the following software installed: | ||
|
||
- jdk 8 | ||
- maven 3.8.* | ||
- docker / docker-compose | ||
- dapr cli | ||
|
||
### dapr install | ||
|
||
```bash | ||
dapr init | ||
``` | ||
|
||
## Start kafka | ||
|
||
In this demo, we will use kafka as component for pubsub. | ||
|
||
start a single kafka cluster by docker-compose | ||
|
||
```bash | ||
$ mkdir kafka | ||
$ cd kafka | ||
$ git clone https://github.com/conduktor/kafka-stack-docker-compose.git | ||
$ cd kafka-stack-docker-compose | ||
$ docker-compose -f zk-single-kafka-single.yml up | ||
...... | ||
kafka1 | [2022-08-05 05:53:59,001] INFO KafkaConfig values: | ||
kafka1 | advertised.listeners = INTERNAL://kafka1:19092,EXTERNAL://127.0.0.1:9092,DOCKER://host.docker.internal:29092 | ||
...... | ||
``` | ||
|
||
Check it by: | ||
|
||
```bash | ||
# check if kafka is running with docker | ||
$ docker ps | ||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ||
340a4e85beca confluentinc/cp-kafka:7.2.0 "/etc/confluent/dock…" 5 minutes ago Up 5 minutes 0.0.0.0:9092->9092/tcp, 0.0.0.0:9999->9999/tcp, 0.0.0.0:29092->29092/tcp kafka1 | ||
48e7c08f2ff6 confluentinc/cp-zookeeper:7.2.0 "/etc/confluent/dock…" 5 minutes ago Up 5 minutes 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp zoo1 | ||
|
||
# verify kafka 9092 port | ||
$ nc -zv 127.0.0.1 9092 | ||
``` | ||
|
||
## Start dapr sidecar | ||
|
||
```bash | ||
# start dapr runtime for grpc | ||
cd spring-cloud-stream-dapr/samples/kafka | ||
dapr run --app-port 3500 --app-id app1 --app-protocol grpc --dapr-http-port 3501 --dapr-grpc-port 50001 --components-path=./components | ||
``` | ||
|
||
Check the log to see if dapr runtime start successfully. | ||
|
||
|
||
## start sample app kafka | ||
|
||
Find class `SampleApplication` in package `io.dapr.spring.cloud.stream.sample.kafka` and run it with your IDE. Then you will see logs like this: | ||
|
||
```bash | ||
...... | ||
Started SampleApplication in 1.63 seconds (JVM running for 1.874) | ||
|
||
...... | ||
Sending message, sequence 29 | ||
succeed to send event GenericMessage [payload=byte[13], headers={contentType=application/json, id=308b580d-d684-cdcc-1281-3399708a3acd, timestamp=1662516457376}]to kafka-pubsub/topic1 | ||
|
||
Message received : GenericMessage [payload=event body 29, headers={contentType=application/json, id=4dde7c71-65ca-10d0-d26d-69cbbc45abdb, timestamp=1662516457381}] | ||
|
||
Sending message, sequence 30 | ||
succeed to send event GenericMessage [payload=byte[13], headers={contentType=application/json, id=a9305d7a-86af-4ceb-b363-a56924670d65, timestamp=1662516458382}]to kafka-pubsub/topic1 | ||
|
||
Message received : GenericMessage [payload=event body 30, headers={contentType=application/json, id=1b351355-fdaa-373d-f184-4305c972f5c2, timestamp=1662516458389}] | ||
|
||
Sending message, sequence 31 | ||
succeed to send event GenericMessage [payload=byte[13], headers={contentType=application/json, id=c2b0cb09-ddea-8c2a-bb9c-c3d0987c0a23, timestamp=1662516459389}]to kafka-pubsub/topic1 | ||
|
||
Message received : GenericMessage [payload=event body 31, headers={contentType=application/json, id=420cf68c-6218-01bb-3b1c-c5c1433c5b05, timestamp=1662516459394}] | ||
...... | ||
``` |
30 changes: 30 additions & 0 deletions
30
spring-cloud-stream-dapr/samples/kafka/components/kafka_pubsub.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# Copyright 2021 The Dapr Authors | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
apiVersion: dapr.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: kafka-pubsub | ||
spec: | ||
type: pubsub.kafka | ||
initTimeout: 1m | ||
version: v1 | ||
metadata: | ||
# Kafka broker connection setting | ||
- name: brokers | ||
value: localhost:9092 | ||
# consumer configuration: consumer group | ||
- name: consumerGroup | ||
value: group1 | ||
- name: authType # Required. | ||
value: "none" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-dapr-samples-kafka</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.6.8</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-starter-stream-dapr</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
53 changes: 53 additions & 0 deletions
53
...s/kafka/src/main/java/io/dapr/spring/cloud/stream/sample/grpckafka/SampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2022 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.dapr.spring.cloud.stream.sample.kafka; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.integration.support.MessageBuilder; | ||
import org.springframework.messaging.Message; | ||
|
||
@SpringBootApplication | ||
public class SampleApplication { | ||
private static Logger logger = LoggerFactory.getLogger(SampleApplication.class); | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SampleApplication.class, args); | ||
} | ||
|
||
private int i = 0; | ||
|
||
@Bean | ||
public Supplier<Message<String>> supply() { | ||
return () -> { | ||
logger.info("Sending message, sequence " + i++); | ||
return MessageBuilder.withPayload("event body").build(); | ||
}; | ||
} | ||
|
||
@Bean | ||
public Consumer<Message<String>> consume() { | ||
return message -> { | ||
logger.info("Message received : {}", message); | ||
}; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
spring-cloud-stream-dapr/samples/kafka/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
grpc: | ||
server: | ||
port: 3500 | ||
|
||
spring: | ||
cloud: | ||
stream: | ||
function: | ||
definition: supply;consume | ||
bindings: | ||
supply-out-0: | ||
destination: topic1 | ||
consume-in-0: | ||
destination: topic1 | ||
dapr: | ||
bindings: | ||
supply-out-0: | ||
producer: | ||
pubsubName: kafka-pubsub | ||
consume-in-0: | ||
consumer: | ||
pubsubName: kafka-pubsub |
22 changes: 22 additions & 0 deletions
22
spring-cloud-stream-dapr/samples/kafka/target/classes/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
grpc: | ||
server: | ||
port: 3500 | ||
|
||
spring: | ||
cloud: | ||
stream: | ||
function: | ||
definition: supply;consume | ||
bindings: | ||
supply-out-0: | ||
destination: topic1 | ||
consume-in-0: | ||
destination: topic1 | ||
dapr: | ||
bindings: | ||
supply-out-0: | ||
producer: | ||
pubsubName: kafka-pubsub | ||
consume-in-0: | ||
consumer: | ||
pubsubName: kafka-pubsub |
Binary file added
BIN
+1.4 KB
...kafka/target/classes/io/dapr/spring/cloud/stream/sample/grpckafka/SampleApplication.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-dapr-samples-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<description>Spring Cloud Stream Dapr samples</description> | ||
|
||
<modules> | ||
<module>kafka</module> | ||
</modules> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
spring-cloud-stream-dapr/spring-cloud-starter-stream-dapr/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-dapr-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>spring-cloud-starter-stream-dapr</artifactId> | ||
<description>Spring Cloud Starter Stream Dapr</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-binder-dapr-grpc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
spring-cloud-stream-dapr/spring-cloud-stream-binder-dapr-common/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>io.dapr.spring</groupId> | ||
<artifactId>spring-cloud-stream-dapr-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>spring-cloud-stream-binder-dapr-common</artifactId> | ||
<description>Dapr Implementation for Spring Cloud Stream Binder</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-stream</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.