Coder Social home page Coder Social logo

eigr-labs / samples-js-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudstateio/samples-js-chat

0.0 0.0 0.0 1.58 MB

Sample app demoing using Cloudstate to build a chat application in Node.js

Home Page: https://cloudstate.io

License: Apache License 2.0

Dockerfile 24.29% JavaScript 75.71%

samples-js-chat's Introduction

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)

samples-js-chat's People

Contributors

coreyauger avatar dependabot[bot] avatar jroper avatar jsravn avatar justinhj avatar katsutoxin avatar marcoderama avatar michaelpnash avatar tringuyen-yw avatar viktorklang avatar vkorenev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.