mirror of https://github.com/dapr/docs.git
				
				
				
			Add pub/sub content-type info (#1158)
* add pub/sub content-type info * datacontenttype clarification * Update pubsub_api.md * add custom cloudevent info * reorder * Update howto-publish-subscribe.md * Update howto-publish-subscribe.md Co-authored-by: Mark Fussell <mfussell@microsoft.com>
This commit is contained in:
		
							parent
							
								
									08d86488bf
								
							
						
					
					
						commit
						df05ea3596
					
				|  | @ -14,6 +14,12 @@ Using Pub/Sub, you can enable scenarios where event consumers are decoupled from | |||
| Dapr provides an extensible Pub/Sub system with At-Least-Once guarantees, allowing developers to publish and subscribe to topics. | ||||
| Dapr provides components for pub/sub, that enable operators to use their preferred infrastructure, for example Redis Streams, Kafka, etc. | ||||
| 
 | ||||
| ## Content Types | ||||
| 
 | ||||
| When publishing a message, it's important to specify the content type of the data being sent. | ||||
| Unless specified, Dapr will assume `text/plain`. When using Dapr's HTTP API, the content type can be set in a `Content-Type` header. | ||||
| gRPC clients and SDKs have a dedicated content type parameter. | ||||
| 
 | ||||
| ## Step 1: Setup the Pub/Sub component | ||||
| The following example creates applications to publish and subscribe to a topic called `deathStarStatus`. | ||||
| 
 | ||||
|  | @ -379,6 +385,14 @@ app.listen(process.env.PORT || port, () => console.log(`Listening on port ${port | |||
| ``` | ||||
| {{% /codetab %}} | ||||
| {{< /tabs >}} | ||||
| 
 | ||||
| ## Sending a custom CloudEvent | ||||
| 
 | ||||
| Dapr automatically takes the data sent on the publish request and wraps it in a CloudEvent 1.0 envelope. | ||||
| If you want to use your own custom CloudEvent, make sure to specify the content type as `application/cloudevents+json`. | ||||
| 
 | ||||
| See info about content types [here](#Content-Types). | ||||
| 
 | ||||
| ## Next steps | ||||
| 
 | ||||
| - Try the [Pub/Sub quickstart sample](https://github.com/dapr/quickstarts/tree/master/pub-sub) | ||||
|  |  | |||
|  | @ -45,6 +45,14 @@ curl -X POST http://localhost:3500/v1.0/publish/pubsubName/deathStarStatus \ | |||
|      }' | ||||
| ``` | ||||
| 
 | ||||
| ### Headers | ||||
| 
 | ||||
| The `Content-Type` header tells Dapr which content type your data adheres to when constructing a CloudEvent envelope. | ||||
| The value of the `Content-Type` header populates the `datacontenttype` field in the CloudEvent. | ||||
| Unless specified, Dapr assumes `text/plain`. If your content type is JSON, use a `Content-Type` header with the value of `application/json`. | ||||
| 
 | ||||
| If you want to send your own custom CloundEvent, use the `application/cloudevents+json` value for the `Content-Type` header. | ||||
| 
 | ||||
| #### Metadata | ||||
| 
 | ||||
| Metadata can be sent via query parameters in the request's URL. It must be prefixed with `metadata.` as shown below. | ||||
|  | @ -143,7 +151,7 @@ other | warning is logged and message to be retried | |||
| 
 | ||||
| ## Message envelope | ||||
| 
 | ||||
| Dapr Pub/Sub adheres to version 1.0 of Cloud Events. | ||||
| Dapr Pub/Sub adheres to version 1.0 of CloudEvents. | ||||
| 
 | ||||
| ## Related links | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue