use of com.aliyun.mns.client.CloudQueue in project jeesuite-libs by vakinge.
the class MNSClientInstance method createQueueIfAbsent.
public static CloudQueue createQueueIfAbsent(String queueName) {
QueueMeta queueMeta = new QueueMeta();
queueMeta.setQueueName(queueName);
CloudQueue queue = getClient().getQueueRef(queueName);
if (!queue.isQueueExist()) {
queue.create(queueMeta);
}
return queue;
}
use of com.aliyun.mns.client.CloudQueue in project jeesuite-libs by vakinge.
the class MNSConsumer method start.
private void start() {
CloudQueue queue = MNSClientInstance.createQueueIfAbsent(queueName);
initTopicHanlders();
fetchExecutor = new StandardThreadExecutor(1, 1, 0, TimeUnit.SECONDS, 1, new StandardThreadFactory("mns-Fetch-Executor"));
int maxThread = ResourceUtils.getInt("aliyun.mns.consumer.processThreads", 50);
semaphore = new Semaphore(maxThread);
defaultProcessExecutor = new StandardThreadExecutor(1, maxThread, 60, TimeUnit.SECONDS, 1, new StandardThreadFactory("mns-defaultProcess-Executor"));
fetchExecutor.submit(new Worker(queue));
logger.info("start work for queue Ok -> queue:{}", queue.getQueueURL());
}
use of com.aliyun.mns.client.CloudQueue in project summer-mis by cn-cerc.
the class SyncServerQueue method pop.
@Override
public int pop(ISession session, IPopProcesser popProcesser, int maxRecords) {
if (popFrom == null)
throw new RuntimeException("popFrom is null");
if (popTo == null)
throw new RuntimeException("popTo is null");
// 取出数据队列
String queueCode = popFrom.name().toLowerCase() + "-to-" + popTo.name().toLowerCase();
QueueServer mns = (QueueServer) session.getProperty(QueueServer.SessionId);
CloudQueue queue = mns.openQueue(queueCode);
for (int i = 0; i < maxRecords; i++) {
Message msg = queue.popMessage();
if (msg == null) {
return i;
}
String receiptHandle = msg.getReceiptHandle();
String body = msg.getMessageBody();
if (body == null) {
queue.deleteMessage(receiptHandle);
continue;
}
DataRow record = new DataRow();
record.setJson(body);
try {
if (!popProcesser.popRecord(session, record, true)) {
log.error("{} 处理失败,请检查数据源和帐套信息 {}", receiptHandle, body);
}
queue.deleteMessage(receiptHandle);
} catch (Exception e) {
log.error(record.toString());
e.printStackTrace();
}
}
return maxRecords;
}
use of com.aliyun.mns.client.CloudQueue in project summer-mis by cn-cerc.
the class SyncServerQueue method push.
@Override
public void push(ISession session, DataRow record) {
if (pushFrom == null)
throw new RuntimeException("pushFrom is null");
if (pushTo == null)
throw new RuntimeException("pushTo is null");
// 初始化客户端
QueueServer mns = (QueueServer) session.getProperty(QueueServer.SessionId);
// 数据写入队列
String queueCode = pushFrom.name().toLowerCase() + "-to-" + pushTo.name().toLowerCase();
CloudQueue queue = mns.openQueue(queueCode);
Message message = new Message();
message.setMessageBody(record.toString());
queue.putMessage(message);
}
use of com.aliyun.mns.client.CloudQueue in project httpx by httpx-sh.
the class MessagePublishExecutor method sendMnsMessage.
public void sendMnsMessage(URI mnsURI, HttpRequest httpRequest) {
String[] keyIdAndSecret = readAliyunAccessToken(httpRequest);
if (keyIdAndSecret == null) {
System.err.println("Please supply access key Id/Secret in Authorization header as : `Authorization: Basic keyId:secret`");
return;
}
try {
String topic = mnsURI.getPath().substring(1);
final MNSClient mnsClient = new CloudAccount(keyIdAndSecret[0], keyIdAndSecret[1], "https://" + mnsURI.getHost()).getMNSClient();
final CloudQueue queueRef = mnsClient.getQueueRef(topic);
final com.aliyun.mns.model.Message message = queueRef.putMessage(new com.aliyun.mns.model.Message(httpRequest.getBodyBytes()));
System.out.println("Succeeded to send message to " + topic + " with ID: " + message.getMessageId());
} catch (Exception e) {
log.error("HTX-105-500", httpRequest.getRequestTarget().getUri(), e);
}
}
Aggregations