Attribute | Details |
---|---|
Dapr runtime version | v1.4.0 |
Language | Javascript |
Environment | Service Fabric |
The following is a sample of how to host a Dapr app on a Service Fabric cluster. We'll be deploying a Node.js app that subscribes to order messages and persists them. The following architecture diagram illustrates the components that make up this sample:
Some Dapr functionality, including Pub/Sub, Secrets and Bindings work without any integration with SF. However, service invocation, will not work without additional changes and is out of scope for this post.
Clone this repo using git clone https://github.com/dapr/samples.git
and go to the directory named \hello-service-fabric. All commands should be executed from a PowerShell terminal.
- Docker
- PowerShell
- REST Client extension
- Node.js version 8 or greater
- Microsoft Azure Service Fabric SDK
Follow these instructions to download and install the Dapr CLI and initialize Dapr with dapr init
.
dapr init
-
Create a basic Service Fabric cluster through the SDK as described here.
-
Right click "Service Fabric Local Cluster Manager" in the taskbar and select "Start Local Cluster".
This section will create an application package where daprd.exe and the user node.js app will be run as guest executables in two separate code packages under the same Service Fabric service. They'll always be co-located.
-
Copy daprd.exe from your local Dapr installation,
c:\Users\[user]\.dapr\bin
, into\daprsfpkg\MyService\CodeDapr\
.copy c:\Users\$env:username\.dapr\bin\daprd.exe .\daprsfpkg\MyService\CodeDapr\
-
Copy the components from your local Dapr installation,
c:\Users\[user]\.dapr\components
, into\daprsfpkg\MyService\CodeDapr\components
.copy c:\Users\$env:username\.dapr\components\*.* .\daprsfpkg\MyService\CodeDapr\components\
-
From
\daprsfpkg\MyService\CodeUserApp\
, runnpm install
to install the node.js app's dependencies and return to\hello-service-fabric
.cd .\daprsfpkg\MyService\CodeUserApp\ npm install cd ..\..\..
-
From
\hello-service-fabric
, confirm the application package is well-formed:Test-ServiceFabricApplicationPackage .\daprsfpkg\
Notes:
-
the application package includes the Dapr
components
folder, which stores Dapr component configurations, in the Dapr code package. In Dapr standalone (local) mode, this is generated by the Dapr CLI. It is included so daprd.exe can read it when running on a Service Fabric cluster. -
the service manifest contains a command to invoke daprd.exe with the same args that the Dapr CLI does in the sample.
Copy the application package to the cluster, register it, then create the application.
Connect to the cluster:
Connect-ServiceFabricCluster
Copy the application package to the cluster:
Copy-ServiceFabricApplicationPackage daprsfpkg
Register it:
Register-ServiceFabricApplicationType daprsfpkg
Create the application instance:
New-ServiceFabricApplication -ApplicationName fabric:/dapr1 -ApplicationTypeName daprsf -ApplicationTypeVersion 1.0
daprd.exe and the node.js app will run on the same node.
Now that Dapr and the Node.js app are running, you can publish events to the pubsub component, using the Visual Studio Code REST Client extension.
Open the requests.http
file in the root folder to execute the following requests.
POST http://localhost:3500/v1.0/publish/pubsub/neworder
Content-Type: application/json
{"order":{"orderId":"44"}}
###
GET http://localhost:3500/v1.0/invoke/mynode/method/order
-
Delete the Service Fabric application instance:
Remove-ServiceFabricApplication -ApplicationName fabric:/dapr1 -Force
-
Unregister the Service Fabric application type
Unregister-ServiceFabricApplicationType -ApplicationTypeName daprsf -ApplicationTypeVersion 1.0 -Force