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

Latest commit

 

History

History
167 lines (107 loc) · 6.79 KB

OLD-README.adoc

File metadata and controls

167 lines (107 loc) · 6.79 KB

Friends & Presence service - part of Cloudstate Chat sample

1. Overview

ℹ️
This sample is a work-in-progress, and is not up-to-date with the latest changes in Cloudstate or [Akka Serverless](https://docs.cloudstate.com/). Please see the Shopping Cart samples for the most recent examples of a Cloudstate app instead.

This is the implementation of the Friends and Presence services, which are part of Cloudstate Chat Sample. The code is written in JavaScript and runs as a Node.js server. The screenshot below shows the user interface of the chat application:

Cloudstate Sample - Chat Application

 

2. Tutorial

The Friends and Presence services have no User Interface. In this repository, we build these services and test them using docker and grpcurl.

A detailed tutorial is described in JavaScript implementation of the Friends service. As the design of these services is quite similar, it is not necessary to repeat for the Presence service.

3. Deployment - Akka Serverless

3.1. Deploying to Akka Serverless

The following steps use akkasls to deploy the application to [Akka Serverless](https://docs.cloudstate.com/).

3.3. Login to Akka Serverless

$ akkasls auth login

3.4. Create a new project

$ akkasls projects new sample-chat "Chat Sample"

Wait until you receive an email approving your project!

List projects:

$ akkasls projects list

You should see the project listed:

  NAME                   DESCRIPTION            STATUS   ID
  sample-chat   Chat Sample   active   39ad1d96-466a-4d07-b826-b30509bda21b

You can change the current project:

$ akkasls config set project sample-chat

3.5. Deploying the chat service

A pre-built container image of the friends service has been provided at lightbend-docker-registry.bintray.io/cloudstate-samples/friends. If you have built your own container image, change the image in the following command to point to the one that you just pushed.

$ akkasls svc deploy \
    friends \
    lightbend-docker-registry.bintray.io/cloudstate-samples/friends

Wait for the friends service STATUS to be ready.

$ akkasls svc get

3.6. Expose the friends service

$ akkasls svc expose friends --enable-cors

The output will look like this:

Service 'friends' was successfully exposed at: small-fire-5330.us-east1.apps.lbcs.io

Make a note of the hostname since it will be used by the frontend static html page.

Repeate the above process replacing friends with the word presence to deploy your presence service.

3.7. Visit the chat web frontend

Once the page has loaded your will see a dialog prompting you to enter the hostname for your exposed (and CORS enabled) friends service.

In the example above, the hostname would be:

small-fire-5330.us-east1.apps.lbcs.io

4. Deployment - Kubernetes Open Source Cloudstate

It is at deployment time, when all the services collaborate together that we can really appreciate the true benefits of a serverless deployment model. In particular in terms of their stateful and serverless abilities. By using Cloudstate library and deploying on Kubernetes, your services store and retrieve state without requiring you to write any code nor manage any storage.

The deployment is described in details in the Cloudstate Chat Sample. The deployment is mentioned as a heads-up showing the big picture of the end result. We don’t have yet all the constituants to deploy the entire Chat application.

Our goal here is to build and test the Friends and Presence services. For now, the first step is to setup the dev environment. We will get to the Chat application deployment after we would have successfully tested these services.

5. Tools Prerequisites

5.1. Docker

Cloudstate services are deployed on a cluster complying to Kubernetes deployment model. Docker is used to package the Cloudstate-aware service that you design into a container.

  • Install Docker

    • Check with docker version, version v19.03+ is recommended

5.2. gRPCurl for testing gRPC servers

The communication between the Cloudstate user-function uses the gRPC protocol. gRPCurl is a command-line tool allowing to query gRPC servers in the same fashion as curl with REST servers.

gRPCurl is not a deployment tool per-se. It is used to make a quick integration test of your services before deployment.

Install gRPCurl from brew if you are on macOS or directly from binaries for other OS. If the installation is successful, you should be able to invoke grpcurl -version in a terminal:

$ grpcurl -version
grpcurl 1.6.0

5.3. Optional for Local JavaScript Development

nvm and npm tools are NOT needed to build the Docker images, deploy and test the Friends and Presence services. In case you want to play around with the JavaScript code you need to install:

  • Install nvm (node version manager)

    • Check with nvm --version, version 0.34.0+ recommended

  • Install npm (node package manager)

    • Check with npm -v, version 6.14.3+ recommended

(end)