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.
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 Concepts | Description |
---|---|
Subscription type | Pull : User requests message transmission |
Response waite time | Time to wait for message confirmation response - Time range: Set within 10-600 seconds (10 minutes) |
Acknowledge response | If 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.
- Console
- API
You can check the messages published to the topic through the reception test on the console.
To perform a reception test, you must first publish a message to the topic. For more information, refer to the Publish message.
- Go to KakaoCloud Console > Analytics > Pub/Sub.
- In the Topic menu, select a topic.
- In the Message tab, set test items and click the [Retrieve message] button.
Message tab
Category | Description |
---|---|
Message details | Content of the body of the published message, if none, displayed as - |
Publish time | Time the message was published |
Attributes | Attribute value of the published message, click View Attribute to check Key, Value |
Retry attempts | Number of times the message was reprocessed |
Acknowledgement | Confirmation status according to message response waiting time |
- You can check detailed message contents by clicking Message details or View attributes in the reception test list.
View attributes
Message retrieval can also be performed in the Message tab of the subscription details page.
💡 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
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
Method | Request URL |
---|---|
POST | /pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/pull |
Path | Type | Required | Description |
---|---|---|---|
project_id | String | Required | KakaoCloud project ID - URI displayed in the console address bar of the project (value of project_id ) |
subscription-name | String | Required | Subscription name |
Request Header
Request | Type | Required | Description |
---|---|---|---|
Credential-ID | String | Required | Access key ID |
Credential-Secret | String | Required | Security access key |
Request Elements
Request | Type | Description |
---|---|---|
maxMessages | Integer | Maximum number of message requests 1 to 4,096 |
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
Response | Type | Description |
---|---|---|
ackId | String | ackIds value used for confirmation after message request |
message | Object | Message details |
data | String | Event log, Base64 encoding processing |
messageId | String | Message unique ID |
publishTime | String | Message publishing time |
deliveryAttempt | Integer | Number of message transmission attempts |
Status Code
HTTP Status | Description |
---|---|
200 | Success |
400 | Request information error |
401 , 403 | Authentication failure, unauthorized |
404 | Subscription not found |
Acknowledge
If the message was received normally, you can acknowledge it.
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
Method | Request URL |
---|---|
POST | /pub-sub/kc-event/v1/projects/{project_id}/subscriptions/{subscription-name}/acknowledge |
Path | Type | Required | Description |
---|---|---|---|
project_id | String | Required | KakaoCloud project name (unique ID) - Can be checked at the top of the console |
subscription-name | String | Required | Subscription name |
Request Header
Request | Type | Required | Description |
---|---|---|---|
Credential-ID | String | Required | Access Key ID |
Credential-Secret | String | Required | Security Access Key |
Request Elements
Request | Type | Description |
---|---|---|
ackIds | string Array | ackIds values confirmed after message request |
Status Code
HTTP Status | Description |
---|---|
200 | Success |
400 | Request Information Error |
401 , 403 | Authentication Failed, Unauthorized |
404 | Subscription 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 Concepts | Description |
---|---|
Subscription type | Push: Send messages to the Endpoint you set in Pub/Sub |
Endpoint URL | Endpoint server URL to receive messages published to the topic - PROTOCOL: HTTP/HTTPS - METHOD: POST |
Wait Time for Response | Time 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.
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.
For security reasons, ports 22, 1433, 1521, 3306, 3389, 6379, 27017 cannot be set as Push endpoints.
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.
- Select the VPC menu in the KakaoCloud Console.
- 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.
- 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.
"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)
}
}
]