Search in sources :

Example 1 with MNSClient

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

use of com.aliyun.mns.client.MNSClient 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)2 CloudQueue (com.aliyun.mns.client.CloudQueue)2 MNSClient (com.aliyun.mns.client.MNSClient)2 MqttException (org.eclipse.paho.mqttv5.common.MqttException)2