1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

format code with maven plugins

This commit is contained in:
fangjian0423
2019-09-26 17:15:41 +08:00
parent ed6942d9df
commit 2435167e1e
529 changed files with 6304 additions and 5164 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
import java.util.concurrent.ConcurrentHashMap;
@@ -22,7 +23,6 @@ import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
/**
*
* @author pbting
*/
public abstract class AbstractSmsService implements ISmsService {
@@ -44,4 +44,4 @@ public abstract class AbstractSmsService implements ISmsService {
return regionId + ":" + accessKeyId + ":" + accessKeySecret;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
import com.aliyuncs.IAcsClient;
@@ -30,91 +31,30 @@ import com.aliyuncs.exceptions.ServerException;
*/
public interface ISmsService {
/**
*
* @param accessKeyId
* @param secret
* @return IAcsClient
*/
IAcsClient getHangZhouRegionClientProfile(String accessKeyId, String secret);
/**
*
* @param sendSmsRequest
* @throws ServerException
* @throws ClientException
* @return SendSmsResponse
*/
SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest)
throws ServerException, ClientException;
/**
*
* @param sendBatchSmsRequest
* @throws ServerException
* @throws ClientException
* @return SendBatchSmsResponse
*/
SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendBatchSmsRequest)
throws ServerException, ClientException;
/**
* 因为阿里云支持多个
* accessKeyId/accessKeySecret,当不想使用默认的配置accessKeyId/accessKeySecret时可以使用这个方法来支持额外
* 的accessKeyId/accessKeySecret 发送
* @param sendSmsRequest
* @param accessKeyId
* @param accessKeySecret
* @return
* @throws ServerException
* @throws ClientException
*/
SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest, String accessKeyId,
String accessKeySecret) throws ServerException, ClientException;
/**
*
* @param sendSmsRequest
* @param accessKeyId
* @param accessKeySecret
* @throws ServerException
* @throws ClientException
* @return SendBatchSmsResponse
*/
SendBatchSmsResponse sendSmsBatchRequest(SendBatchSmsRequest sendSmsRequest,
String accessKeyId, String accessKeySecret)
throws ServerException, ClientException;
/**
*
* @param smsReportMessageListener
* @return boolean
*/
boolean startSmsReportMessageListener(
SmsReportMessageListener smsReportMessageListener);
/**
*
* @param smsUpMessageListener
* @return boolean
*/
boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener);
/**
*
* @param request
* @param accessKeyId
* @param accessKeySecret
* @return QuerySendDetailsResponse
*/
QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request,
String accessKeyId, String accessKeySecret) throws ClientException;
/**
*
* @param request
* @return QuerySendDetailsResponse
*/
QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request)
throws ClientException;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,21 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import com.alibaba.alicloud.context.sms.SmsProperties;
import com.alibaba.alicloud.sms.base.MessageListener;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import com.alibaba.alicloud.context.sms.SmsProperties;
import com.alibaba.alicloud.sms.base.MessageListener;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
/**
* @author pbting
*/
@@ -104,4 +104,5 @@ public class SmsInitializerEventListener
"initialize sms profile end point cause an exception");
}
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
import com.alibaba.alicloud.sms.base.MessageListener;
@@ -21,4 +22,5 @@ import com.alibaba.alicloud.sms.base.MessageListener;
* @author pbting
*/
public interface SmsMessageListener extends MessageListener {
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
/**
* @author pbting
*/
public interface SmsReportMessageListener extends SmsMessageListener {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,19 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
import java.text.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.alicloud.context.AliCloudProperties;
import com.alibaba.alicloud.context.sms.SmsProperties;
import com.alibaba.alicloud.sms.base.DefaultAlicomMessagePuller;
import com.alibaba.alicloud.sms.endpoint.EndpointManager;
import com.alibaba.alicloud.sms.endpoint.ReceiveMessageEntity;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest;
@@ -34,6 +31,8 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author pbting
@@ -41,10 +40,9 @@ import com.aliyuncs.exceptions.ServerException;
public final class SmsServiceImpl extends AbstractSmsService {
private static final Logger log = LoggerFactory.getLogger(SmsServiceImpl.class);
/**
* will expose user to call this method send sms message
* @param sendSmsRequest
* @return
* will expose user to call this method send sms message.
*/
private SmsProperties smsProperties;
@@ -64,17 +62,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
aliCloudProperties.getSecretKey());
}
/**
* 因为阿里云支持多个
* accessKeyId/accessKeySecret,当不想使用默认的配置accessKeyId/accessKeySecret时可以使用这个方法来支持额外
* 的accessKeyId/accessKeySecret 发送
* @param sendSmsRequest
* @param accessKeyId
* @param accessKeySecret
* @throws ServerException
* @throws ClientException
* @return SendSmsResponse
*/
@Override
public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest,
String accessKeyId, String accessKeySecret)
@@ -85,11 +72,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
.getAcsResponse(sendSmsRequest);
}
/**
*
* @param smsReportMessageListener
* @return boolean
*/
@Override
public boolean startSmsReportMessageListener(
SmsReportMessageListener smsReportMessageListener) {
@@ -99,11 +81,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
return startReceiveMsg(messageType, queueName, smsReportMessageListener);
}
/**
*
* @param smsUpMessageListener
* @return boolean
*/
@Override
public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener) {
// 短信回执SmsReport短信上行SmsUp
@@ -112,13 +89,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
return startReceiveMsg(messageType, queueName, smsUpMessageListener);
}
/**
*
* @param messageType
* @param queueName
* @param messageListener
* @return boolean
*/
private boolean startReceiveMsg(String messageType, String queueName,
SmsMessageListener messageListener) {
String accessKeyId = aliCloudProperties.getAccessKey();
@@ -141,13 +111,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
return result;
}
/**
*
* @param sendBatchSmsRequest
* @throws ServerException
* @throws ClientException
* @return SendBatchSmsResponse
*/
@Override
public SendBatchSmsResponse sendSmsBatchRequest(
SendBatchSmsRequest sendBatchSmsRequest)
@@ -157,14 +120,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
aliCloudProperties.getSecretKey());
}
/**
*
* @param sendBatchSmsRequest
* @param accessKeyId
* @param accessKeySecret
* @throws ClientException
* @return SendBatchSmsResponse
*/
@Override
public SendBatchSmsResponse sendSmsBatchRequest(
SendBatchSmsRequest sendBatchSmsRequest, String accessKeyId,
@@ -174,14 +129,6 @@ public final class SmsServiceImpl extends AbstractSmsService {
.getAcsResponse(sendBatchSmsRequest);
}
/**
*
* @param request
* @param accessKeyId
* @param accessKeySecret
* @throws ClientException
* @return QuerySendDetailsResponse
*/
@Override
public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request,
String accessKeyId, String accessKeySecret) throws ClientException {
@@ -189,16 +136,11 @@ public final class SmsServiceImpl extends AbstractSmsService {
.getAcsResponse(request);
}
/**
*
* @param request
* @throws ClientException
* @return QuerySendDetailsResponse
*/
@Override
public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request)
throws ClientException {
return querySendDetails(request, aliCloudProperties.getAccessKey(),
aliCloudProperties.getSecretKey());
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms;
/**
* @author pbting
*/
public interface SmsUpMessageListener extends SmsMessageListener {
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import java.text.ParseException;
@@ -25,32 +26,40 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aliyun.mns.client.CloudQueue;
import com.aliyun.mns.common.ClientException;
import com.aliyun.mns.common.ServiceException;
import com.aliyun.mns.model.Message;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 阿里通信官方消息默认拉取工具类
* 阿里通信官方消息默认拉取工具类.
*/
public class DefaultAlicomMessagePuller {
private static final Logger log = LoggerFactory
.getLogger(DefaultAlicomMessagePuller.class);
private String mnsAccountEndpoint = "https://1943695596114318.mns.cn-hangzhou.aliyuncs.com/";// 阿里通信消息的endpoint,固定。
private String mnsAccountEndpoint = "https://1943695596114318.mns.cn-hangzhou.aliyuncs.com/"; // 阿里通信消息的endpoint,固定。
private String endpointNameForPop = "cn-hangzhou";
private String regionIdForPop = "cn-hangzhou";
private String domainForPop = "dybaseapi.aliyuncs.com";
private TokenGetterForAlicom tokenGetter;
private MessageListener messageListener;
private boolean isRunning = false;
private Integer pullMsgThreadSize = 1;
private boolean debugLogOpen = false;
private Integer sleepSecondWhenNoData = 30;
public void openDebugLog(boolean debugLogOpen) {
@@ -86,7 +95,9 @@ public class DefaultAlicomMessagePuller {
}
protected static final Map<String, Object> S_LOCK_OBJ_MAP = new HashMap<>();
protected static Map<String, Boolean> sPollingMap = new ConcurrentHashMap<>();
protected Object lockObj;
public boolean setPolling(String queueName) {
@@ -118,8 +129,155 @@ public class DefaultAlicomMessagePuller {
isRunning = running;
}
/**
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param messageType 消息类型
* @param queueName 队列名称
* @param messageListener 回调的listener,用户自己实现
* @throws com.aliyuncs.exceptions.ClientException throw by sdk
* @throws ParseException throw parse exception
*/
public void startReceiveMsg(String accessKeyId, String accessKeySecret,
String messageType, String queueName, MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, null);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
/**
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param messageType 消息类型
* @param queueName 队列名称
* @param regionIdForPop region
* @param endpointNameForPop endpoint name
* @param domainForPop domain
* @param mnsAccountEndpoint mns account endpoint
* @param messageListener 回调的listener,用户自己实现
* @throws com.aliyuncs.exceptions.ClientException throw by sdk
* @throws ParseException throw parse exception
*/
public void startReceiveMsgForVPC(String accessKeyId, String accessKeySecret,
String messageType, String queueName, String regionIdForPop,
String endpointNameForPop, String domainForPop, String mnsAccountEndpoint,
MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
this.mnsAccountEndpoint = mnsAccountEndpoint;
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, null);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
/**
* 虚商用户定制接收消息方法.
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param ownerId 实际的ownerId
* @param messageType 消息类型
* @param queueName 队列名称
* @param messageListener 回调listener
* @throws com.aliyuncs.exceptions.ClientException throw by sdk
* @throws ParseException throw parse exception
*/
public void startReceiveMsgForPartnerUser(String accessKeyId, String accessKeySecret,
Long ownerId, String messageType, String queueName,
MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, ownerId);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
public void stop() {
isRunning = false;
}
private class PullMessageTask implements Runnable {
private String messageType;
private String queueName;
@Override
@@ -287,145 +445,4 @@ public class DefaultAlicomMessagePuller {
}
/**
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param messageType 消息类型
* @param queueName 队列名称
* @param messageListener 回调的listener,用户自己实现
* @throws com.aliyuncs.exceptions.ClientException
* @throws ParseException
*/
public void startReceiveMsg(String accessKeyId, String accessKeySecret,
String messageType, String queueName, MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, null);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
/**
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param messageType 消息类型
* @param queueName 队列名称
* @param messageListener 回调的listener,用户自己实现
* @throws com.aliyuncs.exceptions.ClientException
* @throws ParseException
*/
public void startReceiveMsgForVPC(String accessKeyId, String accessKeySecret,
String messageType, String queueName, String regionIdForPop,
String endpointNameForPop, String domainForPop, String mnsAccountEndpoint,
MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
this.mnsAccountEndpoint = mnsAccountEndpoint;
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, null);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
/**
* 虚商用户定制接收消息方法
* @param accessKeyId accessKeyId
* @param accessKeySecret accessKeySecret
* @param ownerId 实际的ownerId
* @param messageType 消息类型
* @param queueName 队列名称
* @param messageListener 回调listener
* @throws com.aliyuncs.exceptions.ClientException
* @throws ParseException
*/
public void startReceiveMsgForPartnerUser(String accessKeyId, String accessKeySecret,
Long ownerId, String messageType, String queueName,
MessageListener messageListener)
throws com.aliyuncs.exceptions.ClientException, ParseException {
tokenGetter = new TokenGetterForAlicom(accessKeyId, accessKeySecret,
endpointNameForPop, regionIdForPop, domainForPop, ownerId);
this.messageListener = messageListener;
isRunning = true;
PullMessageTask task = new PullMessageTask();
task.messageType = messageType;
task.queueName = queueName;
synchronized (S_LOCK_OBJ_MAP) {
lockObj = S_LOCK_OBJ_MAP.get(queueName);
if (lockObj == null) {
lockObj = new Object();
S_LOCK_OBJ_MAP.put(queueName, lockObj);
}
}
if (executorService == null) {
ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(
pullMsgThreadSize,
new BasicThreadFactory.Builder()
.namingPattern(
"PullMessageTask-" + messageType + "-thread-pool-%d")
.daemon(true).build());
executorService = scheduledExecutorService;
}
for (int i = 0; i < pullMsgThreadSize; i++) {
executorService.execute(task);
}
}
public void stop() {
isRunning = false;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import com.aliyun.mns.model.Message;

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import com.aliyuncs.RpcAcsRequest;
public class QueryTokenForMnsQueueRequest
extends RpcAcsRequest<QueryTokenForMnsQueueResponse> {
private String resourceOwnerAccount;
private String messageType;
private Long resourceOwnerId;
private Long ownerId;
public QueryTokenForMnsQueueRequest() {
@@ -80,4 +85,5 @@ public class QueryTokenForMnsQueueRequest
public Class<QueryTokenForMnsQueueResponse> getResponseClass() {
return QueryTokenForMnsQueueResponse.class;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,15 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import com.aliyuncs.AcsResponse;
import com.aliyuncs.transform.UnmarshallerContext;
public class QueryTokenForMnsQueueResponse extends AcsResponse {
private String requestId;
private String code;
private String message;
private QueryTokenForMnsQueueResponse.MessageTokenDTO messageTokenDTO;
public QueryTokenForMnsQueueResponse() {
@@ -66,10 +71,15 @@ public class QueryTokenForMnsQueueResponse extends AcsResponse {
}
public static class MessageTokenDTO {
private String accessKeyId;
private String accessKeySecret;
private String securityToken;
private String createTime;
private String expireTime;
public MessageTokenDTO() {
@@ -114,5 +124,7 @@ public class QueryTokenForMnsQueueResponse extends AcsResponse {
public void setExpireTime(String expireTime) {
this.expireTime = expireTime;
}
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import com.aliyuncs.transform.UnmarshallerContext;
public class QueryTokenForMnsQueueResponseUnmarshaller {
public final class QueryTokenForMnsQueueResponseUnmarshaller {
public QueryTokenForMnsQueueResponseUnmarshaller() {
private QueryTokenForMnsQueueResponseUnmarshaller() {
}
public static QueryTokenForMnsQueueResponse unmarshall(
@@ -45,4 +46,5 @@ public class QueryTokenForMnsQueueResponseUnmarshaller {
queryTokenForMnsQueueResponse.setMessageTokenDTO(messageTokenDTO);
return queryTokenForMnsQueueResponse;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,22 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import com.aliyun.mns.client.CloudQueue;
import com.aliyun.mns.client.MNSClient;
/**
* 用于接收云通信消息的临时token
* 用于接收云通信消息的临时token.
*
*/
public class TokenForAlicom {
private String messageType;
private String token;
private Long expireTime;
private String tempAccessKeyId;
private String tempAccessKeySecret;
private MNSClient client;
private CloudQueue queue;
public String getMessageType() {

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.base;
import java.text.ParseException;
@@ -21,9 +22,6 @@ import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aliyun.mns.client.CloudAccount;
import com.aliyun.mns.client.CloudQueue;
import com.aliyun.mns.client.MNSClient;
@@ -36,23 +34,36 @@ import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 获取接收云通信消息的临时token
*
* 获取接收云通信消息的临时token.
*/
public class TokenGetterForAlicom {
private static final Logger log = LoggerFactory.getLogger(TokenGetterForAlicom.class);
private String accessKeyId;
private String accessKeySecret;
private String endpointNameForPop;
private String regionIdForPop;
private String domainForPop;
private IAcsClient iAcsClient;
private Long ownerId;
private final static String PRODUCT_NAME = "Dybaseapi";
private long bufferTime = 1000 * 60 * 2;// 过期时间小于2分钟则重新获取防止服务器时间误差
private long bufferTime = 1000 * 60 * 2; // 过期时间小于2分钟则重新获取防止服务器时间误差
private final Object lock = new Object();
private ConcurrentMap<String, TokenForAlicom> tokenMap = new ConcurrentHashMap<String, TokenForAlicom>();
public TokenGetterForAlicom(String accessKeyId, String accessKeySecret,
@@ -112,7 +123,7 @@ public class TokenGetterForAlicom {
throws ServerException, ClientException, ParseException {
TokenForAlicom token = tokenMap.get(messageType);
Long now = System.currentTimeMillis();
if (token == null || (token.getExpireTime() - now) < bufferTime) {// 过期时间小于2分钟则重新获取防止服务器时间误差
if (token == null || (token.getExpireTime() - now) < bufferTime) { // 过期时间小于2分钟则重新获取防止服务器时间误差
synchronized (lock) {
token = tokenMap.get(messageType);
if (token == null || (token.getExpireTime() - now) < bufferTime) {
@@ -138,4 +149,5 @@ public class TokenGetterForAlicom {
}
return token;
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,28 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.config;
import com.alibaba.alicloud.context.AliCloudProperties;
import com.alibaba.alicloud.context.sms.SmsProperties;
import com.alibaba.alicloud.sms.ISmsService;
import com.alibaba.alicloud.sms.SmsInitializerEventListener;
import com.alibaba.alicloud.sms.SmsServiceImpl;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.alicloud.context.AliCloudProperties;
import com.alibaba.alicloud.context.sms.SmsProperties;
import com.alibaba.alicloud.sms.ISmsService;
import com.alibaba.alicloud.sms.SmsInitializerEventListener;
import com.alibaba.alicloud.sms.SmsServiceImpl;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
/**
* @author pbting
*/
@Configuration
@EnableConfigurationProperties
@ConditionalOnClass(value = SendSmsRequest.class)
@ConditionalOnClass(SendSmsRequest.class)
@ConditionalOnProperty(value = "spring.cloud.alicloud.sms.enable", matchIfMissing = true)
public class SmsAutoConfiguration {
@@ -49,4 +49,5 @@ public class SmsAutoConfiguration {
SmsProperties smsProperties, ISmsService smsService) {
return new SmsInitializerEventListener(smsProperties, smsService);
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.endpoint;
import java.util.HashMap;
@@ -26,20 +27,27 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendBatchSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
/**
*
*
*/
public final class EndpointManager {
private EndpointManager() {
}
private final static int BACKLOG_SIZE = 20;
private final static ReentrantLock SEND_REENTRANT_LOCK = new ReentrantLock(true);
private final static ReentrantLock SEND_BATCH_REENTRANT_LOCK = new ReentrantLock(
true);
private final static LinkedBlockingQueue<SendSmsRequest> SEND_SMS_REQUESTS = new LinkedBlockingQueue(
BACKLOG_SIZE);
private final static LinkedBlockingQueue<SendBatchSmsRequest> SEND_BATCH_SMS_REQUESTS = new LinkedBlockingQueue(
BACKLOG_SIZE);
private final static LinkedBlockingQueue<ReceiveMessageEntity> RECEIVE_MESSAGE_ENTITIES = new LinkedBlockingQueue(
BACKLOG_SIZE);
@@ -103,4 +111,5 @@ public final class EndpointManager {
return endpointMessages;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.endpoint;
import java.io.Serializable;
@@ -23,8 +24,11 @@ import com.alibaba.alicloud.sms.base.MessageListener;
* @author pbting
*/
public class ReceiveMessageEntity implements Serializable {
private String messageType;
private String queueName;
private MessageListener messageListener;
public ReceiveMessageEntity(String messageType, String queueName,
@@ -57,4 +61,5 @@ public class ReceiveMessageEntity implements Serializable {
public void setMessageListener(MessageListener messageListener) {
this.messageListener = messageListener;
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.endpoint;
import java.util.Map;
@@ -28,4 +29,5 @@ public class SmsEndpoint {
return EndpointManager.getSmsEndpointMessage();
}
}
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2019 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.alicloud.sms.endpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -28,4 +29,5 @@ public class SmsEndpointAutoConfiguration {
public SmsEndpoint smsEndpoint() {
return new SmsEndpoint();
}
}
}