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
| Task | Guide | Demo |
|---|---|---|
| Configure an access credential by using a Resource Access Management (RAM) role | Configure endpoints and access credentials | RamRoleCredentialsDemo.java |
Queue operations
| Task | Guide | Demo |
|---|---|---|
| Send messages to a queue | Send a message to a queue | SendMessageDemo.java |
| Receive and consume messages from a queue | Receive messages | ReceiveMessageDemo.java |
Topic operations
| Task | Guide | Demo |
|---|---|---|
| Publish messages to a topic | Send a message to a topic | PublishMessageDemo.java |
| Subscribe to a topic and receive messages on downstream clients | Subscribe to a topic | ConsumerQueueForTopicDemo.java |
| Create an HTTPS subscription | Create an HTTP subscription | HttpEndpointSubscription.java |
Advanced scenarios
| Task | Guide | Demo |
|---|---|---|
| Send and receive oversized messages | Transfer oversized messages | LargeMessageDemo.java |
| Run a concurrency test | Perform a concurrency test | JavaSDKPerfTest.java |