ping-json

command
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

A simple ping-pong service implementation that that integrates ringpop to forward requests between nodes.

Note: this file can be cram-executed using make test-examples. That's why some of the example outputs below are a bit unusual.

Running the example

All commands are relative to this directory:

$ cd ${TESTDIR}  # examples/ping-json
$ go build

Start a custer of 5 nodes using tick-cluster:

$ tick-cluster.js --interface=127.0.0.1 -n 5 ping-json &> tick-cluster.log &
$ sleep 5

Lookup the node my_key key belongs to using tcurl:

$ tcurl ringpop -P hosts.json /admin/lookup '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"dest":"127.0.0.1:300?"},"headers":{"as":"json"},"trace":"*"} (glob)

Call the /ping endpoint (multiple times) and see the request being forwarded. Each request is sent to a random node in the cluster because of the -P hosts.json argument--but is always handled by the node owning the key. This can be seen in the from field of the response:

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:300?","pheader":""},"headers":{"as":"json"},"trace":"*"} (glob)

Optionally, set the p header. This value will be forwarded together with the request body to the node owning the key. Its value is returned in the response body in the pheader field:

$ tcurl pingchannel -P hosts.json /ping '{"key": "my_key"}' --headers '{"p": "my_header"}'
{"ok":true,"head":null,"body":{"message":"Hello, world!","from":"127.0.0.1:300?","pheader":"my_header"},"headers":{"as":"json"},"trace":"*"} (glob)

$ kill %1

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL