code: public Subscription createSubscriptionWithPushEndpoint(
        String topicId, String subscriptionId, String endpoint) throws Exception {
      // [START pubsub_create_push_subscription]
      try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
        ProjectSubscriptionName subscriptionName =
            ProjectSubscriptionName.of(projectId, subscriptionId);
  
        // eg. endpoint = "https://my-test-project.appspot.com/push"
        PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
  
        // acknowledgement deadline in seconds for the message received over the push endpoint
        int ackDeadlineInSeconds = 10;
  
        Subscription subscription =
            subscriptionAdminClient.createSubscription(
                subscriptionName, topicName, pushConfig, ackDeadlineInSeconds);
        return subscription;
      }
      // [END pubsub_create_push_subscription]
    }
docs: Example of creating a subscription with a push endpoint.