public override void Dispose()
        {
            var subscriber = new SubscriberServiceApiClientBuilder {
                EmulatorDetection = EmulatorDetection.EmulatorOrProduction
            }.Build();
            var subscriptions = subscriber.ListSubscriptions(new ProjectName(ProjectId))
                                .Where(sub => sub.SubscriptionName.SubscriptionId.StartsWith(SubscriptionPrefix))
                                .ToList();

            foreach (var sub in subscriptions)
            {
                subscriber.DeleteSubscription(sub.SubscriptionName);
            }

            var publisher = new PublisherServiceApiClientBuilder {
                EmulatorDetection = EmulatorDetection.EmulatorOrProduction
            }.Build();
            var topics = publisher.ListTopics(new ProjectName(ProjectId))
                         .Where(topic => topic.TopicName.TopicId.StartsWith(TopicPrefix))
                         .ToList();

            foreach (var topic in topics)
            {
                publisher.DeleteTopic(topic.TopicName);
            }
        }
Esempio n. 2
0
        public void Emulator()
        {
            // Sample: Emulator
            // [START pubsub_use_emulator]
            // For example, "localhost:8615"
            string emulatorHostAndPort = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");

            PublisherServiceApiClient client = new PublisherServiceApiClientBuilder
            {
                Endpoint           = emulatorHostAndPort,
                ChannelCredentials = ChannelCredentials.Insecure
            }.Build();

            client.CreateTopic(new TopicName("project", "topic"));
            foreach (var topic in client.ListTopics(new ProjectName("project")))
            {
                Console.WriteLine(topic.Name);
            }
            // [END pubsub_use_emulator]
            // End sample
        }