public async Task CreateTopicAsync() { // <CreateTopicAsync> PublisherClient client = PublisherClient.Create(); // Alternative: use a known topic resource name // projects/{PROJECT_ID}/topics/{TOPIC_ID} string topicName = PublisherClient.GetTopicName("{PROJECT_ID}", "{TOPIC_ID}"); Topic topic = await client.CreateTopicAsync(topicName); Console.WriteLine($"Created {topic.Name}"); // </CreateTopicAsync> }
public async Task CreateSubscriptionAsync() { // <CreateSubscriptionAsync> SubscriberClient client = SubscriberClient.Create(); // Alternative: use an existing subscription resource name: // projects/{PROJECT_ID}/subscriptions/{SUBSCRIPTION_ID} // Similarly for the topic name: // projects/{PROJECT_ID}/topics/{TOPIC_ID} string subscriptionName = SubscriberClient.GetSubscriptionName("{PROJECT_ID}", "{SUBSCRIPTION_ID}"); string topicName = PublisherClient.GetTopicName("{PROJECT_ID}", "{TOPIC_ID}"); Subscription subscription = await client.CreateSubscriptionAsync( subscriptionName, topicName, pushConfig : null, ackDeadlineSeconds : 30); Console.WriteLine($"Created {subscription.Name} subscribed to {subscription.Topic}"); // </CreateSubscriptionAsync> }