code: public Subscription createSubscription(String topicId, String subscriptionId) throws Exception {
      // [START pubsub_create_pull_subscription]
      try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        // eg. projectId = "my-test-project", topicId = "my-test-topic"
        ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
        // eg. subscriptionId = "my-test-subscription"
        ProjectSubscriptionName subscriptionName =
            ProjectSubscriptionName.of(projectId, subscriptionId);
        // create a pull subscription with default acknowledgement deadline
        Subscription subscription =
            subscriptionAdminClient.createSubscription(
                subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
        return subscription;
      }
      // [END pubsub_create_pull_subscription]
    }
docs: Example of creating a pull subscription for a topic.