Esempio n. 1
0
        private void LoadTopics()
        {
            var topics = _serviceApiClient.ListTopics(new ProjectName(_options.ProjectId));

            foreach (var t in topics)
            {
                _publishers.Add(t.TopicName.TopicId, null);
            }
        }
        public static int Main(string[] args)
        {
            // Read projectId from args
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: Project ID must be passed as first argument.");
                Console.WriteLine();
                return(1);
            }
            string projectId = args[0];

            // Create client
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();

            // Initialize request argument(s)
            ProjectName project = new ProjectName(projectId);

            // Call API method
            PagedEnumerable <ListTopicsResponse, Topic> pagedResponse = client.ListTopics(project);

            // Show the result
            foreach (var item in pagedResponse)
            {
                Console.WriteLine(item);
            }

            // Success
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
Esempio n. 3
0
        public static IEnumerable <Topic> ListProjectTopics(string projectId)
        {
            PublisherServiceApiClient publisher = PublisherServiceApiClient.Create();
            ProjectName         projectName     = ProjectName.FromProject(projectId);
            IEnumerable <Topic> topics          = publisher.ListTopics(projectName);

            return(topics);
        }
Esempio n. 4
0
        public static object ListProjectTopics(PublisherServiceApiClient publisher, string projectId)
        {
            // [START pubsub_list_topics]
            ProjectName         projectName = new ProjectName(projectId);
            IEnumerable <Topic> topics      = publisher.ListTopics(projectName);

            foreach (Topic topic in topics)
            {
                Console.WriteLine($"{topic.Name}");
            }
            // [END pubsub_list_topics]
            return(0);
        }
Esempio n. 5
0
        public bool IsRunning()
        {
            try
            {
                _serviceApiClient.ListTopics(new ProjectName(_options.ProjectId));
            }
            catch (Exception)
            {
                return(false);
            }

            return(_running);
        }
        public void AllResources()
        {
            string projectId = _fixture.ProjectId;
            // Sample: AllResources
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();
            ProjectName projectName          = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageSize: 3);

            foreach (Topic topic in topics)
            {
                Console.WriteLine(topic.Name);
            }
            // End sample
        }
Esempio n. 7
0
        private async Task Run()
        {
// 1. no basic auth, with usercredentials
// need to set export http_proxy=http://localhost:3128 for Pubsub
// need to set ProxySupportedHttpClientFactory for GCS and oauth2

//  auth Y
//  gcs Y
//  pubsub Y


// 1638323879.659    693 192.168.9.1 TCP_TUNNEL/200 45147 CONNECT storage.googleapis.com:443 - HIER_DIRECT/172.253.63.128 -
// 1638323879.659    884 192.168.9.1 TCP_TUNNEL/200 7349 CONNECT oauth2.googleapis.com:443 - HIER_DIRECT/142.251.45.10 -
// 1638323879.659    372 192.168.9.1 TCP_TUNNEL/200 7878 CONNECT pubsub.googleapis.com:443 - HIER_DIRECT/172.217.13.234 -


// 2. no basic auth, with service account credentials
// export GOOGLE_APPLICATION_CREDENTIALS=/path/to/svc_account.json
//  auth N
//  gcs N
//  pubsub Y

// 3. no basicauth, with ServiceAccountCredential
            //var stream = new FileStream("/path/to/svc_account.json", FileMode.Open, FileAccess.Read);
            //ServiceAccountCredential sacredential = ServiceAccountCredential.FromServiceAccountData(stream);
            GoogleCredential credential = await GoogleCredential.GetApplicationDefaultAsync();

            credential = credential.CreateWithHttpClientFactory(new ProxySupportedHttpClientFactory());

            StorageService service = new StorageService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = StorageClientImpl.ApplicationName,
                HttpClientFactory     = new ProxySupportedHttpClientFactory(),
            });
            var client = new StorageClientImpl(service, null);

            foreach (var b in client.ListBuckets(projectID))
            {
                Console.WriteLine(b.Name);
            }

            PublisherServiceApiClient publisher = PublisherServiceApiClient.Create();
            ProjectName projectName             = ProjectName.FromProject(projectID);

            foreach (Topic t in publisher.ListTopics(projectName))
            {
                Console.WriteLine(t.Name);
            }
        }
        public void ListTopics()
        {
            string projectId = _fixture.ProjectId;

            // Snippet: ListTopics(*,*,*,*)
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();

            ProjectName projectName = new ProjectName(projectId);

            foreach (Topic topic in client.ListTopics(projectName))
            {
                Console.WriteLine(topic.Name);
            }
            // End snippet
        }
