java 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 Quickstart Project

    Clone the Java Quickstart project from Github.

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

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

    cd proteus-quickstart
    ./gradlew build
  3. Start the Broker

    Once the project is built you need to start the broker. The Proteus Broker is packaged and distributed as a Docker container. To start the Broker run the following command in another terminal window:

    docker run \
    -p 8001:8001 \
    -p 7001:7001 \
    -p 9000:9000 \
    -e BROKER_SERVER_OPTS="'-Dnetifi.authentication.0.accessKey=9007199254740991'  \
    '-Dnetifi.broker.console.enabled=true' \
    '-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=' \
    '-Dnetifi.broker.admin.accessKey=9007199254740991' \
    '-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY='" \
    netifi/proteus:1.5.2
  4. Start the Example Service

    Back in the proteus-quickstart directory start up the service by running the following command:

    ./gradlew :service:run

    This will startup a simple service that connects to the broker.

  5. Run the Example Client

    Open another terminal window and go the proteus-quickstart directory. This time instead of starting the service, use a client to send a message. This can be done by running the following command:

    ./gradlew :client:run

    The client will startup, connect to the broker, and send a message to the service.

    The following is approximately the expected output from the client:

    $ ./gradlew :client:run
    ...
    i.n.s.Netifi [main] registering with netifi with account id 100, group quickstart.clients, and destination client1
    i.n.p.q.c.Main [main] Sending 'World' to HelloService...
    i.n.p.q.c.Main [main] message: "Hello, World! from helloservice-2782cbee-1bcd-49c9-991c-fbb88c8e26d7"
    ...

    The service logs should show that it has received the message:

    i.n.p.q.s.DefaultHelloService [reactor-tcp-nio-4] received a message -> World

    And the broker should show something akin to this:

    i.n.r.a.RouterSocketAcceptor [reactor-tcp-nio-4] -4687034539111874558 - adding destination helloservice-2782cbee-1bcd-49c9-991c-fbb88c8e26d7 to group 100:quickstart.services.helloservices
    i.n.r.a.RouterSocketAcceptor [reactor-tcp-nio-1] -2050621438 - adding destination client1 to group 100:quickstart.clients
    i.n.r.b.RemoteLoadBalancedRSocket [reactor-tcp-nio-1] -2050621436 - creating load balancer for group quickstart.services.helloservices
    i.n.r.a.RouterSocketAcceptor [reactor-tcp-nio-1] -2050621438 - removing destination client1 from destination map
    i.n.r.a.RouterSocketAcceptor [reactor-tcp-nio-1] -2050621438 - removing destination client1 from group 100:quickstart.clients
    i.n.r.a.RouterSocketAcceptor [reactor-tcp-nio-1] -2050621438 - removing destination client1 from group quickstart.clients load balancer

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