use of com.aliyun.mns.model.SubscriptionMeta in project jeesuite-libs by vakinge.
the class MNSClientInstance method createTopicIfAbsent.
public static CloudTopic createTopicIfAbsent(String topicName, String subForQueue) {
TopicMeta topicMeta = new TopicMeta();
topicMeta.setTopicName(topicName);
CloudTopic topic = getClient().getTopicRef(topicName);
try {
topic.getAttribute();
} catch (ServiceException e) {
if ("TopicNotExist".equals(e.getErrorCode())) {
topic.create(topicMeta);
}
}
if (StringUtils.isNotBlank(subForQueue)) {
String subscriptionName = "sub-for-queue-" + subForQueue;
PagingListResult<SubscriptionMeta> topicSubscriptions = topic.listSubscriptions(subscriptionName, "", 1);
if (topicSubscriptions == null || topicSubscriptions.getResult() == null || topicSubscriptions.getResult().isEmpty()) {
// 创建订阅关系
SubscriptionMeta subMeta = new SubscriptionMeta();
subMeta.setSubscriptionName(subscriptionName);
subMeta.setEndpoint(topic.generateQueueEndpoint(subForQueue));
subMeta.setNotifyContentFormat(SubscriptionMeta.NotifyContentFormat.SIMPLIFIED);
subMeta.setNotifyStrategy(SubscriptionMeta.NotifyStrategy.EXPONENTIAL_DECAY_RETRY);
topic.subscribe(subMeta);
}
}
return topic;
}
use of com.aliyun.mns.model.SubscriptionMeta in project jeesuite-libs by vakinge.
the class MNSClientInstance method createTopicIfAbsent.
public static CloudTopic createTopicIfAbsent(String topicName, String subForQueue) {
TopicMeta topicMeta = new TopicMeta();
topicMeta.setTopicName(topicName);
CloudTopic topic = getClient().getTopicRef(topicName);
try {
topic.getAttribute();
} catch (ServiceException e) {
if ("TopicNotExist".equals(e.getErrorCode())) {
topic.create(topicMeta);
}
}
if (StringUtils.isNotBlank(subForQueue)) {
String subscriptionName = "sub-for-queue-" + subForQueue;
PagingListResult<SubscriptionMeta> topicSubscriptions = topic.listSubscriptions(subscriptionName, "", 1);
if (topicSubscriptions == null || topicSubscriptions.getResult() == null || topicSubscriptions.getResult().isEmpty()) {
// 创建订阅关系
SubscriptionMeta subMeta = new SubscriptionMeta();
subMeta.setSubscriptionName(subscriptionName);
subMeta.setEndpoint(topic.generateQueueEndpoint(subForQueue));
subMeta.setNotifyContentFormat(SubscriptionMeta.NotifyContentFormat.SIMPLIFIED);
subMeta.setNotifyStrategy(SubscriptionMeta.NotifyStrategy.EXPONENTIAL_DECAY_RETRY);
topic.subscribe(subMeta);
}
}
return topic;
}
Aggregations