我正在使用服务结构,并且有一个包含两个actor和一个服务的包,在构建时,我的应用程序的清单文件会自动更新为:
<?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="MessageProcessor.ServiceFabricHostType" ApplicationTypeVersion="1.0.2" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="QueueListenerActorService_PartitionCount" DefaultValue="10" />
<Parameter Name="QueueManagerActorService_PartitionCount" DefaultValue="10" />
<Parameter Name="QueueManagerActorService_MinReplicaSetSize" DefaultValue="2" />
<Parameter Name="QueueManagerActorService_TargetReplicaSetSize" DefaultValue="3" />
<Parameter Name="ManagementApiService_InstanceCount" DefaultValue="-1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="ServiceFabricPkg" ServiceManifestVersion="1.0.2" />
</ServiceManifestImport>
<DefaultServices>
<Service Name="QueueManagerActorService" GeneratedIdRef="1fbd648e-7780-4ddb-869e-9bc965f0d15f">
<StatefulService ServiceTypeName="QueueManagerActorServiceType" TargetReplicaSetSize="[QueueManagerActorService_TargetReplicaSetSize]" MinReplicaSetSize="[QueueManagerActorService_MinReplicaSetSize]">
<UniformInt64Partition PartitionCount="[QueueManagerActorService_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatefulService>
</Service>
<Service Name="ManagementApiService">
<StatelessService ServiceTypeName="ManagementApiServiceType" InstanceCount="[ManagementApiService_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="QueueListenerActorService" GeneratedIdRef="06c6a81c-fbb7-4938-97b5-15e76888363c">
<StatelessService ServiceTypeName="QueueListenerActorServiceType">
<UniformInt64Partition PartitionCount="[QueueListenerActorService_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
但我希望它不会部署QueueListenerActorService
,因为我将在应用程序代码中稍后设置一些在部署时未知的放置约束。
`
var fabricClient = new FabricClient();
var services = await fabricClient.QueryManager.GetServiceListAsync(new Uri("fabric:/MessageProcessor.ServiceFabricHost"), new Uri("fabric:/MessageProcessor.ServiceFabricHost/QueueListenerActorService"));
await fabricClient.ServiceManager.CreateServiceAsync(new StatelessServiceDescription
{
ServiceTypeName = "QueueListenerActorServiceType",
ServiceName = serviceUri,
PartitionSchemeDescription = new UniformInt64RangePartitionSchemeDescription { PartitionCount = 2, LowKey = Int64.MinValue, HighKey = Int64.MaxValue },
InstanceCount = 1,
PlacementConstraints = "NodeType == something",
ApplicationName = new Uri("fabric:/MessageProcessor.ServiceFabricHost"),
});
如果我从清单文件中删除它,那么它会在构建时再次生成
答案 0 :(得分:2)
作为Actor Nuget包的一部分,它包含了一个构建脚本,可以使用工具FabActUtil.exe
自动生成和更新服务和应用程序清单。
通过更改包含actor和设置属性的项目的项目文件.csproj。
<UpdateServiceFabricManifestEnabled>false</UpdateServiceFabricManifestEnabled>
可以禁用该工具。
然后我可以评论出我想忽略的服务。
因为咕噜几乎是视觉工作室的第一手公民,所以我决定用它来实现自动化。禁用上述属性的问题在于,卸载项目以使其在添加新actor时生成新清单非常烦人。现在,我有一项令人目眩的任务,让事情变得更加轻松。
module.exports = function (grunt) {
'use strict';
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-xmlstoke');
grunt.registerTask("FabActUtil", ["copy:FabActUtilBackup", "copy:FabActUtil", "exec:FabActUtil","xmlstoke:FabActUtil","clean:FabActUtil"]);
var relativePackageDir = "../../packages/";
var buildDir = "bin/x64/Debug/";
var temp = "artifacts"
var assemblyName = "S-Innovations.Azure.MessageProcessor.ServiceFabric.exe";
var relativeAppDir = "../MessageProcessor.ServiceFabricHost/";
var appManifest = relativeAppDir + 'ApplicationPackageRoot/ApplicationManifest.xml';
grunt.initConfig({
copy:{
FabActUtil:{
src: relativePackageDir + "Microsoft.ServiceFabric.Actors*/build/FabActUtil.exe",
dest: buildDir+"FabActUtil.exe"
},
FabActUtilBackup:{
src:appManifest,
dest: appManifest+".bac"
}
},
clean:{
FabActUtil: ["bin/x64/Debug/FabActUtil.exe"],
},
exec: {
// Run tsd link to add bower/npm packages typescript definition files.
"FabActUtil": {
cmd: 'bin\\x64\\Debug\\FabActUtil.exe /app:' + relativeAppDir.replace(new RegExp('/', 'g'), "\\") + '\\ApplicationPackageRoot /out:' + temp.replace(new RegExp('/', 'g'), "\\") + ' /spp:PackageRoot /in:' +buildDir.replace(new RegExp('/', 'g'),"\\")+ assemblyName,
}
},
xmlstoke: {
FabActUtil: {
options: {
actions: [{
xpath: '//DefaultServices/Service[@Name="QueueListenerActorService"]',
type: 'D'
}],
},
files: { appManifest: appManifest },
},
},
})
}
在添加package.json
时自动在vs中安装以下软件包{
"name": "sf",
"version": "1.0.0",
"dependencies": { },
"devDependencies": {
"grunt": "^0.4.5",
"grunt-exec": "^0.4.6",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-clean": "1.0.0",
"grunt-xmlstoke": "0.7.1"
}
}
请注意,要使用此功能必须修复路径。