Search in sources :

Example 6 with CloudQueue

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;
}
Also used : QueueMeta(com.aliyun.mns.model.QueueMeta) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 7 with CloudQueue

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());
}
Also used : StandardThreadExecutor(com.mendmix.common.async.StandardThreadExecutor) StandardThreadFactory(com.mendmix.common.async.StandardThreadExecutor.StandardThreadFactory) Semaphore(java.util.concurrent.Semaphore) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 8 with CloudQueue

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;
}
Also used : Message(com.aliyun.mns.model.Message) QueueServer(cn.cerc.db.queue.QueueServer) DataRow(cn.cerc.db.core.DataRow) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 9 with CloudQueue

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);
}
Also used : Message(com.aliyun.mns.model.Message) QueueServer(cn.cerc.db.queue.QueueServer) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 10 with CloudQueue

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);
    }
}
Also used : CloudAccount(com.aliyun.mns.client.CloudAccount) MNSClient(com.aliyun.mns.client.MNSClient) MqttException(org.eclipse.paho.mqttv5.common.MqttException) CloudQueue(com.aliyun.mns.client.CloudQueue)

Aggregations

CloudQueue (com.aliyun.mns.client.CloudQueue)14 Message (com.aliyun.mns.model.Message)5 QueueServer (cn.cerc.db.queue.QueueServer)2 CloudAccount (com.aliyun.mns.client.CloudAccount)2 MNSClient (com.aliyun.mns.client.MNSClient)2 ClientException (com.aliyun.mns.common.ClientException)2 ServiceException (com.aliyun.mns.common.ServiceException)2 QueueMeta (com.aliyun.mns.model.QueueMeta)2 Semaphore (java.util.concurrent.Semaphore)2 MqttException (org.eclipse.paho.mqttv5.common.MqttException)2 DataRow (cn.cerc.db.core.DataRow)1 QueueSession (cn.cerc.jdb.queue.QueueSession)1 HttpEndpoint (com.aliyun.mns.sample.HttpEndpoint)1 StandardThreadExecutor (com.jeesuite.common.async.StandardThreadExecutor)1 StandardThreadFactory (com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory)1 StandardThreadExecutor (com.mendmix.common.async.StandardThreadExecutor)1 StandardThreadFactory (com.mendmix.common.async.StandardThreadExecutor.StandardThreadFactory)1