1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.pubsub.v1.samples; 18 19 // [START pubsub_v1_generated_Subscriber_Pull_sync] 20 import com.google.cloud.pubsub.v1.SubscriptionAdminClient; 21 import com.google.pubsub.v1.PullRequest; 22 import com.google.pubsub.v1.PullResponse; 23 import com.google.pubsub.v1.SubscriptionName; 24 25 public class SyncPull { 26 main(String[] args)27 public static void main(String[] args) throws Exception { 28 syncPull(); 29 } 30 syncPull()31 public static void syncPull() throws Exception { 32 // This snippet has been automatically generated and should be regarded as a code template only. 33 // It will require modifications to work: 34 // - It may require correct/in-range values for request initialization. 35 // - It may require specifying regional endpoints when creating the service client as shown in 36 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 37 try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { 38 PullRequest request = 39 PullRequest.newBuilder() 40 .setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString()) 41 .setReturnImmediately(true) 42 .setMaxMessages(496131527) 43 .build(); 44 PullResponse response = subscriptionAdminClient.pull(request); 45 } 46 } 47 } 48 // [END pubsub_v1_generated_Subscriber_Pull_sync] 49