简体   繁体   中英

How do I publish multiple instances of an application to Service Fabric cluster from Visual Studio?

I have created a statless service fabric application in visual studio and need to publish two instances of it. The first goes well, but when i try to pusblish the second app i get the error:

2>Application Type  DevelopmentType  and Version  1.0.0  was already registered with Cluster, unregistering it...
2>Unregister-ServiceFabricApplicationType : Application type and version is still in use
2>At C:\Program Files\Microsoft SDKs\Service 
2>Fabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:224 char:20
2>+             $reg | Unregister-ServiceFabricApplicationType -Force
2>+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2>    + CategoryInfo          : InvalidOperation: (Microsoft.Servi...usterConnection:ClusterConnection) [Unregister-Serv 
2>   iceFabricApplicationType], FabricException
2>    + FullyQualifiedErrorId : UnregisterApplicationTypeErrorId,Microsoft.ServiceFabric.Powershell.UnregisterApplicatio 
2>   nType
2> 
2>Finished executing script 'Deploy-FabricApplication.ps1'.

I want the instance to have the same ApplicationType, but when i publish with a new application name and a new publish profile i only get the error above.

The problem is that you're essentially trying to overwrite the existing app type with a new one but since the existing app type has an app associated with it, you get this error. In order to "overwrite" the app type, the system would need to delete it and register the new one. But it can't be deleted because it has an existing app associated with it. So that's why you get this error.

A little background on the difference between an application type and an application. It's sort of like the difference between a class and an instance in programming. An app type represents what an app can be. It contains the code, configuration, and data. But an app type is just a definition; it's not a running app. When you create an app, you create it to be based on an app type. Now you've got a running application. Just like the programming analogy, you can create multiple applications from one app type, which is what you're trying to do.

When you deploy from VS, it doesn't know your intention that you want to create a new application from an existing app type on the cluster. It assumes you want to deploy the application with the code that you've defined in your project. Since VS doesn't know how that code differs from what is on the cluster, it proceeds with attempting to remove any conflicting app type (an app type with the same name and version) in order to register a new app type with the code that was contained in your project. And that's when you run into the error.

So how do you resolve this? If your intention is really to just create another application from the existing app type, without any code differences between the two applications, then you'll need to handle this directly from PowerShell and not use VS. What you're trying to do is just basic management of your cluster. You'll want to use the New-ServiceFabricApplication PowerShell cmdlet (see https://docs.microsoft.com/en-us/powershell/servicefabric/vlatest/new-servicefabricapplication ). Note that if you haven't configuration your application properly, you may run into port conflicts between the two applications. To avoid that, you'd want to parameterize your ports in your app manifest so that you can provide different port values when invoking New-ServiceFabricApplication .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM