private void makeSubscriber() { try { log.info("Creating subscriber."); subscriber = SubscriberGrpc.newFutureStub(ConnectorUtils.getChannel(gcpCredentialsProvider)); // We change the subscriber every 25 - 35 minutes in order to avoid GOAWAY errors. nextSubscriberResetTime = System.currentTimeMillis() + rand.nextInt(10 * 60 * 1000) + 25 * 60 * 1000; } catch (IOException e) { throw new RuntimeException("Could not create subscriber stub; no subscribing can occur.", e); } } }
/** * Check whether the user provided Cloud Pub/Sub subscription name specified by {@link * #CPS_SUBSCRIPTION_CONFIG} exists or not. */ @VisibleForTesting public void verifySubscription(String cpsProject, String cpsSubscription, CredentialsProvider credentialsProvider) { try { SubscriberFutureStub stub = SubscriberGrpc.newFutureStub(ConnectorUtils.getChannel(credentialsProvider)); GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder() .setSubscription( String.format( ConnectorUtils.CPS_SUBSCRIPTION_FORMAT, cpsProject, cpsSubscription)) .build(); stub.getSubscription(request).get(); } catch (Exception e) { throw new ConnectException( "Error verifying the subscription " + cpsSubscription + " for project " + cpsProject, e); } }