Beispiel #1
0
        private static async Task Subscribe(SubscriberClient client, string projectId, string topicId)
        {
            string topicName        = TopicTemplate.Expand(projectId, topicId);
            var    subscriptionName = SubscriptionTemplate.Expand(projectId, "sub-" + Guid.NewGuid());
            var    subscription     = await client.CreateSubscriptionAsync(subscriptionName, topicName, null, 10);

            try
            {
                bool keepGoing = true;
                while (keepGoing)
                {
                    var pullResponse = await client.PullAsync(subscription.Name, false, 10);

                    await client.AcknowledgeAsync(subscription.Name, pullResponse.ReceivedMessages.Select(resp => resp.AckId));

                    foreach (var message in pullResponse.ReceivedMessages)
                    {
                        var text = message.Message.Data.ToStringUtf8();
                        if (text == "QUIT")
                        {
                            keepGoing = false; // Stop *after* the end of this set of messages
                        }
                        Console.WriteLine(text);
                    }
                }
            }
            finally
            {
                await client.DeleteSubscriptionAsync(subscription.Name);
            }
        }
Beispiel #2
0
        private static Task ListTopics(PublisherClient client, string projectId)
        {
            var topics = client.ListTopicsAsync(ProjectTemplate.Expand(projectId));

            Console.WriteLine($"Topics in {projectId}:");
            return(topics.ForEachAsync(topic => Console.WriteLine($"  {topic.Name}")));
        }
Beispiel #3
0
        public void Expand_Valid(string templateText, string[] resourceIds, string expectedResult)
        {
            var template = new PathTemplate(templateText);
            var actual   = template.Expand(resourceIds);

            Assert.Equal(expectedResult, actual);
        }
 /// <summary>
 /// Creates a project resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <returns>The full project resource name.</returns>
 public static string GetProjectName(string projectId) => ProjectTemplate.Expand(projectId);
Beispiel #5
0
        public void Expand_Invalid(string templateText, string[] resourceIds)
        {
            var template = new PathTemplate(templateText);

            Assert.Throws <ArgumentException>(() => template.Expand(resourceIds));
        }
Beispiel #6
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId);
Beispiel #7
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceConfigId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, UptimeCheckConfigId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, MetricDescriptorId);
 public void Expand_Invalid(string templateText, string[] resourceIds)
 {
     var template = new PathTemplate(templateText);
     Assert.Throws<ArgumentException>(() => template.Expand(resourceIds));
 }
 /// <summary>
 /// Creates a log resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <param name="logId">The log ID.</param>
 /// <returns>The full log resource name.</returns>
 public static string FormatLogName(string projectId, string logId) => LogTemplate.Expand(projectId, logId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ResultId);
Beispiel #13
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(OrganizationId);
Beispiel #14
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceId, AppProfileId);
Beispiel #15
0
 private static Task CreateTopic(PublisherClient client, string projectId, string topicId)
 {
     return(client.CreateTopicAsync(TopicTemplate.Expand(projectId, topicId)));
 }
 /// <summary>
 /// Creates a topic resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <param name="topicId">The topic ID.</param>
 /// <returns>The full topic resource name.</returns>
 public static string GetTopicName(string projectId, string topicId) => TopicTemplate.Expand(projectId, topicId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(UserId);
 /// <summary>
 /// Creates a sink resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <param name="sinkId">The sink ID.</param>
 /// <returns>The full sink resource name.</returns>
 public static string FormatSinkName(string projectId, string sinkId) => SinkTemplate.Expand(projectId, sinkId);
 public void Expand_Valid(string templateText, string[] resourceIds, string expectedResult)
 {
     var template = new PathTemplate(templateText);
     var actual = template.Expand(resourceIds);
     Assert.Equal(expectedResult, actual);
 }
 /// <summary>
 /// Creates a group resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <param name="groupId">The group ID.</param>
 /// <returns>
 /// The full group resource name.
 /// </returns>
 public static string FormatGroupName(string projectId, string groupId) => GroupTemplate.Expand(projectId, groupId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, MonitoredResourceDescriptorId);
 /// <summary>
 /// Creates a operation_path resource name from its component IDs.
 /// </summary>
 /// <param name="operationPathId">The operationPath ID.</param>
 /// <returns>
 /// The full operation_path resource name.
 /// </returns>
 public static string FormatOperationPathName(string operationPathId) => OperationPathTemplate.Expand(operationPathId);
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, SubscriptionId);
Beispiel #24
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, DatabaseId, DocumentId, AnyPathId);
Beispiel #25
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceId, ClusterId);
Beispiel #26
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(BillingAccountId);
Beispiel #27
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceId, DatabaseId);
 /// <summary>
 /// Creates a metric resource name from its component IDs.
 /// </summary>
 /// <param name="projectId">The project ID.</param>
 /// <param name="metricId">The metric ID.</param>
 /// <returns>The full metric resource name.</returns>
 public static string FormatMetricName(string projectId, string metricId) => MetricTemplate.Expand(projectId, metricId);