Skip to content

Commit

Permalink
Simplify Service Discovery by decoupling the service registry from in…
Browse files Browse the repository at this point in the history
…tent brokering (#141)

Service Discovery as its own service - Simple implementation
  • Loading branch information
ladatz authored Jun 29, 2023
1 parent db9bb92 commit d8375a8
Show file tree
Hide file tree
Showing 18 changed files with 1,011 additions and 4 deletions.
88 changes: 86 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[workspace]
members = [
"common",
Expand All @@ -15,10 +19,11 @@ members = [
"examples/common",
"keyvalue",
"proto.rs",
"service_discovery/core",
"service_discovery/samples/simple-discovery/consumer",
"service_discovery/samples/simple-discovery/provider"
]

exclude = []

[package]
name = "chariott"
version = "0.1.0"
Expand Down Expand Up @@ -55,6 +60,7 @@ chariott-common = { path = "./common/" }
chariott-proto = { path = "./proto.rs/" }
futures = { version = "0.3" }
lazy_static = "1.4.0"
parking_lot = "0.12.1"
prost = "0.11"
prost-types = "0.11"
regex = "1.7"
Expand Down
21 changes: 21 additions & 0 deletions service_discovery/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[package]
name = "service_discovery"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
parking_lot = { workspace = true }
prost = { workspace = true }
service_discovery_proto = { path = "../proto_build/"}
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tonic = { workspace = true }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[build-dependencies]
tonic-build = { workspace = true }
52 changes: 52 additions & 0 deletions service_discovery/core/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

//! Project Eclipse Chariott Service Discovery
//!
//! This is the Service Discovery system for Chariott. It includes a service registry,
//! which is a database of services that are currently registered. Other applications
//! can find the metadata for registered services.
// Tells cargo to warn if a doc comment is missing and should be provided.
#![warn(missing_docs)]

use parking_lot::RwLock;
use service_discovery_proto::service_registry::v1::service_registry_server::ServiceRegistryServer;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use tonic::transport::Server;
use tracing::{debug, info};
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

mod service_registry_impl;

/// Endpoint for the service registry
const SERVICE_REGISTRY_ADDR: &str = "0.0.0.0:50000";

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set up tracing
let collector = tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(tracing::Level::INFO.into())
.from_env_lossy(),
)
.finish();

collector.init();

// Start up registry service
let addr: SocketAddr = SERVICE_REGISTRY_ADDR.parse()?;
let registry_impl =
service_registry_impl::ServiceRegistryImpl::new(Arc::new(RwLock::new(HashMap::new())));
info!("Service Registry listening on {addr}");

Server::builder().add_service(ServiceRegistryServer::new(registry_impl)).serve(addr).await?;

debug!("The Service Registry has completed.");
Ok(())
}
Loading

0 comments on commit d8375a8

Please sign in to comment.