Improve authentication performance for HttpEndpoint API calls in Simple Message Queue (formerly MNS)

Updated at:

Overview

Remote requests for public key certificates can slow down authentication for HttpEndpoint API calls in Simple Message Queue (formerly MNS). This topic describes how to improve authentication performance.

Cause

Each push request from Simple Message Queue (formerly MNS) includes a public key certificate address. You can use this address to cache the certificate as a key-value pair. If the certificate has not been updated, you can retrieve it directly from memory. This reduces the time required for each remote request. If the certificate is replaced, its name and address might also change.

Solution

When you process a push request, retrieve the certificate from the cache using the address in the x-mns-signing-cert-url parameter. If the retrieval fails, retrieve the certificate remotely and store it in the cache for future use.

For example, the public key certificate address is https://mnstest.oss-cn-hangzhou.aliyuncs.com/x509_public_certificate.pem. You can cache the public key certificate as follows.

typedef map<string, string> cache;
cache["x509_public_certificate.pem"] = "$content";
cache["x509_public_certificate.pem.version2"] = "$content2";