Search in sources :

Example 11 with AcknowledgeablePubsubMessage

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);
}
Also used : Disposable(reactor.core.Disposable) Disposable(reactor.core.Disposable) FluxSink(reactor.core.publisher.FluxSink) CompletableFuture(java.util.concurrent.CompletableFuture) Mono(reactor.core.publisher.Mono) Scheduler(reactor.core.scheduler.Scheduler) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) Flux(reactor.core.publisher.Flux) List(java.util.List) Duration(java.time.Duration) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) PubSubSubscriberOperations(org.springframework.cloud.gcp.pubsub.core.subscriber.PubSubSubscriberOperations) Assert(org.springframework.util.Assert)

Example 12 with AcknowledgeablePubsubMessage

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();
}
Also used : List(java.util.List) ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) ConvertedBasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage) BasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage) Test(org.junit.Test)

Aggregations

AcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage)12 ConvertedAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage)8 BasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage)7 ConvertedBasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage)7 Test (org.junit.Test)5 List (java.util.List)4 HashSet (java.util.HashSet)3 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2 ArrayList (java.util.ArrayList)2 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 Empty (com.google.protobuf.Empty)1 AcknowledgeRequest (com.google.pubsub.v1.AcknowledgeRequest)1 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)1 Duration (java.time.Duration)1 CompletableFuture (java.util.concurrent.CompletableFuture)1