Esempio n. 9
0
        public void Emulator()
        {
            // Sample: Emulator
            // For example, "localhost:8615"
            string emulatorHostAndPort = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");

            Channel channel = new Channel(emulatorHostAndPort, ChannelCredentials.Insecure);
            PublisherServiceApiClient client = PublisherServiceApiClient.Create(channel);

            client.CreateTopic(new TopicName("project", "topic"));
            foreach (var topic in client.ListTopics(new ProjectName("project")))
            {
                Console.WriteLine(topic.Name);
            }
            // End sample
        }
Esempio n. 10
0
        /// <summary>Snippet for ListTopics</summary>
        public void ListTopicsRequestObject()
        {
            // Snippet: ListTopics(ListTopicsRequest, CallSettings)
            // Create client
            PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create();
            // Initialize request argument(s)
            ListTopicsRequest request = new ListTopicsRequest
            {
                ProjectAsProjectName = ProjectName.FromProject("[PROJECT]"),
            };
            // Make the request
            PagedEnumerable <ListTopicsResponse, Topic> response = publisherServiceApiClient.ListTopics(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (Topic item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (ListTopicsResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Topic item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int          pageSize   = 10;
            Page <Topic> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Topic item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
        public void ReadPage()
        {
            string projectId            = _fixture.ProjectId;
            string pageTokenFromRequest = "";

            // Sample: ReadPage
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();
            ProjectName projectName          = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics = client.ListTopics(projectName, pageTokenFromRequest);

            Page <Topic> page = topics.ReadPage(3);

            // In a web application, this would be a matter of including the topics in the web page.
            foreach (Topic topic in page)
            {
                Console.WriteLine(topic.Name);
            }
            // ... and embedding the next page token into a "next page" link.
            Console.WriteLine($"Next page token: {page.NextPageToken}");
            // End sample
        }
Esempio n. 12
0
        public IEnumerable <string> ListTopics([FromBody] CreatTopicModel attr)
        {
            List <string> retorno = new List <string>();

            try
            {
                // List all topics for the project
                PublisherServiceApiClient publisher = PublisherServiceApiClient.Create();
                var topics = publisher.ListTopics(new ProjectName(attr.projectId));

                foreach (Topic topic1 in topics)
                {
                    retorno.Add(topic1.Name);
                }
            }
            catch (Exception ex)
            {
                retorno.Add(ex.Message + "-------" + ex.StackTrace);
            }
            return(retorno);
        }
        public void SingleResponse()
        {
            string projectId = _fixture.ProjectId;
            // Sample: SingleResponse
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();
            ProjectName projectName          = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics         = client.ListTopics(projectName, pageSize: 3);
            IEnumerable <ListTopicsResponse>            topicResponses = topics.AsRawResponses();
            // This is just the regular LINQ First() method. The sequence of pages will never be empty,
            // but the page may have no resources.
            ListTopicsResponse firstResponse = topicResponses.First();

            Console.WriteLine("Topics in response:");
            foreach (Topic topic in firstResponse.Topics)
            {
                Console.WriteLine($"  {topic.Name}");
            }
            // If you were processing items in batches, you might wish to store this
            // in order to recover from failures. The page token can be passed into the ListTopics method.
            Console.WriteLine($"Next page token: {firstResponse.NextPageToken}");
            // End sample
        }
        public void Responses()
        {
            string projectId = _fixture.ProjectId;
            // Sample: Responses
            PublisherServiceApiClient client = PublisherServiceApiClient.Create();
            ProjectName projectName          = new ProjectName(projectId);
            PagedEnumerable <ListTopicsResponse, Topic> topics         = client.ListTopics(projectName, pageSize: 3);
            IEnumerable <ListTopicsResponse>            topicResponses = topics.AsRawResponses();

            foreach (ListTopicsResponse response in topicResponses)
            {
                Console.WriteLine("Topics in response:");
                foreach (Topic topic in response.Topics)
                {
                    Console.WriteLine($"  {topic.Name}");
                }
                // If you were processing items in batches, you might wish to store this
                // in order to recover from failures. The page token can be passed into the ListTopics method.
                Console.WriteLine($"Next page token: {response.NextPageToken}");
            }
            // End sample
        }