-
Notifications
You must be signed in to change notification settings - Fork 1
Spring Cloud Stream Binder Dapr Design
The project is ultimately to implement a "Spring Cloud Stream Binder For Dapr", which is a library for users.
When the project relies on specific message middleware to send and receive messages, users can replace the message middleware with dapr by modifying the pom and configuration files to send and receive messages.
Send and receive messages based on dapr's api.
- Add or update dependency
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-stream-binder-dapr</artifactId>
</dependency>
- Update configuration
If the project has previously used message oriented middleware, you only need to remove the middleware configuration and keep the spring cloud stream configuration.
If the project has not used message oriented middleware before, you only need to add the configuration related to messaging in spring cloud stream.
spring:
cloud:
stream:
function:
definition: consume;supply
bindings:
consume-in-0:
destination: ${AZURE_DAPR_NAME}
supply-out-0:
destination: ${AZURE_DAPR_NAME} # same as the above destination
poller:
initial-delay: 0
fixed-delay: 1000
- Code
@Bean
public Supplier<Message<String>> supply() {
return () -> {
LOGGER.info("Sending message, sequence " + i);
return MessageBuilder.withPayload("Hello world, " + i++).build();
};
}
@Bean
public Consumer<Message<String>> consume() {
return message -> {
LOGGER.info("New message received: '{}'", message.getPayload());
};
}
- Github project including source code, readme doc and test
- Sample project
- Quick Start and Migrate doc
- Blogs (optional)
Stream Feature | Support | Currently Support |
---|---|---|
Consumer Groups | ||
Consumer Types | ||
Partitioning Support | ||
Error Handling | ☑️ | |
Event Routing | ☑️ | |
Health Indicator | ☑️ | |
Producing and Consuming Messages | ☑️ | ☑️ |
We rely on dapr-sdk-autogen but not dapr-sdk, because dapr-sdk will have features that our project doesn't need and may cause dependency conflicts.
- Add the required dependencies
- spring-cloud-stream
- dapr-sdk-autogen
- Provide a Binder implementation
- createProducerMessageHandler(provide a MessageHandler implementation)
- createConsumerEndpoint(provide a MessageProducer implementation)
- Create a Binder Configuration(initialize all bean)
- Define your binder in META-INF/spring.binders
- dapr=com.azure.spring.cloud.stream.binder.dapr.config.DaprBinderConfiguration
- Provide a ProvisioningProvider implementation
- DaprProducerDestination implements ProducerDestination
- DaprConsumerDestination implements ConsumerDestination