Search in sources :

Example 1 with CloudAccount

use of com.aliyun.mns.client.CloudAccount 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 CloudAccount

use of com.aliyun.mns.client.CloudAccount in project jeesuite-libs by vakinge.

the class MNSClientInstance method getClient.

public static MNSClient getClient() {
    if (client != null)
        return client;
    synchronized (MNSClientInstance.class) {
        if (client != null)
            return client;
        String accessKeyId = ResourceUtils.getAndValidateProperty("aliyun.mns.accessKeyId");
        String accessKeySecret = ResourceUtils.getAndValidateProperty("aliyun.mns.accessKeySecret");
        String endpoint = ResourceUtils.getAndValidateProperty("aliyun.mns.endpoint");
        CloudAccount account = new CloudAccount(accessKeyId, accessKeySecret, endpoint);
        client = account.getMNSClient();
    }
    return client;
}
Also used : CloudAccount(com.aliyun.mns.client.CloudAccount)

Example 3 with CloudAccount

use of com.aliyun.mns.client.CloudAccount in project rocketmq-connect by apache.

the class MNSSourceTask method start.

@Override
public void start(SourceTaskContext sourceTaskContext) {
    super.start(sourceTaskContext);
    try {
        CloudAccount cloudAccount = new CloudAccount(accessKeyId, accessKeySecret, accountEndpoint);
        mnsClient = cloudAccount.getMNSClient();
        cloudQueue = mnsClient.getQueueRef(queueName);
    } catch (Exception e) {
        log.error("MNSSourceTask | start | error => ", e);
        throw new RuntimeException(e);
    }
}
Also used : CloudAccount(com.aliyun.mns.client.CloudAccount) ServiceException(com.aliyun.mns.common.ServiceException) ClientException(com.aliyun.mns.common.ClientException)

Example 4 with CloudAccount

use of com.aliyun.mns.client.CloudAccount in project jeesuite-libs by vakinge.

the class MNSClientInstance method getClient.

public static MNSClient getClient() {
    if (client != null)
        return client;
    synchronized (MNSClientInstance.class) {
        if (client != null)
            return client;
        String accessKeyId = ResourceUtils.getAndValidateProperty("aliyun.mns.accessKeyId");
        String accessKeySecret = ResourceUtils.getAndValidateProperty("aliyun.mns.accessKeySecret");
        String endpoint = ResourceUtils.getAndValidateProperty("aliyun.mns.endpoint");
        CloudAccount account = new CloudAccount(accessKeyId, accessKeySecret, endpoint);
        client = account.getMNSClient();
    }
    return client;
}
Also used : CloudAccount(com.aliyun.mns.client.CloudAccount)

Example 5 with CloudAccount

use of com.aliyun.mns.client.CloudAccount 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

CloudAccount (com.aliyun.mns.client.CloudAccount)6 CloudQueue (com.aliyun.mns.client.CloudQueue)2 MNSClient (com.aliyun.mns.client.MNSClient)2 MqttException (org.eclipse.paho.mqttv5.common.MqttException)2 ClientException (com.aliyun.mns.common.ClientException)1 ServiceException (com.aliyun.mns.common.ServiceException)1