Send message

Prev Next

Available in VPC

Send a message (data) to a topic. You can check the delivery result by clicking the Topic > [Data] tab menu in the Data Stream service in the NAVER Cloud Platform console.

Note

For more information on how to connect to an Apache Kafka cluster via a TCP endpoint to product and consume messages, see the Data Stream user guide.

Request

This section describes the request format. The method and URI are as follows:

Method URI
POST /api/produce

Request headers

For information about the headers common to all Data Stream APIs, see Data Stream request headers.

Caution

For security reasons, the access key and secret key of the main account on the NAVER Cloud Platform cannot be used for authentication. Therefore, you must create a sub account and use the access key and secret key of the sub account. For more information on how to create a sub account and check the access key and secret key, see the Sub Account User Guides.

Request body

You can include the following data in the body of your request:

Field Type Required Description
topic String Required Topic name
key String Required Message key
value String Required Message value (content)
partition Number Optional Topic partition index to send messages to
  • Send to random partition on no input.

Request example

The request example is as follows:

Unpartitioned

The following is a sample request when sending without specifying a partition.

curl --location --request POST 'https://api.datastream.naverncp.com/api/produce' \
--header 'x-ncp-apigw-timestamp: {Timestamp}' \
--header 'x-ncp-iam-access-key: {Access Key}' \
--header 'x-ncp-apigw-signature-v2: {API Gateway Signature}' \
--data '{  
            "topic": "{TopicName}",  
            "key": "test-key",  
            "value": "this is a test (body)"
}'

Partitioned

The following is a sample request when sending by specifying a partition.

curl --location --request POST 'https://api.datastream.naverncp.com/api/produce' \
--header 'x-ncp-apigw-timestamp: {Timestamp}' \
--header 'x-ncp-iam-access-key: {Access Key}' \
--header 'x-ncp-apigw-signature-v2: {API Gateway Signature}' \
--data '{  
            "topic": "{TopicName}",  
            "key": "test-key",  
            "value": "this is a test (body)",
            "partition": 0
}'
# Partition numbers start from 0

Response

This section describes the response format.

Response body

The response body includes the following data:

Field Type Required Description
status Number Required Response status codes
detail String Required Response status code message

Response status codes

The following describes the response status codes.

HTTP status code Code Message Description
200 - OK Request succeeded
400 - Bad Request Invalid request or body values
400 - Bad Request, Invalid headers Invalid header request
400 - Bad Request, Invalid topic partition Invalid partition request
401 - Unauthorized Authentication failed
403 - Forbidden Unauthorized
500 - Internal Server Error Unresolved error

Response example

The response example is as follows:

{
    "status": "200",
    "detail" : "OK"
}