Get started with SMQ SDK for Java

Updated at:

Add Simple Message Queue (formerly MNS) SDK for Java to your project and find sample code for common messaging scenarios.

Add the SDK to your project

SMQ SDK for Java is available on Maven Repository. Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.aliyun.mns</groupId>
    <artifactId>aliyun-sdk-mns</artifactId>
    <version>1.1.10</version>
</dependency>
Note
  • The examples in this guide use version 1.1.10. Check Versions for the latest release.

  • Use the latest version for debugging to prevent errors.

The source code and release tags are also available on GitHub.

Sample code

SMQ SDK for Java includes samples for credentials, queue messaging, topic pub/sub, and advanced scenarios. Each entry links to a step-by-step guide and a runnable demo on GitHub.

Credentials

TaskGuideDemo
Configure an access credential by using a Resource Access Management (RAM) roleConfigure endpoints and access credentialsRamRoleCredentialsDemo.java

Queue operations

TaskGuideDemo
Send messages to a queueSend a message to a queueSendMessageDemo.java
Receive and consume messages from a queueReceive messagesReceiveMessageDemo.java

Topic operations

TaskGuideDemo
Publish messages to a topicSend a message to a topicPublishMessageDemo.java
Subscribe to a topic and receive messages on downstream clientsSubscribe to a topicConsumerQueueForTopicDemo.java
Receive messages on an HTTP subscriber endpointCreate an HTTP subscriptionHttpEndpointSubscription.java

Advanced scenarios

TaskGuideDemo
Send and receive oversized messagesTransfer oversized messagesLargeMessageDemo.java
Run a concurrency testPerform a concurrency testJavaSDKPerfTest.java