public Topic GetTopic(string topicId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); TopicName topicName = TopicName.FromProjectTopic(ProjectId, topicId); return(publisher.GetTopic(topicName)); }
public static object GetTopic(string projectId, string topicId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); TopicName topicName = new TopicName(projectId, topicId); Topic topic = publisher.GetTopic(topicName); Console.WriteLine($"Topic found: {topic.TopicName.ToString()}"); return(0); }
public void TestDeleteTopic() { string topicId = "testTopicForDeleteTopic" + TestUtil.RandomName(); Run("createTopic", _projectId, topicId); Run("deleteTopic", _projectId, topicId); _tempTopicIds.Clear(); // We already deleted it. TopicName topicName = new TopicName(_projectId, topicId); Exception ex = Assert.Throws <Grpc.Core.RpcException>(() => _publisher.GetTopic(topicName)); }
/// <summary>Snippet for GetTopic</summary> public void GetTopic() { // Snippet: GetTopic(string, CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create(); // Initialize request argument(s) string topic = "projects/[PROJECT]/topics/[TOPIC]"; // Make the request Topic response = publisherServiceApiClient.GetTopic(topic); // End snippet }
/// <summary>Snippet for GetTopic</summary> public void GetTopic() { // Snippet: GetTopic(TopicName,CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create(); // Initialize request argument(s) TopicName topic = new TopicName("[PROJECT]", "[TOPIC]"); // Make the request Topic response = publisherServiceApiClient.GetTopic(topic); // End snippet }
private Topic CreateGetTopic() { PublisherServiceApiClient client = PublisherServiceApiClient.Create(); //We check if Topic exists, if no we create it and return it TopicName tn = new TopicName("programmingforthecloudbf", "BFTopic"); try { return(client.GetTopic(tn)); } catch { return(client.CreateTopic(tn)); } }
/// <summary>Snippet for GetTopic</summary> public void GetTopic_RequestObject() { // Snippet: GetTopic(GetTopicRequest,CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create(); // Initialize request argument(s) GetTopicRequest request = new GetTopicRequest { TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"), }; // Make the request Topic response = publisherServiceApiClient.GetTopic(request); // End snippet }
private Topic CreateGetTopic() { PublisherServiceApiClient client = PublisherServiceApiClient.Create(); //We check if Topic exists, if no we create it and return it TopicName tn = new TopicName("justinportellimsd63b", "HomeAssignmentTopic"); try { return(client.GetTopic(tn)); } catch { return(client.CreateTopic(tn)); } }
public TopicName CreateTopic() { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); var topicName = new TopicName(_projectId, "topicId"); try { return(publisher.CreateTopic(topicName).TopicName); } catch (RpcException e) when(e.Status.StatusCode == StatusCode.AlreadyExists) { return(publisher.GetTopic(topicName).TopicName); } }
private Topic CreateGetTopic() { PublisherServiceApiClient client = PublisherServiceApiClient.Create(); //We check if Topic exists, if no we create it and return it TopicName tn = new TopicName("jurgen-cloud-project", "pftc"); try { return(client.GetTopic(tn)); } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); return(client.CreateTopic(tn)); } }
//Creates or gets a topic. private Topic CreateGetTopic() { PublisherServiceApiClient client = PublisherServiceApiClient.Create(); TopicName tn = new TopicName("pfc-home", topicName); try { //Get topic if already exists return(client.GetTopic(tn)); } catch { //Create new topic if it does not exist. return(client.CreateTopic(tn)); } }
private Topic GetOrCreateTopic(string name) { PublisherServiceApiClient client = PublisherServiceApiClient.Create(); try { return(client.GetTopic(new TopicName("programming-for-the-cloud", name))); } catch (RpcException ex) { if (ex.Status.StatusCode == StatusCode.NotFound) { return(client.CreateTopic(new TopicName("programming-for-the-cloud", name))); } } return(null); }
public async Task <int> PublishAvroMessagesAsync(string projectId, string topicId, IEnumerable <AvroUtilities.State> messageStates) { TopicName topicName = TopicName.FromProjectTopic(projectId, topicId); PublisherClient publisher = await PublisherClient.CreateAsync(topicName); PublisherServiceApiClient publishApi = PublisherServiceApiClient.Create(); var topic = publishApi.GetTopic(topicName); int publishedMessageCount = 0; var publishTasks = messageStates.Select(async state => { try { string messageId = null; switch (topic.SchemaSettings.Encoding) { case Encoding.Binary: using (var ms = new MemoryStream()) { var encoder = new BinaryEncoder(ms); var writer = new SpecificDefaultWriter(state.Schema); writer.Write(state, encoder); messageId = await publisher.PublishAsync(ms.ToArray()); } break; case Encoding.Json: var jsonMessage = AvroUtilities.StateUtils.StateToJsonString(state); messageId = await publisher.PublishAsync(jsonMessage); break; } Console.WriteLine($"Published message {messageId}"); Interlocked.Increment(ref publishedMessageCount); } catch (Exception exception) { Console.WriteLine($"An error ocurred when publishing message {state}: {exception.Message}"); } }); await Task.WhenAll(publishTasks); return(publishedMessageCount); }
public async Task <int> PublishProtoMessagesAsync(string projectId, string topicId, IEnumerable <Utilities.State> messageStates) { TopicName topicName = TopicName.FromProjectTopic(projectId, topicId); PublisherClient publisher = await PublisherClient.CreateAsync(topicName); PublisherServiceApiClient publishApi = PublisherServiceApiClient.Create(); var topic = publishApi.GetTopic(topicName); int publishedMessageCount = 0; var publishTasks = messageStates.Select(async state => { try { string messageId = null; switch (topic.SchemaSettings.Encoding) { case Encoding.Binary: var binaryMessage = state.ToByteString(); messageId = await publisher.PublishAsync(binaryMessage); break; case Encoding.Json: var jsonMessage = JsonFormatter.Default.Format(state); messageId = await publisher.PublishAsync(jsonMessage); break; } Console.WriteLine($"Published message {messageId}"); Interlocked.Increment(ref publishedMessageCount); } catch (Exception exception) { Console.WriteLine($"An error ocurred when publishing message {state}: {exception.Message}"); } }); await Task.WhenAll(publishTasks); return(publishedMessageCount); }