lega911 / ijson

Inverted json - lightweight and blazing fast message-broker
MIT License
149 stars 12 forks source link

Inverted Json

Inverted Json is a job server which helps you to organize RPC, MQ, PubSub communication between clients and workers. It helps to save time and resources.

Benchmark

Performance

Memory usage, CPU usage, Multi-core result

Try Inverted Json in 5 min

Example

Here we:

  1. Start Inverted Json
  2. A worker publishes a command
  3. A client invokes the command
  4. The worker responds to the client

read more, an article

Start ijson

docker run -it -p 8001:8001 lega911/ijson

Example with curl (client + worker)

# 1. a worker requests for a command (task) "test/command"
curl localhost:8001/test/command -H 'type: get'

# 2. a client invokes the command
curl localhost:8001/test/command -d '{"id": 123, "params": "test data"}'

# the worker receives {"id": 123, "params": "test data"}
# 3. and sends response with the same id
curl localhost:8001 -H 'type: result' -d '{"id": 123, "result": "data received"}'

# client receives {"id": 123, "result": "data received"}

Python client

response = requests.post('http://127.0.0.1:8001/test/command', json={'id': 1, 'params': 'Hello'})
print(response.json())

Python worker

while True:
    # get a request
    request = requests.post('http://127.0.0.1:8001/test/command', headers={'Type': 'get'}).json()

    # send a response
    response = {
        'id': request['id'],
        'result': request['params'] + ' world!'
    }
    requests.post('http://127.0.0.1:8001/', json=response, headers={'Type': 'result'})