girolle
Description
A nameko-rpc like lib in rust. Check the To-Do section to see limitation.
Do not use in production!
Girolle use Nameko architecture to send request and get response.
Documentation
User documentation and Rust documentation
Installation
cargo add girolle
Stack
Girolle use lapin as an AMQP client/server library.
Configuration
There is two way to create a configuration. The first one is to use the Config::with_yaml_defaults function that will read a configuration from
a YAML file, see example. The second one is to create a configuration by hand.
Create a configuration from a yaml file
The configuration is done by a yaml file. It should be compliant with a Nameko one. The file should look like this:
AMQP_URI: 'amqp://toto:super@$172.16.1.1:5672//'
rpc_exchange: 'nameko-rpc'
max_workers: 10
parent_calls_tracked: 10
In this example:
- The
AMQP_URIis the connection string to the RabbitMQ server. - The
rpc_exchangeis the exchange name for the rpc calls. - The
max_workersis the max number of workers that will be created to handle the rpc calls. - The
parent_calls_trackedis the number of parent calls that will be tracked by the service.
Create a configuration by hand
let conf = default_config;
conf.with_amqp_uri
.with_rpc_exchange
.with_max_workers
.with_parent_calls_tracked;
Environment variables
The configuration supports the expansion of the environment variables with the
following syntax ${VAR_NAME}. Like in this example:
AMQP_URI: 'amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@${RABBITMQ_HOST}:${RABBITMQ_PORT}/%2f'
rpc_exchange: 'nameko-rpc'
max_workers: 10
parent_calls_tracked: 10
How to use it
The core concept is to remove the pain of the queue creation and reply by
mokcing the Nameko architecture with a RpcService or RpcClient, and to
use an abstract type serde_json::Value to manipulate a serializable data.
if you do not use the macro #[girolle] you need to create a function that
extract the data from the a &[Value] like this:
Exemple
Create a simple service
use *;
// Because the function is recursive, it need to be wrap in a function
Create multiple calls to service of methods, sync and async
use *;
use vec;
use ;
async
To-Do
- Handle the error
- write test
- create a proxy service in rust to interact with an other service nameko-rpc
- Add macro to simplify the creation of a service
- Add basic macro
- fix macro to handle
return - fix macro to handle recursive function
- listen to a pub/sub queue
Limitation
The current code as been tested with the nameko and girolle examples in this repository.
| nameko_test.py | simple_senders | |
|---|---|---|
| simple_service | x | x |
| nameko_service | x | x |
| simple_macro | x | x |
Benchmark
The benchmark is done to test the overhead of the macro.