How-To: Trigger your application with input bindings
Using bindings, your code can be triggered with incoming events from different resources which can be anything: a queue, messaging pipeline, cloud-service, filesystem etc.
This is ideal for event-driven processing, data pipelines or just generally reacting to events and doing further processing.
Dapr bindings allow you to:
- Receive events without including specific SDKs or libraries
- Focus on business logic and not the event resource implementation
For more info on bindings, read this overview.
For a quickstart sample showing bindings, visit this .
For the purpose of this HowTo, we’ll use a Kafka binding. You can find a list of the different binding specs here.
Create the following YAML file, named binding.yaml, and save this to a sub-folder in your application directory. (Use the --components-path
flag with dapr run
to point to your custom components dir)
Note: When running in Kubernetes, apply this file to your cluster using kubectl apply -f binding.yaml
Here, you create a new binding component with the name of .
Inside the metadata
section, configure the Kafka related properties such as the topics to listen on, the brokers and more.
The following example shows how you would listen for the event in Node.js, but this is applicable to any programming language
In order to tell Dapr that you successfully processed an event in your application, return a 200 OK
response from your HTTP handler.
In order to tell Dapr that the event wasn’t processed correctly in your application and schedule it for redelivery, return any response different from 200 OK
. For example, a 500 Error
.
Event delivery guarantees are controlled by the binding implementation. Depending on the binding implementation, the event delivery can be exactly once or at least once.