Search in sources :

Example 1 with CloudQueue

use of com.aliyun.mns.client.CloudQueue in project httpx by servicex-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)

Example 2 with CloudQueue

use of com.aliyun.mns.client.CloudQueue in project xnx3 by xnx3.

the class MNSUtil method deleteQueue.

/**
 * 删除队列
 * @param queueName
 */
public void deleteQueue(String queueName) {
    try {
        // Delete Queue
        CloudQueue queue = getMNSClient().getQueueRef(queueName);
        queue.delete();
    } catch (ClientException ce) {
        clientException(ce);
    } catch (ServiceException se) {
        serviceException(se);
    } catch (Exception e) {
        exception(e);
    }
}
Also used : ServiceException(com.aliyun.mns.common.ServiceException) ClientException(com.aliyun.mns.common.ClientException) ServiceException(com.aliyun.mns.common.ServiceException) ClientException(com.aliyun.mns.common.ClientException) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 3 with CloudQueue

use of com.aliyun.mns.client.CloudQueue in project summer-bean by cn-cerc.

the class MailRecord method send.

public boolean send() {
    QueueSession sess = (QueueSession) handle.getProperty(QueueSession.sessionId);
    CloudQueue queue = sess.openQueue(appQueue.queueSendMail);
    return sess.append(queue, this.toString());
}
Also used : QueueSession(cn.cerc.jdb.queue.QueueSession) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 4 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.jeesuite.common.async.StandardThreadExecutor) StandardThreadFactory(com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory) Semaphore(java.util.concurrent.Semaphore) CloudQueue(com.aliyun.mns.client.CloudQueue)

Example 5 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)

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