mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Something is ok
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
use crate::web::proxyhttp::{BGService, GetHost, LB};
|
||||
use crate::web::proxyhttp::{BGService, LB};
|
||||
use dashmap::DashMap;
|
||||
use pingora_core::prelude::background_service;
|
||||
use pingora_core::server::Server;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
/*
|
||||
pub fn run1() {
|
||||
let mut upstreams = LoadBalancer::try_from_iter(vec!["192.168.1.10:8000", "192.168.1.1:8000", "127.0.0.1:8000"]).unwrap();
|
||||
@@ -31,27 +34,19 @@ pub fn run() {
|
||||
let mut server = Server::new(None).unwrap();
|
||||
server.bootstrap();
|
||||
|
||||
// let backends = Backends::new(Box::new(SD));
|
||||
// let load_balancer = LoadBalancer::from_backends(backends);
|
||||
// load_balancer.set_health_check(TcpHealthCheck::new());
|
||||
// load_balancer.health_check_frequency = Some(Duration::from_secs(1));
|
||||
// load_balancer.update_frequency = Some(Duration::from_secs(1));
|
||||
|
||||
// let background = background_service("load balancer", load_balancer);
|
||||
|
||||
let upstreams_map: DashMap<String, (Vec<(String, u16)>, AtomicUsize)> = DashMap::new();
|
||||
let config = Arc::new(RwLock::new(upstreams_map)); // Wrap in Arc<RwLock<...>>
|
||||
|
||||
let mut ll = LB { upstreams_map };
|
||||
let lb = LB { upstreams_map: config.clone() }; // Share the Arc<RwLock<...>>
|
||||
let bg_service = BGService { upstreams_map: config.clone() }; // Share the Arc<RwLock<...>>
|
||||
|
||||
let bg_service = background_service("bgsrvc", BGService {});
|
||||
let background = background_service("load balancer", ll.discover_hosts());
|
||||
background.task();
|
||||
let bg_srvc = background_service("bgsrvc", bg_service);
|
||||
bg_srvc.task();
|
||||
|
||||
let mut lb = pingora_proxy::http_proxy_service(&server.configuration, ll);
|
||||
|
||||
lb.add_tcp("0.0.0.0:6193");
|
||||
server.add_service(lb);
|
||||
server.add_service(bg_service);
|
||||
let mut proxy = pingora_proxy::http_proxy_service(&server.configuration, lb);
|
||||
proxy.add_tcp("0.0.0.0:6193");
|
||||
server.add_service(proxy);
|
||||
server.add_service(bg_srvc);
|
||||
|
||||
server.run_forever();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user