LoginSignup
8
5

More than 5 years have passed since last update.

Azure Function で App Settings / Connection String で使ってはいけない名前

Last updated at Posted at 2017-08-16

今日は同僚とどっぷりハマった内容を。

Azure Functions の、 Queue Trigger を使った時に、私の同僚の環境だとちゃんとデキューするのに、私の環境だと動かなかった。同僚といろいろ試してみると、私の環境だと、App Setting で指定する、Queue Trigger の名前が "Storage" だったらダメだけど、他の名前だったら動くという全く意味不明な振る舞いが判明した。

Function02.png

原因はわからないので、Issue をあげてみた

彼がここで、App Settings とっているといったコードを見て分かった事。

      internal static readonly string Prefix = "AzureWebJobs";

        /// <summary>

        /// Attempts to first read a connection string from the connectionStrings configuration section.

        /// If not found there, it will attempt to read from environment variables.

        /// </summary>

        /// <param name="connectionStringName">The name of the connection string to look up.</param>

        /// <returns>The connection string, or <see langword="null"/> if no connection string was found.</returns>

        public string GetConnectionString(string connectionStringName)

        {

            // first try prefixing

            string prefixedConnectionStringName = GetPrefixedConnectionStringName(connectionStringName);

            string connectionString = ConfigurationUtility.GetConnectionFromConfigOrEnvironment(prefixedConnectionStringName);



            if (string.IsNullOrEmpty(connectionString))

            {

                // next try a direct unprefixed lookup

                connectionString = ConfigurationUtility.GetConnectionFromConfigOrEnvironment(connectionStringName);

            }



            return connectionString;

        }


これやと、Storage と記述して、もし、AzureWebJobsStorage というのがセットされていたら、こっちが勝つがな。そして、AzureWebJobsStorage というのは先に登録されているので、そっちのほうが読み込まれる。

同僚の環境で動いたのは、同僚の環境だと、AzureWebJobsStorage の StorageAccount が Queue のものと同一だったから。その同僚が、こんなコードを発見してくれた。

namespace Microsoft.Azure.WebJobs

{

    /// <summary>Defines connection string names used by <see cref="IConnectionStringProvider"/>.</summary>

    public static class ConnectionStringNames

    {

        /// <summary>Gets the dashboard connection string name.</summary>

        public static readonly string Dashboard = "Dashboard";



        /// <summary>Gets the Azure Storage connection string name.</summary>

        public static readonly string Storage = "Storage";



        /// <summary>Gets the Azure ServiceBus connection string name.</summary>

        public static readonly string ServiceBus = "ServiceBus";

    }

}

結論

Azure Functions の AppSettings/Connection String には、Storage, Dashboard, ServiceBus という名前は付けてはいけない。

以上です!

リソース

8
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5