public void DeleteTopic(string topicId, PublisherClient publisher) { // [START delete_topic] TopicName topicName = new TopicName(_projectId, topicId); publisher.DeleteTopic(topicName); // [END delete_topic] }
public void Overview() { string projectId = _fixture.ProjectId; string topicId = _fixture.CreateTopicId(); string subscriptionId = _fixture.CreateSubscriptionId(); // Sample: Overview // First create a topic. PublisherClient publisher = PublisherClient.Create(); TopicName topicName = new TopicName(projectId, topicId); publisher.CreateTopic(topicName); // Subscribe to the topic. SubscriberClient subscriber = SubscriberClient.Create(); SubscriptionName subscriptionName = new SubscriptionName(projectId, subscriptionId); subscriber.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 60); // Publish a message to the topic. PubsubMessage message = new PubsubMessage { // The data is any arbitrary ByteString. Here, we're using text. Data = ByteString.CopyFromUtf8("Hello, Pubsub"), // The attributes provide metadata in a string-to-string dictionary. Attributes = { { "description", "Simple text message" } } }; publisher.Publish(topicName, new[] { message }); // Pull messages from the subscription. We're returning immediately, whether or not there // are messages; in other cases you'll want to allow the call to wait until a message arrives. PullResponse response = subscriber.Pull(subscriptionName, returnImmediately: true, maxMessages: 10); foreach (ReceivedMessage received in response.ReceivedMessages) { PubsubMessage msg = received.Message; Console.WriteLine($"Received message {msg.MessageId} published at {msg.PublishTime.ToDateTime()}"); Console.WriteLine($"Text: '{msg.Data.ToStringUtf8()}'"); } // Acknowledge that we've received the messages. If we don't do this within 60 seconds (as specified // when we created the subscription) we'll receive the messages again when we next pull. subscriber.Acknowledge(subscriptionName, response.ReceivedMessages.Select(m => m.AckId)); // Tidy up by deleting the subscription and the topic. subscriber.DeleteSubscription(subscriptionName); publisher.DeleteTopic(topicName); // End sample Assert.Equal(1, response.ReceivedMessages.Count); Assert.Equal("Hello, Pubsub", response.ReceivedMessages[0].Message.Data.ToStringUtf8()); Assert.Equal("Simple text message", response.ReceivedMessages[0].Message.Attributes["description"]); }
public async Task SimpleOverview() { string projectId = _fixture.ProjectId; string topicId = _fixture.CreateTopicId(); string subscriptionId = _fixture.CreateSubscriptionId(); // Sample: SimpleOverview // First create a topic. PublisherClient publisher = await PublisherClient.CreateAsync(); TopicName topicName = new TopicName(projectId, topicId); publisher.CreateTopic(topicName); // Subscribe to the topic. SubscriberClient subscriber = await SubscriberClient.CreateAsync(); SubscriptionName subscriptionName = new SubscriptionName(projectId, subscriptionId); subscriber.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 60); // Publish a message to the topic using SimplePublisher. SimplePublisher simplePublisher = await SimplePublisher.CreateAsync(topicName); // PublishAsync() has various overloads. Here we're using the string overload. string messageId = await simplePublisher.PublishAsync("Hello, Pubsub"); // SimplePublisher should be shutdown after use. // The TimeSpan specifies for how long to attempt to publish locally queued messages. await simplePublisher.ShutdownAsync(TimeSpan.FromSeconds(15)); // Pull messages from the subscription using SimpleSubscriber. SimpleSubscriber simpleSubscriber = await SimpleSubscriber.CreateAsync(subscriptionName); List <PubsubMessage> receivedMessages = new List <PubsubMessage>(); // Start the subscriber listening for messages. await simpleSubscriber.StartAsync((msg, cancellationToken) => { receivedMessages.Add(msg); Console.WriteLine($"Received message {msg.MessageId} published at {msg.PublishTime.ToDateTime()}"); Console.WriteLine($"Text: '{msg.Data.ToStringUtf8()}'"); // Stop this subscriber after one message is received. // This is non-blocking, and the returned Task may be awaited. simpleSubscriber.StopAsync(TimeSpan.FromSeconds(15)); // Return Reply.Ack to indicate this message has been handled. return(Task.FromResult(SimpleSubscriber.Reply.Ack)); }); // Tidy up by deleting the subscription and the topic. subscriber.DeleteSubscription(subscriptionName); publisher.DeleteTopic(topicName); // End sample Assert.Equal(1, receivedMessages.Count); Assert.Equal("Hello, Pubsub", receivedMessages[0].Data.ToStringUtf8()); }
public static object DeleteTopic(string projectId, string topicId) { PublisherClient publisher = PublisherClient.Create(); // [START delete_topic] TopicName topicName = new TopicName(projectId, topicId); publisher.DeleteTopic(topicName); // [END delete_topic] Console.WriteLine("Topic deleted."); return(0); }
public void DeleteTopic() { // Snippet: DeleteTopic(TopicName,CallSettings) // Create client PublisherClient publisherClient = PublisherClient.Create(); // Initialize request argument(s) TopicName topic = new TopicName("[PROJECT]", "[TOPIC]"); // Make the request publisherClient.DeleteTopic(topic); // End snippet }
public void DeleteTopic() { // Snippet: DeleteTopic(string,CallSettings) // Create client PublisherClient publisherClient = PublisherClient.Create(); // Initialize request argument(s) string formattedTopic = PublisherClient.FormatTopicName("[PROJECT]", "[TOPIC]"); // Make the request publisherClient.DeleteTopic(formattedTopic); // End snippet }
public void DeleteTopic_RequestObject() { // Snippet: DeleteTopic(DeleteTopicRequest,CallSettings) // Create client PublisherClient publisherClient = PublisherClient.Create(); // Initialize request argument(s) DeleteTopicRequest request = new DeleteTopicRequest { TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"), }; // Make the request publisherClient.DeleteTopic(request); // End snippet }
public void DeleteTopic() { string projectId = _fixture.ProjectId; string topicId = _fixture.CreateTopicId(); PublisherClient.Create().CreateTopic(new TopicName(projectId, topicId)); // Snippet: DeleteTopic(TopicName,*) PublisherClient client = PublisherClient.Create(); TopicName topicName = new TopicName(projectId, topicId); client.DeleteTopic(topicName); Console.WriteLine($"Deleted {topicName}"); // End snippet }
public void DeleteTopic() { string projectId = _fixture.ProjectId; string topicId = _fixture.CreateTopicId(); PublisherClient.Create().CreateTopic(PublisherClient.FormatTopicName(projectId, topicId)); // Snippet: DeleteTopic PublisherClient client = PublisherClient.Create(); // Alternative: use a known topic resource name // "projects/{PROJECT_ID}/topics/{TOPIC_ID}" string topicName = PublisherClient.FormatTopicName(projectId, topicId); client.DeleteTopic(topicName); Console.WriteLine($"Deleted {topicName}"); // End snippet }
public void DeleteTopic(string topicId, PublisherClient publisher) { // [START delete_topic] string topicName = PublisherClient.FormatTopicName(_projectId, topicId); publisher.DeleteTopic(topicName); // [END delete_topic] }