Microsoft Azureサービスファブリックを初めて使用しました。私の修士号のために、私はサービスファブリックでマイクロサービスアプローチプロトタイプを開発しなければなりません。調査の時間がたっても、私はまだ私の問題を解決していません。ServiceProxy経由でステートレスサービスにアクセスできません+ ASP.NET 5 Web APIプロジェクトによって正常性状態エラーが発生します
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-add-a-web-frontend/のように、Webフロントエンドで(展開されたローカルファブリッククラスタの)ステートレスサービスにアクセスしたいとします。そのための最も簡単な方法は、Service FabricアプリケーションにASP .NET 5 Web Apiプロジェクトを追加し、ValuesController
でServiceProxy
メソッド呼び出しを行うことです。だから、私は解決策にこのコードを追加:
ValuesController.cs:
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values/IObject
[HttpGet("{interfaceName}")]
public async Task<string> Get(string interfaceName)
{
var serviceName = "fabric:/DataServiceFabric/MasterDataMService";
var masterDataService = ServiceProxy.Create<IMasterDataMService>(new Uri(serviceName));
var result = await masterDataService.GetMasterDataByName(interfaceName);
return result.Content;
}
}
を私のブラウザが自動的に自分のWebフロントエンドに移動していないF5は、配置した後。私のASP .NET 5アプリケーションは、健康状態のエラーをスローサービスファブリックExplorerに見ることによって:
Kind Health State Description
=============================================================================
Partitions Error Unhealthy partitions: 100% (1/1), MaxPercentUnhealthyPartitionsPerService=0%.
Partition Error Unhealthy partition: PartitionId='413...', AggregatedHealthState='Error'.
Event Error Error event: SourceId='System.FM', Property='State'. Partition is below target replica or instance count.
このthis質問の後「パーティションがターゲットレプリカまたはインスタンス数を下回っている」は、私の中にその未処理の例外を示し、サービスが起動しないようにしています。しかし、私はService Fabric Explorerでこの障害をデバッグするためにスタックstraceを見つけることができません。
ServiceManifest.xml(WEB1):
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Web1" Version="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Web1Type">
<Extensions>
<Extension Name="__GeneratedServiceType__">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="Web1Service" />
<ServiceEndpoint Name="Web1TypeEndpoint" />
</GeneratedNames>
</Extension>
</Extensions>
</StatelessServiceType>
</ServiceTypes>
<CodePackage Name="C" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>approot\runtimes\dnx-clr-win-x64.1.0.0-rc1-update1\bin\dnx.exe</Program>
<Arguments>--appbase approot\src\Web1 Microsoft.Dnx.ApplicationHost Microsoft.ServiceFabric.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener</Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048" />
</ExeHost>
</EntryPoint>
</CodePackage>
<Resources>
<Endpoints>
<Endpoint Name="Web1TypeEndpoint" Protocol="http" Type="Input" Port="80" />
</Endpoints>
</Resources>
</ServiceManifest>
そして、ここに私の私のサービス・ファブリック・ソリューションのApplicationManifest.xml
:
ApplicationManifest.xmlこれは私のASP .NET Webサービスの私のServiceManifest.xml
です:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="DataServiceFabricType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="ActorTestServiceActorService_PartitionCount" DefaultValue="10" />
<Parameter Name="MasterDataMService_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Web2Pkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Web1" ServiceManifestVersion="1.0.0" />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="ActorTestServicePkg" ServiceManifestVersion="1.0.0" />
</ServiceManifestImport>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="MasterDataMServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<DefaultServices>
<Service Name="Web1Service">
<StatelessService ServiceTypeName="Web1Type">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="ActorTestServiceActorService" GeneratedIdRef="761ee3cf-5a3a-49d8-9c57-aa3480d1acf1">
<StatelessService ServiceTypeName="ActorTestServiceActorServiceType">
<UniformInt64Partition PartitionCount="[ActorTestServiceActorService_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatelessService>
</Service>
<Service Name="MasterDataMService">
<StatelessService ServiceTypeName="MasterDataMServiceType" InstanceCount="[MasterDataMService_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
ASP.NET 5 Webアプリケーションと同じValuesController.cs
で新しいソリューションを作成しました。ステートレスサービスがローカルクラスタ上で実行されていることを保証し、私は新しいWebアプリケーションを開始しました。私のコントローラでGET-メソッドを呼び出した後、私は次の例外を得た:
Exception thrown: 'System.Fabric.FabricException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 0,2593ms 500
Microsoft.AspNet.Server.Kestrel: Error: An unhandled exception was thrown by the application.
System.Fabric.FabricException: Invalid partition key/ID '{0}' for selector {1}
は私のステートレスサービスはSingletonPartitionあるので、私はここでは、パーティション・キーが必要なのでしょうか?はいの場合は、どうすれば鍵を入手できますか?サービスファブリックエクスプローラは、私のステートレスサービスに関するこの情報を私に提供しません。ここに私のステートレスサービスのServiceManifest.xml
です:
ServiceManifest.xml(MasterDataMService):
MasterDataMService:私はOWINとサービスの通信を設定することを決めた後
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="MasterDataMServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="MasterDataMServiceType" />
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MasterDataMService.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="ServiceEndpoint" Type="Input" Protocol="http" Port="80"/>
</Endpoints>
</Resources>
</ServiceManifest>
。CS:
var client = new HttpClient();
var request = "http://localhost:80/MasterDataMService/api/values/query";
var result = string.Empty;
HttpResponseMessage response = await client.GetAsync(request);
if (response.IsSuccessStatusCode)
{
result = await response.Content.ReadAsStringAsync();
}
しかし、私は元々望んでいないthatsの:
internal sealed class MasterDataMService : StatelessService, IMasterDataMService
{
[...]
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(initParams => new OwinCommunicationListener("MasterDataMService", new StartUp(), initParams))
};
}
}
今、私は私のDefaultController
でHttpClient
を使用して、私のmicroserviceをアセスすることができます。私は私の要求でサービスエンドポイントを特定したくありません。代わりに、ServiceProxy
で私の無国籍サービスと連絡したいと思います。ここではどのように達成するのですか?何が間違っていたのですか?また、サービスファブリッククラスタに展開されているASP .NET 5アプリケーションでこの正常性状態のエラーを解決するにはどうすればよいですか。
お時間をいただきありがとうございます。
編集:無効なパーティションキー例外の
拡張スタックトレース:
Exception thrown: 'System.Fabric.FabricException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 1,35ms 500
Microsoft.AspNet.Server.WebListener.MessagePump: Error: ProcessRequestAsync
System.Fabric.FabricException: Invalid partition key/ID '{0}' for selector {1} ---> System.Runtime.InteropServices.COMException: exception of HRESULT: 0x80071BBF
at System.Fabric.Interop.NativeClient.IFabricServiceManagementClient4.EndResolveServicePartition(IFabricAsyncOperationContext context)
at System.Fabric.FabricClient.ServiceManagementClient.ResolveServicePartitionEndWrapper(IFabricAsyncOperationContext context)
at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Client.ServicePartitionResolver.<ResolveAsyncHelper>d__2a.MoveNext()
--- End of stack trace from the previous location where the exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<GetClientAsync>d__a.MoveNext()
あなたがより多くを必要とする場合は、私にフィードバックをお願いします。
無効スキーム例外スタックトレース(フルスタックトレースは82行の長さである):
Exception thrown: 'System.ArgumentException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 1,45ms 500
Microsoft.AspNet.Server.WebListener.MessagePump: Error: ProcessRequestAsync
System.ArgumentException: the provided uri scheme 'http' is invalid; expected 'net.tcp'.
Parametername: via
at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelFactory`1.OnCreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.Channels.ChannelFactoryBase`1.InternalCreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverDuplexSession.CreateInnerChannelBinder(EndpointAddress to, Uri via)
at System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress address, Uri via)
at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(Type channelType, EndpointAddress address, Uri via)
at System.ServiceModel.DuplexChannelFactory`1.CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
at System.ServiceModel.DuplexChannelFactory`1.CreateChannel(InstanceContext callbackInstance, Binding binding, EndpointAddress endpointAddress)
at Microsoft.ServiceFabric.Services.Communication.Wcf.Client.WcfCommunicationClientFactory`1.<CreateClientAsync>d__2.MoveNext()
--- End of stack trace from the previous location where the exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<CreateClientWithRetriesAsync>d__1e.MoveNext()
に役立ちます願っていますが、1つのパーティションを持っている場合、それは問題ではないはずです。 – Mikhail
無効なパーティションキー例外のスタックトレースには他のものがありますか?シングルトンパーティションスキームを使用するサービスのパーティションキーを指定する必要はありません。ステートレスサービスのように、エラーが奇妙に見えることがあります。 –
@Mikhail私の 'ActorTestServiceActorService'のようなを指定し、 'ServiceProxy'を使って私のマイクロサービスに話をすると、** System.ArgumentExceptionが発生します:**提供されたURIスキーム 'http'は無効です。期待されるネット。tcp'_ –
MegaMax