From ef09bef162953f934c863e57c69d8c72324ccccf Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Thu, 3 Oct 2019 13:41:05 -0700 Subject: [PATCH] howtooutputbinding (#36) --- .../Readme.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 howto/send-events-with-output-bindings/Readme.md diff --git a/howto/send-events-with-output-bindings/Readme.md b/howto/send-events-with-output-bindings/Readme.md new file mode 100644 index 000000000..7933cff59 --- /dev/null +++ b/howto/send-events-with-output-bindings/Readme.md @@ -0,0 +1,44 @@ +# Send events to external systems using Output Bindings + +Using bindings, its possible to invoke external resources without tying in to special SDK or libraries. +For a compelete sample showing output bindings, visit this [link](). + +## 1. Create a binding + +An output binding represents a resource that Dapr will use invoke and send messages to. + +For the purpose of this guide, we'll use a Kafka binding. You can find a list of the different binding specs [here](../concepts/bindings//specs). + +Create the following YAML file, named binding.yaml, and save this to the /components sub-folder in your application directory. + +*Note: When running in Kubernetes, apply this file to your cluster using `kubectl apply -f binding.yaml`* + +``` +apiVersion: actions.io/v1alpha1 +kind: Component +metadata: + name: myEvent +spec: + type: bindings.kafka + metadata: + - name: brokers + value: localhost:9092 + - name: publishTopic + value: topic1 +``` + +Here, we create a new binding component with the name of `myEvent`.
+Inside the `metadata` section, we configure Kafka related properties such as the topic to publish the message to and the broker. + +## 2. Send an event + +All that's left now is to invoke the bindings endpoint on a running Dapr instance. + +We can do so using HTTP: + +``` +curl -X POST -H http://localhost:3500/v1.0/bindings/myEvent -d '{ data: { "message": "Hi!" } }' +``` + +As seen above, we invoked the `/binding` endpoint with the name of the binding to invoke, in our case its `myEvent`.
+The payload goes inside the `data` field.