use of org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubReactiveFactory method pollingPull.
private void pollingPull(String subscriptionName, long pollingPeriodMs, FluxSink<AcknowledgeablePubsubMessage> sink) {
Disposable disposable = Flux.interval(Duration.ZERO, Duration.ofMillis(pollingPeriodMs), scheduler).flatMap(ignore -> pullAll(subscriptionName)).subscribe(sink::next, sink::error);
sink.onDispose(disposable);
}
use of org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubSubscriberTemplateTests method testPullAsync_AndManualAck.
@Test
public void testPullAsync_AndManualAck() throws InterruptedException, ExecutionException, TimeoutException {
ListenableFuture<List<AcknowledgeablePubsubMessage>> asyncResult = this.pubSubSubscriberTemplate.pullAsync("sub", 1, true);
List<AcknowledgeablePubsubMessage> result = asyncResult.get(10L, TimeUnit.SECONDS);
assertThat(asyncResult.isDone()).isTrue();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(0).getPubsubMessage()).isSameAs(this.pubsubMessage);
assertThat(result.get(0).getProjectSubscriptionName().getProject()).isEqualTo("testProject");
assertThat(result.get(0).getProjectSubscriptionName().getSubscription()).isEqualTo("sub");
AcknowledgeablePubsubMessage acknowledgeablePubsubMessage = result.get(0);
assertThat(acknowledgeablePubsubMessage.getAckId()).isNotNull();
TestListenableFutureCallback ackTestListenableFutureCallback = new TestListenableFutureCallback();
ListenableFuture<Void> ackListenableFuture = this.pubSubSubscriberTemplate.ack(result);
assertThat(ackListenableFuture).isNotNull();
ackListenableFuture.addCallback(ackTestListenableFutureCallback);
ackListenableFuture.get(10L, TimeUnit.SECONDS);
assertThat(ackListenableFuture.isDone()).isTrue();
assertThat(ackTestListenableFutureCallback.getThrowable()).isNull();
}
Aggregations