603
新东方
发送消息示例代码__Java SDK_SDK使用手册_消息服务-阿里云
发送消息
public class ProducerDemo {
public static void main(String[] args) {
CloudAccount account = new CloudAccount("YourAccessId", "YourAccessKey", "MNSEndpoint");
//这个client仅初始化一次
MNSClient client = account.getMNSClient();
//循环发送10条消息
try{
//TestQueue是你的测试队列,请提前创建
CloudQueue queue = client.getQueueRef("TestQueue");
for (int i = 0; i < 10; i++)
{
Message message = new Message();
message.setMessageBody("I am test message " + i);
Message putMsg = queue.putMessage(message);
System.out.println("Send message id is: " + putMsg.getMessageId());
}
} catch (ClientException ce)
{
System.out.println("Something wrong with the network connection between client and MNS service."
+ "Please check your network and DNS availablity.");
ce.printStackTrace();
} catch (ServiceException se)
{
se.printStackTrace();
logger.error("MNS exception requestId:" + se.getRequestId(), se);
if (se.getErrorCode() != null) {
if (se.getErrorCode().equals("QueueNotExist"))
{
System.out.println("Queue is not exist.Please create before use");
} else if (se.getErrorCode().equals("TimeExpired"))
{
System.out.println("The request is time expired. Please check your local machine timeclock");
}
/*
you can get more MNS service error code from following link:
https://help.aliyun.com/document_detail/mns/api_reference/error_code/error_code.html
*/
}
} catch (Exception e)
{
System.out.println("Unknown exception happened!");
e.printStackTrace();
}
client.close();
}
}
最后更新:2016-08-18 13:22:55
上一篇:
主题使用手册__Java SDK_SDK使用手册_消息服务-阿里云
下一篇:
消费消息示例代码__Java SDK_SDK使用手册_消息服务-阿里云
文件操作___用户指南(Linux)_数据管理-阿里云
设置读策略__数据库管理_开放API_分布式关系型数据库 DRDS-阿里云
SMTP之python调用示例__SMTP接口说明_邮件推送-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
删除API分组__API分组相关接口_API_API 网关-阿里云
查询回源流量__资源监控接口_API 手册_CDN-阿里云
创建编排模板__镜像与模板管理_用户指南_容器服务-阿里云
ColumnSchema__DataType_API 参考_表格存储-阿里云
DRDS读写分离__开发手册_分布式关系型数据库 DRDS-阿里云
集群方式订阅消息__Java SDK_TCP 接入(专业)_消息队列 MQ-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云