Vincent
1
Azure Service Bus์ console app์ผ๋ก ๋ฉ์ธ์ง ํ๋ก์ธ์ฑ์ ํ๊ณ ์์๋๋ฐ ์ด๋ฒ์ Azure Function Trigger๋ก ๋ณ๊ฒฝํ๊ณ ์์ต๋๋ค.
๋ณ๊ฒฝํ๋ฉด์ ๋๋ ๊ฒ์ Azure Function์ด .NET 5๋ฅผ ์ง์ํ์ง ์๋๋ค๋ ๊ฒ์ธ๋ฐ์.
๋๋ถ์ ์ ๊ฐ ์ฌ์ฉํ๋ ์์ค์ฝ๋๋ค๋ C# 9.0 โ C# 8.0์ผ๋ก ๋ค ๊ณ ์น๊ณ โฆ์ฌ์ฉํ๋ Nuget Package๋ ๋ค์ด๊ทธ๋ ์ด๋๋ฅผ ํ๊ณ ์์ต๋๋ค. Microsoft.Extensions.Http, Microsoft.Extensions.DependencyInjection ๋ฑ๋ฑ์ด ์๋๋ฐ์.
๊ถ๊ธํ ๊ฒ์ .NET 5๋ฅผ ์ข
์์ฑ์ผ๋ก ๊ฐ์ง์ง ์์ Nuget Package ๋ค๋ ๋ค์ด๊ทธ๋ ์ด๋๋ฅผ ํด์ผํ๋ค๋ ์ ์
๋๋ค. ๋ฌธ์ ๋๋ ํจํค์ง๊ฐ System.ComponentModel.Annotations 5.0.0 ์ธ๋ฐ์โฆ ์ ์ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๋ง๋์ ๋ถ๋ค์ ๊ตฌ๊ธ๋ง์ ํตํด ๋ง๋ ์ ์์์ต๋๋ค. System.ComponentModel.Annotatoins Version=5.0.0.0 (doesn't exist) ยท Issue #7221 ยท Azure/azure-functions-host ยท GitHub
์๋ฌด๋๋ ์์ง ํด๊ฒฐ์ด ๋์ง ์์ ๋ฏ ํฉ๋๋ค.
System.ComponentModel.Annotations 5.0.0 ์ ๋ฒ์ ์ 4.7๋ก ๋ฎ์ถ๋ ค๊ณ ํ๋ฉด Visual Studio 2019์์ ์๋ ์ด๋ฏธ์ง์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋๋ฐ์.

์ฌ๊ธฐ์ ์ง์ ์ฐธ์กฐํ๋ผ๋ ๋ง์ DLL ํํ๋ก ํจํค์ง๋ฅผ ๋ฐ์์ ์๋์ผ๋ก ํ๋ก์ ํธ์ ์ฐ๊ฒฐํด์ฃผ๋ผ๋ ๋ง์ผ๊น์?
Azure Function ์ฌ์ฉ ๊ฒฝํ ์์ผ์ ๋ถ๋ค์ ์กฐ์ธ์ ๊ตฌํฉ๋๋ค.
Vincent
2
์๋ตํฉ๋๋ค.
๋ค๋ฅธ ์ปค๋ฎค๋ํฐ์์ ํํธ๋ฅผ ์ฃผ์ ๋ถ์ด .NET 5๋ก ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ๋ค ํ์
์ ๋ฌธ์๋ฅผ ๋จ๊น๋๋ค.
์ด๊ฒ MSDN์ ํ๊ธ๋ก ๋ณด๋ ์ต๊ด์ด ์๋ค๋ณด๋ ์ด๋ฐ ๊ฑธ ์บ์น๋ฅผ ๋ชปํ๋ค์.
์ด ๋ฌธ์์ ๋ณด๋ฉด ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด VS2019์์๋ .NET 5 Azure Function์ ๊ฐ๋ฐํ ์ ์๋ค๊ณ ๋์ต๋๋ค.
ํ์ง๋ง ์์ด ๋ฌธ์๋ ๋ค์๊ณผ ๊ฐ์ด ๋์์์ต๋๋ค.

๊ทธ๋ฆฌ๊ณ VS2019 16.10 ๋ฒ์ ์ ์ถ์๋์ง 1๋ฌ์ด ์ง๋์ง ์์์ต๋๋คโฆ
์ ๋ 4์ ๋ง์ 16.9๋ฒ์ ๊น์ง ์ฐ๊ณ ์์๋๋ฐ ์
๋ฐ์ดํธ๋ฅผ ์์ฃผ ์ํ๋๋ ์ง์ ํ๋ก์ ํธ ํ
ํ๋ฆฟ์ด ์ ์๋ค์.
์๋ฌดํผ ์ด ๋ฌธ์๋๋กโฆVS2019๋ฅผ 16.10.3 ๋ฒ์ ์ผ๋ก ์
๋ฐ์ดํธํ๋ ์๋ ๊ทธ๋ฆผ์ฒ๋ผ .NET 5๊ฐ Azure Function ํ๋ก์ ํธ ํ
ํ๋ฆฟ์ ์ถ๋ ฅ๋ฉ๋๋ค. ๊ฒฉ๋ฆฌ๋ ๋ฌด์จ ๋ป์ธ์ง ๋ชจ๋ฅด๊ฒ ๋ค์.

.NET 5๋ก Azure Function์ ์์ฑํ๋ฉด ์ต์ด ์ง๋ฌธ์์ ์ธ๊ธํ๋ Nuget ํจํค์ง๋ค์ด ๋ชจ๋ .NET 5๋ก ๋ ๊ฒ๋ค์ด ์๋์ผ๋ก ์ฐธ์กฐ๊ฐ ๋์ด ๋ง๋ค์ด์ง๋๋ค.
.NET Core 3.1๋ก Azure Function ๊ฐ๋ฐํ ๋ IoC ์ปจํ
์ด๋๋ Startup ํด๋์ค๋ฅผ ๋ฐ๋ก ์์ฑํด์ ํ์ด์ผ ํ๋๋ฐ, .NET 5๋ก Azure Function ๊ฐ๋ฐํ ๋๋ Program ํด๋์ค๊ฐ ์์ด์ ๊ทธ๋ฅ ์ฌ๊ธฐ์ ์์ฑํ๋ฉด ๋ ๋ฏ ํฉ๋๋ค.
1๊ฐ์ ์ข์์
Vincent
3
.NET 5๋ก Azure Service Bus Trigger๋ฅผ Azure Function์ผ๋ก ๊ฐ๋ฐํ๋ค ๋ฐ์ํ์ต๋๋ค.
static async Task Main()
{
IHost host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration((hostingContext, configuration) =>
{
//configuration.Sources.Clear();
IHostEnvironment env = hostingContext.HostingEnvironment;
configuration.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
configuration.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true);
IConfigurationRoot configurationRoot = configuration.Build();
ShopeeSecretKeySettings shopeeSecretKeySettings = new();
configurationRoot.GetSection(nameof(ShopeeSecretKeySettings)).Bind(shopeeSecretKeySettings);
})
.ConfigureServices((context, services) =>
{
services.Configure<ShopeeSecretKeySettings>(context.Configuration.GetSection(nameof(ShopeeSecretKeySettings)));
services.AddHttpClient();
services.AddHttpClient("RequestLimitHttpClient").ConfigurePrimaryHttpMessageHandler(() =>
{
return new HttpClientHandler
{
MaxConnectionsPerServer = MaxConnection,
};
});
})
.Build();
await host.RunAsync();
}
์ ์์ค์์ ์ฃผ์์ฒ๋ฆฌํ configuration.Sources.Clear() ๋ฅผ ์ฌ์ฉํ๋ฉด local.settings.json์ ์์ฑํ ์ฐ๊ฒฐ ๋ฌธ์์ด์ ์ธ์ํ์ง ๋ชปํฉ๋๋ค.