javascript Quickstart

Overview

In this quickstart you will create a service that receives a name from a client and responds to the client with a message. Communication between the client and service is facilitated by the Proteus Broker.

Prerequisites

You need the following items installed on your machine to run the quickstart:

Get Started

Follow the steps below to get up and running with Proteus quickly.

  1. Clone Proteus JS Quickstart Project

    Clone the Proteus Browser Demo project from Github.

    git clone https://github.com/netifi/proteus-quickstart-js.git
  2. Build the Project

    After you have cloned the project change to the proteus-browser-demo directory and build the project:

    cd proteus-quickstart-js
    && yarn && yarn install && yarn protoc
  3. Run the Broker Locally

    Run a local instance of the broker with Docker for your clients and server to connect with

    1. Download the Broker

      Once the project is built you need to download the Proteus Broker. The broker is distributed as a Docker container on Docker Hub. To download the Proteus Broker Docker image run the following command in a new terminal window:

      docker pull netifi/proteus
    2. Start the Broker

      Now that you have downloaded the broker from Docker Hub, start it by running the following command:

      docker run -p 8001:8001 -p 7001:7001 -p 9000:9000 -e BROKER_SERVER_OPTS='-Dnetifi.broker.ssl.disabled=true -Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= -Dnetifi.broker.admin.accessKey=9007199254740991 -Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=' netifi/proteus:1.5.2
  4. Run the Node App

    Running the server.js file with a Node process will connect a HelloService server

    node src/main/js/server.js
  5. Run the Browser App

    Running the project with 'start' will start a webserver that hosts the client application at port 3000

    yarn start
  6. View the Browser App

    Open one or more browser tabs and navigate to

    http://localhost:3000

    The application calls "SayHello" on the Node HelloService, reflected in its log. The Client application will print out the response.

  7. Optional: Reverse Roles of Browser and Node

    A couple of changes are required to reverse the roles of the Browser and Node.

    1. Modify the Browser App

      A small change is required to start the Browser app as a server. In the root proteus-quickstart-js directory, open the file webpack.config.js. Line 13 reads

      '__AS_SERVER__': false,

      Change the value to true

      '__AS_SERVER__': true,

      Save the file

    2. Run the Browser App

      Running the project will start a webserver that hosts the application at port 3000 as before but now it runs as a HelloService server

      yarn start
    3. View the Browser App

      Open one of more browser tabs and navigate to

      http://localhost:3000

      The application connects to the local Broker as a HelloService server

    4. Run the Node App

      Running the Node app with an additional "true" argument will start the node process as a HelloService client

      node src/main/js/server.js true

      The console now indicates that the Node app acted as a client and received a reply from the Browser!

Challenge

Now that you have a service, client, and broker successfully running. See if you can implement a ping-pong service whereby the client repeatedly pings the service, and the service always replies with a pong.

An example implementation is in the ping-pong-solution branch.

Background Image

Check out our blog to learn more about Proteus and RSocket.

Read Our Blog