All Products
Search
Document Center

Short Message Service:SMQ (formerly MNS) consumption mode demo

Last Updated:Aug 20, 2026

Download the SDK for your programming language to pull message receipts from an SMQ queue.

SDK version guide

Alibaba Cloud SMS provides V1.0 SDK and V2.0 SDK. V2.0 SDK is the latest version and offers the same API features as V1.0 SDK. Compared to V1.0 SDK, V2.0 SDK is more robust, is easier to use, and supports more languages. It also resolves the single-client thread safety issue, providing a better developer experience.

Note

V1.0 SDK is no longer maintained. If you still use V1.0, upgrade to V2.0 SDK.

SDK downloads

The International SMS SDK supports multiple languages. You can find the SDK installation methods on the OpenAPI Portal. You can also view the source code and installation guides on GitHub. We recommend that you install the SDK using the standard dependency management tool for your programming language.

Language

SDK installation method

GitHub address

Quick Start

Java

SDK for Java

java-dysmsapi-20180501

Use Alibaba Cloud SDK for Java in an IDE

Python

SDK for Python

python-dysmsapi-20180501

Use Alibaba Cloud SDK for Python in an IDE

PHP

SDK for PHP

php-dysmsapi-20180501

Use Alibaba Cloud SDK for PHP in an IDE

Go

SDK for Go

go-dysmsapi-20180501

Use Alibaba Cloud SDK for Go in an IDE

TypeScript

SDK for TypeScript

typescript-dysmsapi-20180501

Use Alibaba Cloud SDK for Node.js in an IDE

C++

SDK for Swift

cpp-dysmsapi-20180501

/

C#

SDK for C#

csharp-dysmsapi-20180501

Use Alibaba Cloud .NET SDK in an IDE

Swift

SDK for Swift

swift-dysmsapi-20180501

/

Message receipt samples

Note

Before calling an API, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables for SDK authentication. Steps to configure environment variables.

Java demo

package com.alicom.mns.sample;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.alicom.mns.tools.inter.DefaultAlicomMessagePuller;
import com.alicom.mns.tools.inter.MessageListener;
import com.aliyun.mns.model.Message;

/**
 * This is the DEMO for SMS MNS Queue messages consumption
 * MessageType: SmsReport
 */
public class ReceiveDemo {


    static class MyMessageListener implements MessageListener {
        @Override
        public boolean dealMessage(Message message) {

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("message receiver time from mns:" + format.format(new Date()));
            System.out.println("message handle: " + message.getReceiptHandle());
            System.out.println("message body: " + message.getMessageBodyAsString());
            System.out.println("message id: " + message.getMessageId());
            System.out.println("message dequeue count:" + message.getDequeueCount());
            System.out.println("Thread:" + Thread.currentThread().getName());
            try {
                //Please start your own code here

            } catch (Throwable e) {
                // The exception caused by your own code. Message will not be deleted and can be retrieved again
                return false;
            }
            // Message will be deleted for the format error
            return true;
        }

    }

    public static void main(String[] args) {

        DefaultAlicomMessagePuller puller = new DefaultAlicomMessagePuller();

        //Set the size of asynchronous thread
        puller.setConsumeMinThreadSize(6);
        puller.setConsumeMaxThreadSize(16);
        puller.setThreadQueueSize(200);
        puller.setPullMsgThreadSize(1);
        //Only enabled when debugging, should be disabled at working status
        puller.openDebugLog(false);

        String regionIdForPop = "ap-southeast-1";
        String endpointNameForPop = "ap-southeast-1";

        //If you are sending SMS requests to Singapore Region OpenAPI (domain: dysmsapi.ap-southeast-1.aliyuncs.com)
        //Please use
        String domainForPop = "dybaseapi.ap-southeast-1.aliyuncs.com";
        String mnsAccountEndpoint = "http://1493622401794734.mns.ap-southeast-1.aliyuncs.com";

        //If you are sending SMS requests to Indonesia Region(Jakarta) OpenAPI (domain: dysmsapi.ap-southeast-5.aliyuncs.com)
        //Please use
        //String domainForPop = "dybaseapi.ap-southeast-5.aliyuncs.com";
        //String mnsAccountEndpoint = "http://1493622401794734.mns.ap-southeast-5.aliyuncs.com";

        //If you are sending SMS requests to Germany Region(Frankfurt) OpenAPI (domain: dysmsapi.eu-central-1.aliyuncs.com)
        //String domainForPop = "dybaseapi.eu-central-1.aliyuncs.com";
        //String mnsAccountEndpoint = "http://1493622401794734.mns.eu-central-1.aliyuncs.com";

        //If you are sending SMS requests to US East Region(Virginia) OpenAPI (domain: dysmsapi.us-east-1.aliyuncs.com)
        //String domainForPop = "dybaseapi.us-east-1.aliyuncs.com";
        //String mnsAccountEndpoint = "http://1493622401794734.mns.us-east-1.aliyuncs.com";

        //AccessKey and SecretKey you can get if from Alibaba Cloud Console
        String accessKeyId = "";
        String accessKeySecret = "";

        //SmsReport
        String messageType = "SmsReport";

        //QueueName you can get it from Alibaba Cloud Sms Console
        //Pattern: Alicom-Queue-{UID}-{messageType}
        String queueName = "";

        puller.startReceiveMsgForVPC(accessKeyId, accessKeySecret, messageType, queueName, regionIdForPop,
            endpointNameForPop, domainForPop, mnsAccountEndpoint, new MyMessageListener());

        //or init your IAcsClient(accessKeySecret free)
        //puller.startReceiveMsg(acsClient, messageType, queueName, new MyMessageListener(), mnsAccountEndpoint);
    }

}

FAQ

"SSL: CERTIFICATE_VERIFY_FAILED" error when you integrate the Python SDK on macOS

The error `websocket closed due to [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)` occurs when the Python SDK on macOS cannot verify the server certificate.

This typically happens because the root certificate is not configured in your Python environment. Fix it with these steps:

  1. Export system certificates and set environment variables: Export all macOS system certificates to a file and set it as the default certificate path.

    security find-certificate -a -p > ~/all_mac_certs.pem
    export SSL_CERT_FILE=~/all_mac_certs.pem
    export REQUESTS_CA_BUNDLE=~/all_mac_certs.pem
  2. Create a symbolic link for the Python OpenSSL configuration: Create a symlink to the system SSL certificates. Replace the path with your actual Python version.

    # 3.9 is an example version number. Adjust the path based on the Python version installed on your local machine.
    ln -s /etc/ssl/* /Library/Frameworks/Python.framework/Versions/3.9/etc/openssl
  3. Restart the terminal and clear the cache: Close and reopen the terminal for the environment variables to take effect. You can then clear any possible cache and try to connect to the WebSocket again.

If the issue persists after these steps, verify the certificate configuration of the destination server.