Class ListTopicsPublisher

  • All Implemented Interfaces:
    org.reactivestreams.Publisher<ListTopicsResponse>, SdkPublisher<ListTopicsResponse>

    @Generated("software.amazon.awssdk:codegen")
    public class ListTopicsPublisher
    extends Object
    implements SdkPublisher<ListTopicsResponse>

    Represents the output for the SnsAsyncClient.listTopicsPaginator(software.amazon.awssdk.services.sns.model.ListTopicsRequest) operation which is a paginated operation. This class is a type of Publisher which can be used to provide a sequence of ListTopicsResponse response pages as per demand from the subscriber.

    When the operation is called, an instance of this class is returned. At this point, no service calls are made yet and so there is no guarantee that the request is valid. If there are errors in your request, you will see the failures only after you start streaming the data. The subscribe method should be called as a request to start streaming data. For more info, see Publisher.subscribe(org.reactivestreams.Subscriber). Each call to the subscribe method will result in a new Subscription i.e., a new contract to stream data from the starting request.

    The following are few ways to use the response class:

    1) Using the subscribe helper method
     
     software.amazon.awssdk.services.sns.paginators.ListTopicsPublisher publisher = client.listTopicsPaginator(request);
     CompletableFuture<Void> future = publisher.subscribe(res -> { // Do something with the response });
     future.get();
     
     
    2) Using a custom subscriber
     
     software.amazon.awssdk.services.sns.paginators.ListTopicsPublisher publisher = client.listTopicsPaginator(request);
     publisher.subscribe(new Subscriber<software.amazon.awssdk.services.sns.model.ListTopicsResponse>() {
     
     public void onSubscribe(org.reactivestreams.Subscriber subscription) { //... };
     
     
     public void onNext(software.amazon.awssdk.services.sns.model.ListTopicsResponse response) { //... };
     });
     
    As the response is a publisher, it can work well with third party reactive streams implementations like RxJava2.

    Please notice that the configuration of null won't limit the number of results you get with the paginator. It only limits the number of results in each page.

    Note: If you prefer to have control on service calls, use the #listTopics(software.amazon.awssdk.services.sns.model.ListTopicsRequest) operation.

    • Method Detail

      • subscribe

        public void subscribe​(org.reactivestreams.Subscriber<? super ListTopicsResponse> subscriber)
        Specified by:
        subscribe in interface org.reactivestreams.Publisher<ListTopicsResponse>
      • topics

        public final SdkPublisher<Topic> topics()
        Returns a publisher that can be used to get a stream of data. You need to subscribe to the publisher to request the stream of data. The publisher has a helper forEach method that takes in a Consumer and then applies that consumer to each response returned by the service.