示例#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);
            }
        }
示例#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}")));
        }
示例#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);
示例#5
0
        public void Expand_Invalid(string templateText, string[] resourceIds)
        {
            var template = new PathTemplate(templateText);

            Assert.Throws <ArgumentException>(() => template.Expand(resourceIds));
        }
示例#6
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId);
示例#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);
示例#10
0
 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);
示例#13
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(OrganizationId);
示例#14
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceId, AppProfileId);
示例#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);
示例#17
0
 /// <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);
示例#19
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 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);
示例#23
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, SubscriptionId);
示例#24
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, DatabaseId, DocumentId, AnyPathId);
示例#25
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(ProjectId, InstanceId, ClusterId);
示例#26
0
 /// <inheritdoc />
 public override string ToString() => s_template.Expand(BillingAccountId);
示例#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);