本文整理汇总了Java中com.google.api.services.pubsub.model.AcknowledgeRequest类的典型用法代码示例。如果您正苦于以下问题:Java AcknowledgeRequest类的具体用法?Java AcknowledgeRequest怎么用?Java AcknowledgeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AcknowledgeRequest类属于com.google.api.services.pubsub.model包,在下文中一共展示了AcknowledgeRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: acknowledge
import com.google.api.services.pubsub.model.AcknowledgeRequest; //导入依赖的package包/类
@Override
public void acknowledge(SubscriptionPath subscription, List<String> ackIds) throws IOException {
AcknowledgeRequest request = new AcknowledgeRequest().setAckIds(ackIds);
pubsub.projects()
.subscriptions()
.acknowledge(subscription.getPath(), request)
.execute(); // ignore Empty result.
}
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:PubsubJsonClient.java
示例2: ackPubsubMessage
import com.google.api.services.pubsub.model.AcknowledgeRequest; //导入依赖的package包/类
private void ackPubsubMessage(String subscriptionName) {
List<String> ackIds = ImmutableList.of(ackId);
AcknowledgeRequest ackRequest = new AcknowledgeRequest().setAckIds(ackIds);
try {
pubsub.projects().subscriptions().acknowledge(subscriptionName, ackRequest).execute();
logger.info("Successfully Acked Pubsub message");
} catch (IOException e) {
// we are unable to ack the message and it will get re-delivered(as a duplicate message).
// since, we are only supporting QOS 1 for MQTT this is fine.
logger.info("Unable to Ack Pubsub message");
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:13,代码来源:GcloudRenewMessageTask.java
示例3: ackPubsubMessage
import com.google.api.services.pubsub.model.AcknowledgeRequest; //导入依赖的package包/类
private void ackPubsubMessage(List<String> ackIds) {
AcknowledgeRequest ackRequest = new AcknowledgeRequest().setAckIds(ackIds);
try {
pubsub.projects().subscriptions().acknowledge(subscriptionName, ackRequest).execute();
logger.info("Successfully Acked Pubsub message");
} catch (IOException e) {
// we are unable to ack the message and it will get re-delivered(as a duplicate message).
// since, we are only supporting QOS 1 for MQTT this is fine.
logger.info("Unable to Ack Pubsub message");
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:12,代码来源:GcloudPullMessageTask.java
示例4: pullMessages
import com.google.api.services.pubsub.model.AcknowledgeRequest; //导入依赖的package包/类
/**
* Keeps pulling messages from the given subscription.
*
* @param client Cloud Pub/Sub client.
* @param args Arguments as an array of String.
* @throws IOException when Cloud Pub/Sub API calls fail.
*/
public static void pullMessages(final Pubsub client, final String[] args)
throws IOException {
Main.checkArgsLength(args, 3);
String subscriptionName = PubsubUtils.getFullyQualifiedResourceName(
PubsubUtils.ResourceType.SUBSCRIPTION, args[0], args[2]);
PullRequest pullRequest = new PullRequest()
.setReturnImmediately(false)
.setMaxMessages(Main.BATCH_SIZE);
do {
PullResponse pullResponse;
pullResponse = client.projects().subscriptions()
.pull(subscriptionName, pullRequest)
.execute();
List<String> ackIds = new ArrayList<>(Main.BATCH_SIZE);
List<ReceivedMessage> receivedMessages =
pullResponse.getReceivedMessages();
if (receivedMessages != null) {
for (ReceivedMessage receivedMessage : receivedMessages) {
PubsubMessage pubsubMessage =
receivedMessage.getMessage();
if (pubsubMessage != null
&& pubsubMessage.decodeData() != null) {
System.out.println(
new String(pubsubMessage.decodeData(),
"UTF-8"));
}
ackIds.add(receivedMessage.getAckId());
}
AcknowledgeRequest ackRequest = new AcknowledgeRequest();
ackRequest.setAckIds(ackIds);
client.projects().subscriptions()
.acknowledge(subscriptionName, ackRequest)
.execute();
}
} while (System.getProperty(Main.LOOP_ENV_NAME) != null);
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:45,代码来源:SubscriptionMethods.java
示例5: run
import com.google.api.services.pubsub.model.AcknowledgeRequest; //导入依赖的package包/类
@Override
public void run() {
try {
while (!pubsubReceiver.isStopped()) {
final PullRequest pullRequest = new PullRequest().setReturnImmediately(false)
.setMaxMessages(pubsubReceiver.getBatchSize());
PullResponse pullResponse;
pullResponse = pubsubClient.projects().subscriptions().pull(pubsubReceiver.getSubscription(), pullRequest)
.execute();
final List<ReceivedMessage> receivedMessages = pullResponse.getReceivedMessages();
if (CollectionUtils.isNotEmpty(receivedMessages)) {
final List<String> messages = new ArrayList<>(pubsubReceiver.getBatchSize());
final List<String> ackIds = new ArrayList<>(pubsubReceiver.getBatchSize());
for (final ReceivedMessage receivedMessage : receivedMessages) {
final PubsubMessage pubsubMessage = receivedMessage.getMessage();
if (pubsubMessage != null) {
if (decodeData) {
messages.add(new String(pubsubMessage.decodeData(), StandardCharsets.UTF_8));
} else {
messages.add(pubsubMessage.getData());
}
}
ackIds.add(receivedMessage.getAckId());
}
if (CollectionUtils.isNotEmpty(messages)) {
pubsubReceiver.store(messages.iterator());
}
final AcknowledgeRequest ackRequest = new AcknowledgeRequest().setAckIds(ackIds);
pubsubClient.projects().subscriptions().acknowledge(pubsubReceiver.getSubscription(), ackRequest)
.execute();
}
}
} catch (Throwable t) {
pubsubReceiver.restart(
"Error while fetching messages from pubsub for subscription " + pubsubReceiver.getSubscription(), t);
}
}
开发者ID:SignifAi,项目名称:Spark-PubSub,代码行数:45,代码来源:PubsubReceiverWorker.java
注:本文中的com.google.api.services.pubsub.model.AcknowledgeRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论