This repository contains a minimal end-to-end example of using Dapr's Pub/Sub building block over gRPC in Java, with raw payloads (i.e., not wrapped as CloudEvents).
publisher
: Publishes raw messages using Dapr's Java SDK over gRPCsubscriber
: gRPC server that subscribes to the topic and receives raw payloads
- Java 17+
- Maven
- Dapr CLI
- Docker (for Redis)
Create a components/redis-pubsub.yaml
file:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: redis-pubsub
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: "localhost:6379"
- name: rawPayload
value: "true"
From each subdirectory:
mvn clean package
dapr run --app-id subscriber --app-port 50051 --app-protocol grpc --resources-path ./components -- java -jar subscriber/target/subscriber-1.0-SNAPSHOT.jar
dapr run --app-id publisher --resources-path ./components -- java -jar publisher/target/publisher-1.0-SNAPSHOT.jar
Subscriber will log:
📥 Received raw message: {"message":"Hello from gRPC Publisher!"}