Git Product home page Git Product logo

eureka-rs's Introduction

Eureka Client for Rust

This project is currently in an alpha state as indicated by the version number.

TODO

  • async support
  • auth support
  • examples

What Works

  • Registering a service with Eureka
  • Sending keep-alive heartbeats to Eureka
  • Re-registering after Eureka restarting

What is implemented but untested

  • Making requests to services connected via Eureka

What is not implemented

  • DNS and AWS resolvers

Installation

Add eureka-client to your Cargo.toml and add extern crate eureka_client to your project's root.

Usage

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.

License

MIT

eureka-rs's People

Contributors

armersong avatar fengyc avatar shssoichiro avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.