Skip to content

Commit 8e6fe13

Browse files
adam6878kgal-akl
authored andcommitted
Added binary cloudevent examples and explanation (#4942)
* Added bianry cloudevent exmaples and explanation Signed-off-by: adam shamis <adamshamis.dev@gmail.com> * tabpane line was missing Signed-off-by: adam shamis <adamshamis.dev@gmail.com> * topic was misproununced Signed-off-by: adam shamis <adamshamis.dev@gmail.com> --------- Signed-off-by: adam shamis <adamshamis.dev@gmail.com> Signed-off-by: Kobbi Gal <kobbi.g@akeyless.io>
1 parent 3f8bf91 commit 8e6fe13

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-cloudevents.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,48 @@ Invoke-RestMethod -Method Post -ContentType 'application/cloudevents+json' -Body
239239

240240
{{< /tabpane >}}
241241

242+
### Publish binary CloudEvents
243+
244+
In binary mode, the transport payload only contains the event body, while
245+
CloudEvent attributes are supplied via transport metadata that begins with the
246+
`ce_` prefix (HTTP headers, Kafka headers, NATS headers, and so on). This is
247+
useful when you already produce binary mode events or you want to send arbitrary
248+
binary data without wrapping it in an additional JSON envelope.
249+
250+
To publish a binary CloudEvent to Dapr (via HTTP/gRPC publish APIs or directly
251+
into a broker that Dapr reads from):
252+
253+
1. Set the transport’s native content-type metadata (for example the HTTP
254+
`Content-Type` header or a Kafka `content-type` message header) to the MIME
255+
type that represents binary data, which is `application/octet-stream`.
256+
257+
2. Add the required CloudEvent attributes (`ce_specversion`, `ce_type`,
258+
`ce_source`, `ce_id`) as transport metadata. Optional attributes such as
259+
`ce_subject`, `ce_time`, or `ce_traceparent` are also honored.
260+
261+
3. Send the payload bytes in the message body.
262+
263+
{{< tabpane text=true >}}
264+
265+
{{% tab "HTTP API (Bash)" %}}
266+
267+
Publish a Binary CloudEvent to orders topic:
268+
269+
```bash
270+
curl -X POST http://localhost:3500/v1.0/publish/order-pub-sub/orders \
271+
-H "Content-Type: application/octet-stream" \
272+
-H "ce_specversion: 1.0" \
273+
-H "ce_type: com.example.order.created" \
274+
-H "ce_source: urn:example:/checkout" \
275+
-H "ce_id: 2a8bbf52-1222-4c2c-85f0-8a8875c7bc10" \
276+
-H "ce_subject: orders/100" \
277+
--data-binary $'\x01\x02\x03\x04'
278+
```
279+
280+
{{% /tab %}}
281+
282+
{{< /tabpane >}}
283+
242284
## Event deduplication
243285

244286
When using cloud events created by Dapr, the envelope contains an `id` field which can be used by the app to perform message deduplication. Dapr does not handle deduplication automatically. Dapr supports using message brokers that natively enable message deduplication.

daprdocs/content/en/reference/api/pubsub_api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ HTTP Status | Description
300300
404 | error is logged and all messages are dropped
301301
other | warning is logged and all messages to be retried
302302

303+
#### CloudEvents binary mode
304+
305+
Supports publishing CloudEvents that use the binary mode defined by
306+
the CloudEvents HTTP binding. In this mode, the HTTP body only contains the
307+
payload bytes, and CloudEvent attributes are passed as headers with the `ce_`
308+
prefix. Provide the required headers (`ce_specversion`, `ce_type`, `ce_source`,
309+
`ce_id`) along with any optional ones (for example `ce_subject` or `ce_time`).
310+
Dapr copies the HTTP `Content-Type` header into the CloudEvent's
311+
`datacontenttype` attribute and forwards the resulting event to subscribers.
312+
313+
Example sending four raw bytes:
314+
315+
```bash
316+
curl -X POST http://localhost:3500/v1.0/publish/pubsubName/deathStarStatus \
317+
-H "Content-Type: application/octet-stream" \
318+
-H "ce_specversion: 1.0" \
319+
-H "ce_type: com.example.deathstar.status.changed" \
320+
-H "ce_source: urn:example:/deathstar" \
321+
-H "ce_id: 3a58b9b8-24d2-4f62-84f4-6177c2fe0633" \
322+
--data-binary $'\x01\x02\x03\x04'
323+
```
324+
303325
## Message envelope
304326

305327
Dapr pub/sub adheres to [version 1.0 of CloudEvents](https://github.com/cloudevents/spec/blob/v1.0/spec.md).

0 commit comments

Comments
 (0)