Creates a subscription to a given topic. See the <a
href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource name
rules</a>. If the subscription already exists, returns `ALREADY_EXISTS`. If the
corresponding topic doesn't exist, returns `NOT_FOUND`.
If the name is not provided in the request, the server will assign a random name for this
subscription on the same project as the topic, conforming to the [resource name
format](https://cloud.google.com/pubsub/docs/admin#resource_names). The generated name is
populated in the returned Subscription object. Note that for REST API requests, you must
specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Subscription request = Subscription.newBuilder()
.setName(name.toString())
.setTopic(topic.toString())
.build();
ApiFuture<Subscription> future = subscriptionAdminClient.createSubscriptionCallable().futureCall(request);
// Do something
Subscription response = future.get();
}