Skip to main content

Receive message

If the subscription type is Pull

If the subscription type is created as Pull in the Pub/Sub, the user can receive a message through the subscription and then confirm the response. For detailed instructions on creating a subscription, please refer to the Create subscription.

info

To request message reception via API, you must obtain an access key ID and a secure access key from the KakaoCloud Console > User Profile (Top right) > Access Key tab.

Key Concepts
Main ConceptsDescription
Subscription typePull: User requests message transmission
Response waite timeTime to wait for message confirmation response
- Time range: Set within 10-600 seconds (10 minutes)
Acknowledge responseIf message confirmation processing (ack) is not performed within the response waiting time, the message is resent

Create subscription

Create a subscription by selecting Pull as the subscription type in the Pub/Sub. For detailed instructions on creating a subscription, please refer to the Create subscription.

Receive message

If the subscription type is Pull, you can receive messages via the console or API.

💡 The API reception test is a test for Default topics. For reception tests for User-created topics, please refer to the Pub/Sub API document.

Pull

Get the messages published to the topic.

Request Syntax
Message Request Request Syntax
curl -k --location --request POST 'https://{endpoint-url}/pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/pull' \
--header "Credential-ID: ****" \
--header "Credential-Secret: ****" \
--header 'Content-Type: application/json' \
--data-raw '{
"maxMessages": 1
}'
Method
MethodRequest URL
POST /pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/pull
PathTypeRequiredDescription
project_idStringRequired   KakaoCloud project ID
- URI displayed in the console address bar of the project (value of project_id)
subscription-nameStringRequired   Subscription name
Request Header
RequestTypeRequiredDescription
Credential-IDStringRequired   Access key ID
Credential-SecretStringRequired   Security access key
Request Elements
RequestTypeDescription
maxMessagesIntegerMaximum number of message requests
1 to 4,096
Response Syntax
Response Syntax
{
"receivedMessages": [
{
"ackId": "Ifaswn660rXu8FZdE2ki7upOjG4pI3Q3eaqNHJxIOXZ4Abj5VpCQRXm/EPoxDHTgImaXz8HK7P5l1rmhLoSJaf0Q330DO10BivvG+yt4sEGMGLc5wB4VKACuzGDTFOAyhFAkualNoKqZLyzQYAJuILZeZfO7BUBmmMkS3O+pZlMvxmthpyDrNnyUmLBb2uXlzig5kBWh0ZFWegioX7nLs/uODqMhlj2U2qEX6E33q0R9qEuJjv4HWEnVRjrTUdrRV6fiahbf7gnH68jN9f0+MisPBqPLzpQBj+eyqt2BZAq9J2cn70I5lzErIpxMBPXwfmM4sF7MhtyvaNvAbq9Sm02IVOIwxHDsoON/yjggIVeY5g+6XvKQgq5/jg==",
"message": {
"data": "eyJldmVudF92ZXJzaW9uIjoiMS4wLjAiLCJldmVudF9pZCI6InRyYWlsXzBfNjAzNDUyNjY2XzE2Njg0MTQzNTAzMzQiLCJldmVudF9uYW1lIjoiS2V5cGFpciBjcmVhdGUiLCJldmVudF9zb3VyY2UiOiJWaXJ0dWFsIG1hY2hpbmUiLCJldmVudF90aW1lIjoiMjAyMi0xMS0xNFQwODoyNTo1MC4zMzRaIiwia2ljX3JlZ2lvbiI6Ii0iLCJkb21haW5faWQiOiI5ODJmYzM5MjY5OWQ0Mzg1YjBiMWE5ZDEwYjlmMjM5MyIsImRvbWFpbl9uYW1lIjoia2FrYW9lbnRlcnByaXNlIiwicHJvamVjdF9pZCI6IjM1MzA5NGUxMjJkNjQ5M2Q5ODk5ZjBmMjUyM2Q0Y2MxIiwicHJvamVjdF9uYW1lIjoiYmlnZGF0YSIsInJlc291cmNlX25hbWUiOiJwcHBwcGViIiwicmVzb3VyY2VfaWQiOiItIiwicmVzb3VyY2VfdHlwZSI6IktleXBhaXIiLCJ1c2VyX2lkIjoiY2Q3MGU1M2JkNGYxNDFkM2FhYjZmNjUyOGNjNGM0N2MiLCJ1c2VyX25hbWUiOiJwZWIubGVlQGtha2FvZW50ZXJwcmlzZS5jb20iLCJ1c2VyX2FnZW50IjoiLSIsInNvdXJjZV9pcF9hZGRyZXNzIjoiMTAuMTg3LjcwLjEzMyIsIm90aGVyX2FkZGl0aW9uYWxfaW5mbyI6Int9In0=",
"messageId": "1430458965141036376811744864924447649781668345309",
"publishTime": "2022-11-13T13:15:09Z"
},
"deliveryAttempt": 1
}
]
}
}
Response Elements
ResponseTypeDescription
ackIdStringackIds value used for confirmation after message request
messageObjectMessage details
   dataStringEvent log, Base64 encoding processing
   messageIdStringMessage unique ID
   publishTimeStringMessage publishing time
