This crate provides access to a set of strongly typed apis to interact with consul (https://www.consul.io/)
Simply include the rs-consul in your Cargo dependencies.
[dependencies]
rs-consul = "0.9.0"
Check /examples for more detailed usage
The client can be configured automatically using environment variables:
use rs_consul::{types::*, Config, Consul};
let consul_config = Config::from_env();
let consul = Consul::new(consul_config);
Alternatively, you can configure the client manually:
let consul_config = Config {
address: "http://localhost:8500".to_string(),
token: None, // No token required in development mode
..Default::default() // Uses default values for other settings
};
let consul = Consul::new(consul_config);
let node_id = "root-node"; //node name
let service_name = "new-service-1"; //service name
let payload = RegisterEntityPayload {
ID: None,
Node: node_id.to_string(),
Address: "127.0.0.1".to_string(), //server address
Datacenter: None,
TaggedAddresses: Default::default(),
NodeMeta: Default::default(),
Service: Some(RegisterEntityService {
ID: None,
Service: service_name.to_string(),
Tags: vec![],
TaggedAddresses: Default::default(),
Meta: Default::default(),
Port: Some(42424),
Namespace: None,
}),
Check: None,
SkipNodeUpdate: None,
};
consul.register_entity(&payload).await.unwrap();
let node_id = "root-node";
let service_name = "new-service-1";
let payload = DeregisterEntityPayload {
Node: Some(node_id.to_string()),
Datacenter: None,
CheckID: None,
ServiceID: Some(service_name.to_string()),
Namespace: None,
};
consul.deregister_entity(&payload).await.unwrap();
cargo build
Start consul locally with a docker image.
docker-compose up -d
In CI, we start a service container for the test.
cargo test
For contributions, please:
- Make a pull request
- Make sure the tests pass
- Add a bullet to the Changelog
rs-consul is available under the MIT license. See LICENSE for details.