public async Task Initialize() { try { _publisher = await PublisherClient.CreateAsync(_customEndpoint); } catch (Exception e) { ReportErrorAndRethrow(e, "CreateAsync", GoogleErrorCode.Initializing); } bool didCreate = false; try { _topic = await _publisher.CreateTopicAsync(TopicName); didCreate = true; } catch (RpcException e) { if (e.Status.StatusCode != StatusCode.AlreadyExists) { ReportErrorAndRethrow(e, "CreateTopicAsync", GoogleErrorCode.Initializing); } _topic = await _publisher.GetTopicAsync(TopicName); } _logger.LogInformation((int)GoogleErrorCode.Initializing, "{Verb} Google PubSub Topic {TopicId}", (didCreate ? "Created" : "Attached to"), TopicName.TopicId); didCreate = false; try { _subscriber = await SubscriberClient.CreateAsync(_customEndpoint); _subscription = await _subscriber.CreateSubscriptionAsync(SubscriptionName, TopicName, pushConfig : null, ackDeadlineSeconds : _deadline.HasValue?(int)_deadline.Value.TotalSeconds : 60); didCreate = true; } catch (RpcException e) { if (e.Status.StatusCode != StatusCode.AlreadyExists) { ReportErrorAndRethrow(e, "CreateSubscriptionAsync", GoogleErrorCode.Initializing); } _subscription = await _subscriber.GetSubscriptionAsync(SubscriptionName); } _logger.LogInformation( (int)GoogleErrorCode.Initializing, "{Verb} Google PubSub Subscription {SubscriptionId} to Topic {TopicId}", (didCreate ? "Created" : "Attached to"), SubscriptionName.SubscriptionId, TopicName.TopicId); }
public async Task GetTopicAsync() { // Snippet: GetTopicAsync(string,CallSettings) // Additional: GetTopicAsync(string,CancellationToken) // Create client PublisherClient publisherClient = PublisherClient.Create(); // Initialize request argument(s) string formattedTopic = PublisherClient.FormatTopicName("[PROJECT]", "[TOPIC]"); // Make the request Topic response = await publisherClient.GetTopicAsync(formattedTopic); // End snippet }
public async Task GetTopicAsync() { // Snippet: GetTopicAsync(TopicName,CallSettings) // Additional: GetTopicAsync(TopicName,CancellationToken) // Create client PublisherClient publisherClient = await PublisherClient.CreateAsync(); // Initialize request argument(s) TopicName topic = new TopicName("[PROJECT]", "[TOPIC]"); // Make the request Topic response = await publisherClient.GetTopicAsync(topic); // End snippet }
public async Task GetTopicAsync_RequestObject() { // Snippet: GetTopicAsync(GetTopicRequest,CallSettings) // Create client PublisherClient publisherClient = await PublisherClient.CreateAsync(); // Initialize request argument(s) GetTopicRequest request = new GetTopicRequest { TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"), }; // Make the request Topic response = await publisherClient.GetTopicAsync(request); // End snippet }