Crates.io | eureka-client |
lib.rs | eureka-client |
version | 0.0.4 |
source | src |
created_at | 2018-03-21 22:02:18.805209 |
updated_at | 2018-09-21 15:11:02.938891 |
description | Handles HTTP requests to and registering a service with Eureka |
homepage | |
repository | https://github.com/shssoichiro/eureka-rs |
max_upload_size | |
id | 56801 |
size | 33,363 |
This project is currently in an alpha state as indicated by the version number.
Add eureka-client
to your Cargo.toml
and add extern crate eureka_client
to your project's root.
To initialize a eureka client and register with eureka, you'll do something similar to this:
use eureka::{BaseConfig, EurekaClient, PortData};
pub fn init_eureka(
server_host: String,
server_port: u16,
instance_ip_addr: String,
instance_port: u16,
) -> EurekaClient {
let mut config = BaseConfig::default();
config.eureka.host = server_host;
config.eureka.port = server_port;
config.instance.ip_addr = instance_ip_addr;
config.instance.port = Some(PortData::new(instance_port, true));
let eureka = EurekaClient::new(config);
eureka.start();
eureka
}
You'll need to keep this client alive for as long as you intend to be connected to Eureka. For example, in Rocket, you can manage it as state and access it via your routes as you would with other state, e.g. calling our above function:
rocket::ignite()
.mount("/api/", routes![])
.manage(init_eureka(
dotenv!("EUREKA_HOST").into(),
dotenv!("EUREKA_PORT")
.parse()
.expect("Eureka port not valid"),
env::var("EUREKA_INSTANCE_IP").unwrap_or_else(|_| "127.0.0.1".to_string()),
env::var("ROCKET_PORT")
.map_err(|_| ())
.and_then(|port| port.parse().map_err(|_| ()))
.unwrap_or(8080),
))
This client registers with eureka by default. You can disable registration by setting config.eureka.register_with_eureka = false
if you just want to use this client to make requests.