Skip to content

PearsonEducation/thalassa-http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thalassa Client

A lightweight client for Thalassa

Installation

npm install thalassa-http-client

Running the Client

The client can be run either:

  1. From the command-line
  2. As a module

Running Client from Command Line

Why would you do this? Let's say you have an existing legacy Java application that you'd rather not change. You can create a sister service that invokes the command line client to register the service on it's behalf.

For example, if Thalassa is installed globally (other wise `./node_modules/.bin/thalassa-client):

thalassa-client --register [email protected]:8080 --debug

This registers the application named my app at version 1.0.0 that's on the current host on port 8080. The client will continue to ping the Thalassa server with updates.

Client Command Line Options

thalassa-client --help
  Options:
    --host           thalassa host                                                    [default: "127.0.0.1"]
    --apiport        thalassa http api port                                           [default: 9000]
    --register       [email protected]:port,[email protected]:port                                  [required]
    --secsToExpire   default time in seconds for a thalassa registration to be valid  [default: 60]
    --updateFreq     time frequency in ms to ping the thalassa server                 [default: 20000]
    --updateTimeout  time in ms to wait for a registration request to respond         [default: 2500]
    --debug          enabled debug logging

Client as an Embedded Module

Using the client from within a node.js application to register your service is simple. Pass options via the opts object like new ThalassaClient(opts):

var ThalassaClient = require('thalassa-http-client');

var client = new ThalassaClient({
  apiport: 4445,
  host: 'localhost'
});

client.register('myapp', '1.0.0', 8080);

// start reporting registrations to the server
client.start();

// stop reporting registrations to the server
client.stop();

In addition opts.log may be optionally set to your own function to handle logging. opts.log expects this signature: function log (level, message, object){}. level will be one of debug, info, and error. message is a string and object is an optional object with key value pairs. If opts.log is not passed, the module will be quiet.

updateSuccessful and updateFailed Events

The client will periodically check in with the Thalassa server according to opts.updateFreq (default 20000ms). Each registration will product a updateSuccessful or updateFailed event to be emitted.

client.on('updateSuccessful', function () {}); client.on('updateFailed', function (error) {});

Querying Registrations

Also as a module, you can use the client API to query for registrations.

client.getRegistrations('myapp', '1.0.0', function (err, registrations) {
    // registrations is an Array of Registrations
}

See the HTTP API section for the Registration structure.

Metadata

You can also pass metadata with any registration as a fourth parameter. This can be any javascript object with properties. For example:

var meta = {
    az: 'use1a',
    size: 'm1.large',
    foo: {
        bar: 'baz'
    }
};
client.register('myapp', '1.0.0', 8080, meta)

License

Licensed under Apache 2.0. See LICENSE file.

About

A simple http client for Thalassa that doesn't require ZeroMQ

Resources

License

Stars

Watchers

Forks

Packages

No packages published