tencent cloud

TDMQ for CMQ

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Strengths
Use Cases
Use Limits
Basic Concepts
Purchase Guide
Billing Overview
Purchase Methods
Pricing Overview
Payment Overdue
Refund
Getting Started
Getting Started with Queue Model
Getting Started with Topic Model
Operation Guide
Queue Service
Topic Subscription
Access Management (CAM)
Tag Management
Alarm Configuration
Message Query and Trace
Practical Tutorial
Message Deduplication
Push/Pull Selection
Success Stories
Online Image Processing
Qidian.com
Development Guide
HTTP Endpoint Subscription
General References
API Documentation
API Documentation
API 2.0 to 3.0 Switch Guide
SDK Documentation
HTTP Data Flow SDK
HTTP Control Flow SDK
SDK Parameter Configuration Description
FAQs
Features
Operations
Service Level Agreement
Contact Us
Glossary

HTTP Endpoint Subscription

PDF
Focus Mode
Font Size
Last updated: 2024-01-03 10:20:35

Delivery Description

CMQ can push topic messages to the subscribed HTTP endpoint by sending POST requests. The message can be in JSON or SIMPLIFIED format.
JSON format: The body of the pushed HTTP request contains the message body and attribute information. The Content-type is text/plain.
SIMPLIFIED format: The body of the pushed HTTP request is the message body, while information such as msgId will be delivered to the subscriber in the HTTP request header.
If the HTTP service of the subscriber returns a standard 2xx response code (such as 200), the delivery succeeded; otherwise, the delivery failed, and the delivery retry policy has been triggered. If no response is returned after the timeout period elapses, CMQ will also consider the request as a failure and trigger the delivery retry policy. The detection timeout period is about 15 seconds.

HTTP Delivery Request Headers

Parameter
Description
x-cmq-request-id
requestId of the current push message
x-cmq-message-id
msgId of the current push message
x-cmq-message-tag
Tag of the current push message

HTTP Delivery Request Body

The body of an HTTP request in JSON format contains the message body and attribute information.
Parameter
Type
Description
TopicOwner
String
APPID of the owner of the subscribed topic
topicName
String
Topic name
subscriptionName
String
Subscription name
msgId
String
Message ID
msgBody
String
Message body
publishTime
Int
Message published time
The body of an HTTP request in SIMPLIFIED format is the message body published by the publisher.

HTTP Delivery Request Response

If a 2xx response code is returned, the HTTP service of the subscriber has normally processed the delivered message; if another response code is returned or no response is returned after the timeout period elapses, an error will be reported, and the delivery retry policy will be triggered.

Sample Request

In this sample, the subscribed HTTP endpoint is http://test.com/cgi. JSON format:
POST /cgi HTTP/1.1
Host: test.com
Content-Length: 761
Content-Type: text/plain
User-Agent: Qcloud Notification Service Agent
x-cmq-request-id: 2394928734
x-cmq-message-id: 6942316962
x-cmq-message-tag: a, b

{"TopicOwner":100015036,"topicName":"MyTopic","subscriptionName":"mysubscription","msgId":"6942316962","msgBody":"test message","publishTime":11203432}
SIMPLIFIED format:
POST /cgi HTTP/1.1
Host: test.com
Content-Length: 123
Content-Type: text/plain
User-Agent: Qcloud Notification Service Agent
x-cmq-request-id: 2394928734
x-cmq-message-id: 6942316962
x-cmq-message-tag: a, b

test message

Sample Message Subscription

The following is a message subscription demo, where all messages are delivered in the POST method; therefore, you only need to rewrite the do_POST method.
This sample will print the received HTTP POST request content and deserialize post data json to traverse the printed request data.
#!/usr/bin/python
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import json
class TestHTTPHandle(BaseHTTPRequestHandler):
def do_POST(self):
content_len = int(self.headers.getheader('content-length',0))
post_body = self.rfile.read(content_len)
print "receive cmq topic publisher request:"
print self.headers
print post_body
post_data = json.loads(post_body)
for k,v in post_data.iteritems():
print "key:%s value:%s" % (k,v)
#response http status 200
self.send_response(200)
self.end_headers()
self.wfile.write('ok')
def start_server(port):
http_server = HTTPServer(('0.0.0.0', int(port)),TestHTTPHandle)
http_server.serve_forever()
if __name__ == '__main__':
start_server(80)


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback