Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Latest commit

 

History

History
 
 

hello-service-fabric

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Dapr on Service Fabric Sample

Sample info

Attribute Details
Dapr runtime version v1.4.0
Language Javascript
Environment Service Fabric

Overview

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:

Architecture Diagram

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.

Prerequisites

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.

Step 1 - Setup Dapr

Follow these instructions to download and install the Dapr CLI and initialize Dapr with dapr init.

dapr init

Step 2 - Setup Service Fabric

  1. Create a basic Service Fabric cluster through the SDK as described here.

  2. Right click "Service Fabric Local Cluster Manager" in the taskbar and select "Start Local Cluster".

Step 3 - Create the Service Fabric Application Package

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.

  1. 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\
  2. 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\
  3. From \daprsfpkg\MyService\CodeUserApp\, run npm install to install the node.js app's dependencies and return to \hello-service-fabric.

    cd .\daprsfpkg\MyService\CodeUserApp\
    npm install
    cd ..\..\..
  4. 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.

Step 4 - Create the Service Fabric Application

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.

Part 5 - Post Messages to the Service

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

Part 6 - Cleanup

  1. Delete the Service Fabric application instance:

    Remove-ServiceFabricApplication -ApplicationName fabric:/dapr1 -Force
  2. Unregister the Service Fabric application type

    Unregister-ServiceFabricApplicationType -ApplicationTypeName daprsf -ApplicationTypeVersion 1.0 -Force