6

私はホステッドサービスでワーカーの役割を果たしています。労働者は毎日電子メールを送信しています。ただし、ホステッドサービスには、ステージングと本番の2つの環境があります。したがって、私のワーカーの役割は、毎日2回電子メールを送信します。労働者が停滞しているのか生産中なのかを検出する方法を知りたいのですが。前もって感謝します。

4

2 に答える 2

1

ここでの私の質問によると、これを行うための迅速な方法がないことがわかります。また、自分が何をしているのかを本当に理解していない限り、これを行わないことを強くお勧めします。

ただし、必要に応じて、 WCFでの使用に問題があったとしても、非常に優れたライブラリ(C#を介したAzure Service Management)を使用できます。

これを行う方法の簡単なサンプルを次に示します(コードにリソースとして管理証明書を含め、Azureにデプロイする必要があることに注意してください)。

 private static bool IsStaging()
        {
            try
            {
                if (!CloudEnvironment.IsAvailable)
                    return false;

                const string certName = "AzureManagement.pfx";
                const string password = "Pa$$w0rd";

                // load certificate
                var manifestResourceStream = typeof(ProjectContext).Assembly.GetManifestResourceStream(certName);
                if (manifestResourceStream == null)
                {
                    // should we panic?
                    return true;
                }

                var bytes = new byte[manifestResourceStream.Length];
                manifestResourceStream.Read(bytes, 0, bytes.Length);

                var cert = new X509Certificate2(bytes, password);

                var serviceManagementChannel = Microsoft.Toolkit.WindowsAzure.ServiceManagement.ServiceManagementHelper.
                    CreateServiceManagementChannel("WindowsAzureServiceManagement", cert);

                using (new OperationContextScope((IContextChannel)serviceManagementChannel))
                {
                    var hostedServices =
                        serviceManagementChannel.ListHostedServices(WellKnownConfiguration.General.SubscriptionId);

                    // because we don't know the name of the hosted service, we'll do something really wasteful
                    // and iterate
                    foreach (var hostedService in hostedServices)
                    {
                        var ad =
                            serviceManagementChannel.GetHostedServiceWithDetails(
                                WellKnownConfiguration.General.SubscriptionId,
                                hostedService.ServiceName, true);

                        var deployment =
                            ad.Deployments.Where(
                                x => x.PrivateID == Zebra.Framework.Azure.CloudEnvironment.CurrentRoleInstanceId).
                                FirstOrDefault
                                ();

                        if (deployment != null)
                        {
                            return deployment.DeploymentSlot.ToLower().Equals("staging");
                        }
                    }
                }

                return false;
            }
            catch (Exception e)
            {
                // if something went wrong, let's not panic
                TraceManager.AzureFrameworkTraceSource.TraceData(System.Diagnostics.TraceEventType.Error, "Exception", e);
                return false;
            }
        }
于 2011-09-13T11:46:56.363 に答える
0

SQLサーバー(VMでホストされているAzureSQLまたはSQLServerのいずれか)を使用している場合は、本番インスタンスのパブリックIPにデータベースサーバーへのアクセスのみを許可することで、ステージングワーカーの役割による作業を停止できます。

于 2015-04-30T08:19:29.133 に答える