public static SimplePublisher GetSimplePublisher(string projectId, string topicId) { // [START publish_message] PublisherClient publisherClient = PublisherClient.Create(); SimplePublisher publisher = SimplePublisher.Create( new TopicName(projectId, topicId), new[] { publisherClient }); // [END publish_message] return(publisher); }
/// <summary> /// Create a SimplePublisher with custom batch thresholds. /// </summary> public static SimplePublisher GetCustomPublisher(string projectId, string topicId) { // [START pubsub_publisher_batch_settings] PublisherClient publisherClient = PublisherClient.Create(); SimplePublisher publisher = SimplePublisher.Create( new TopicName(projectId, topicId), new[] { publisherClient }, new SimplePublisher.Settings() { BatchingSettings = new Google.Api.Gax.BatchingSettings( elementCountThreshold: 100, byteCountThreshold: 10240, delayThreshold: TimeSpan.FromSeconds(3)) }); // [END pubsub_publisher_batch_settings] return(publisher); }
private static SimplePublisher GetGoogleBusWriter(Microsoft.Azure.WebJobs.ExecutionContext context) { string topicId = ConfigurationManager.AppSettings["GoogleTopicId"]; string projectId = ConfigurationManager.AppSettings["GoogleProjectId"]; //Google credential expected to be a local file called googleCredential.json, copied to output TopicName topicName = new TopicName(projectId, topicId); string credentialPath = Path.Combine(context.FunctionDirectory, "..\\googleCredential.json"); GoogleCredential credential = ReadGoogleCredentialFile(credentialPath); credential = credential.CreateScoped(PublisherClient.DefaultScopes); ClientCreationSettings clientSettings = new ClientCreationSettings(credentials: credential.ToChannelCredentials()); Channel channel = new Channel(PublisherClient.DefaultEndpoint.Host, PublisherClient.DefaultEndpoint.Port, credential.ToChannelCredentials()); PublisherClient client = PublisherClient.Create(channel); return(SimplePublisher.Create(topicName, new[] { client })); }