diff --git a/issues/Issue12964/Issue12964.csproj b/issues/Issue12964/Issue12964.csproj new file mode 100644 index 000000000000..bcca18ce92ad --- /dev/null +++ b/issues/Issue12964/Issue12964.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + + + + + + + + diff --git a/issues/Issue12964/Issue12964.sln b/issues/Issue12964/Issue12964.sln new file mode 100644 index 000000000000..8b9fa442d8a8 --- /dev/null +++ b/issues/Issue12964/Issue12964.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Issue12964", "Issue12964.csproj", "{41562B49-7518-423B-957D-876704FF3F85}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Cloud.PubSub.V1", "..\..\apis\Google.Cloud.PubSub.V1\Google.Cloud.PubSub.V1\Google.Cloud.PubSub.V1.csproj", "{C7261A02-B28E-4457-A661-4C61BB000B28}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {41562B49-7518-423B-957D-876704FF3F85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41562B49-7518-423B-957D-876704FF3F85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41562B49-7518-423B-957D-876704FF3F85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41562B49-7518-423B-957D-876704FF3F85}.Release|Any CPU.Build.0 = Release|Any CPU + {C7261A02-B28E-4457-A661-4C61BB000B28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7261A02-B28E-4457-A661-4C61BB000B28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7261A02-B28E-4457-A661-4C61BB000B28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7261A02-B28E-4457-A661-4C61BB000B28}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FDFAD55E-A2C5-4D70-9BB7-9A086622EC9F} + EndGlobalSection +EndGlobal diff --git a/issues/Issue12964/Program.cs b/issues/Issue12964/Program.cs new file mode 100644 index 000000000000..7ed29ec367fb --- /dev/null +++ b/issues/Issue12964/Program.cs @@ -0,0 +1,47 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"): +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Google.Cloud.PubSub.V1; +using Microsoft.Extensions.Logging; + +if (args.Length != 2) +{ + Console.WriteLine("Arguments: "); + return; +} + +var loggerFactory = LoggerFactory.Create(builder => builder.AddSimpleConsole(options => +{ + options.SingleLine = true; + options.TimestampFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z '"; + options.UseUtcTimestamp = true; +})); + +var client = new SubscriberClientBuilder +{ + SubscriptionName = new SubscriptionName(args[0], args[1]), + Logger = loggerFactory.CreateLogger("Subscriber") +}.Build(); + +var handlerLogger = loggerFactory.CreateLogger("Handler"); + +loggerFactory.CreateLogger("Timing").LogInformation("Starting subscriber"); +var task = client.StartAsync((message, cancellationToken) => +{ + handlerLogger.LogInformation("Received message with text '{text}'. MessageID='{id}'", + message.Data.ToStringUtf8(), message.MessageId); + return Task.FromResult(SubscriberClient.Reply.Ack); +}); + +await task;