deliveryAttemptIntegerNumber of message transmission attempts
Status Code
HTTP StatusDescription
200Success
400Request information error
401, 403Authentication failure, unauthorized
404Subscription not found
Acknowledge

If the message was received normally, you can acknowledge it.

Request Syntax
Request Syntax
curl -k --location --request POST 'https://{endpoint-url}/pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/acknowledge' \
--header "Credential-ID: ****" \
--header "Credential-Secret: ****" \
--header 'Content-Type: application/json' \
--data-raw '{
"ackIds": [
"Ifaswn660rXu8FZdE2ki7upOjG4pI3Q3eaqNHJxIOXZ4Abj5VpCQRXm/EPoxDHTgImaXz8HK7P5l1rmhLoSJaf0Q330DO10BivvG+yt4sEGMGLc5wB4VKACuzGDTFOAyhFAkualNoKqZLyzQYAJuILZeZfO7BUBmmMkS3O+pZlMvxmthpyDrNnyUmLBb2uXlzig5kBWh0ZFWegioX7nLs/uODqMhlj2U2qEX6E33q0R9qEuJjv4HWEnVRjrTUdrRV6fiahbf7gnH68jN9f0+MisPBqPLzpQBj+eyqt2BZAq9J2cn70I5lzErIpxMBPXwfmM4sF7MhtyvaNvAbq9Sm02IVOIwxHDsoON/yjggIVeY5g+6XvKQgq5/jg=="
]
}'
Method
MethodRequest URL
POST /pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/acknowledge
PathTypeRequiredDescription
project_idStringRequired   KakaoCloud project name (unique ID)
- Can be checked at the top of the console
subscription-nameStringRequired   Subscription name
Request Header
RequestTypeRequiredDescription
Credential-IDStringRequired   Access Key ID
Credential-SecretStringRequired   Security Access Key
Request Elements
RequestTypeDescription
ackIdsstring ArrayackIds values ​​confirmed after message request
Status Code
HTTP StatusDescription
200Success
400Request Information Error
401, 403Authentication Failed, Unauthorized
404Subscription Not Found

If the subscription type is Push

If you select Push as the subscription type, here's how to receive messages:

Key Concepts
Key ConceptsDescription
Subscription typePush: Send messages to the Endpoint you set in Pub/Sub
Endpoint URLEndpoint server URL to receive messages published to the topic
- PROTOCOL: HTTP/HTTPS
- METHOD: POST
Wait Time for ResponseTime to Wait for Message Acknowledgement Response
- Time Range: Set within 10-600 seconds (10 minutes)
Acknowledgement response- If there is no HTTP Response from the Endpoint registered by the user within the response waiting time, the message is resent
- If a code other than HTTP Response Status Code (102, 200, 201, 202, 204) is received, the message is resent immediately

Create subscription

Create a subscription by selecting Push as the subscription type in the Pub/Sub service. For detailed instructions on creating a subscription, refer to the Create subscription.

info

If you use the Push subscription type, you can Push Message only with an endpoint URL using KakaoCloud public IP.

Configure security group

If you use a Push type subscription, you need to set up a security group to send messages to the endpoint server.

  • You need to set an inbound policy for the security group of the resource connected to the set endpoint URL.
  • You can Push even if you set the bandwidth to Any, but it is recommended to specify a Source IP because it is vulnerable to security.
caution

For security reasons, ports 22, 1433, 1521, 3306, 3389, 6379, 27017 cannot be set as Push endpoints.

info

For using Push subscription of Default-Topic

  • kr-central-2 security group open source IP is 61.109.235.11.

For using Push subscription of User Topic

  • kr-central-2 security group open source IP is 61.109.238.137, 61.109.238.107, 61.109.237.249, 61.109.238.114, 61.109.238.74, 61.109.236.65.

For detailed information on security groups, please refer to the document Creating and Managing Security Groups.

  1. Select the VPC menu in the KakaoCloud Console.
  2. Click the Security Group menu, then select the security group to set the inbound policy.
  • However, you must select the security group of the resource connected to the endpoint URL.
  1. Click the [Manage inbound rules] button on the Inbound rules tab, then set the inbound policy to the security group.

Receive messages

When a message is published to a topic, the message is received in the following format.

Message format
"subscription": string
"messages": [
{
"message": {
"data": string,
"attributes": map[string][]string
"messageId": string,
"publishTime": time (RFC3339)
}
},
{
"message": {
"data": string,
"attributes": map[string][]string
"messageId": string,
"publishTime": time (RFC3339)
}
}
]