Shipping news

Last updated: 2020-02-26 15:51:43

    Queue Endpoint subscription

    CMQ will push the original message of publish and topic to the subscribed queue Queue, so that consumers can read the corresponding message from Queue.

    HTTP Endpoint subscription

    Shipping description

    CMQ pushes topic's message to the HTTP Endpoint side of the subscription by sending a POST request. Two message formats are supported: JSON format and SIMPLIFIED simplified format.

    • JSON format: the pushed HTTP request Body contains the body of the message and the attribute information of the message. Content-type is text/plain .
    • SIMPLIFIED format: the pushed HTTP request Body is the message body, and information such as msgId is passed to the subscriber in the HTTP request Header.

    The subscriber's HTTP service returns a standard 2xx response (such as 200), which means that shipping is successful, otherwise shipping fails, and the policy of shipping is triggered to retry. If there is no response when the timeout occurs, the CMQ will also consider it a failure, and the policy of shipping will be retried. The detection timeout is about 15 seconds.

    Shipping's HTTP request Header

    Parameter name Description
    X-cmq-request-id The requestId of this push message
    X-cmq-message-id The msgId of this push message
    X-cmq-message-tag The message label of this push message

    Shipping's HTTP request Body

    In JSON format, HTTP Body contains the body of the message and the attribute information of the message.

    Parameter name Type Description
    TopicOwner String The APPID of the subscribed owner of topic
    TopicName String Topic Name
    SubscriptionName String Subscription Name
    MsgId String Message ID
    MsgBody String Message body
    PublishTime Int Publish time of the news

    In SIMPLIFIED format, HTTP Body is the message body of the publisher publish.

    Shipping's HTTP request response

    The subscriber HTTP service normally processes the shipping message and returns a 2xx response; other response codes or timeouts do not respond, which is regarded as an error and triggers a retry of shipping policy.

    Request Sample

    In this example, the HTTP Endpoint of the subscription 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 subscription message

    The following is the subscription message Demo, shipping messages are all POST methods, so you only need to override the do_POST method.
    This example prints the received HTTP POST request content and deserializes the post data json to enable traversal to print the 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)

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help