Skip to content

Commit 8ce4142

Browse files
Merge pull request #187 from code0-tech/186-configurable-grpc-host
Configurable grpc host
2 parents 8de3900 + 5972c86 commit 8ce4142

File tree

6 files changed

+57
-52
lines changed

6 files changed

+57
-52
lines changed

.env

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
REDIS_URL='redis://localhost:6379'
21
ENVIRONMENT='development'
32
MODE='static'
3+
NATS_URL='nats://localhost:4222'
4+
NATS_BUCKET='flow_store'
45
RUNTIME_TOKEN="<token>"
5-
FLOW_FALLBACK_PATH='./flow/test_flow_one.json'
6+
FLOW_FALLBACK_PATH='../flow/test_flow_one.json'
7+
GRPC_HOST='127.0.0.1'
8+
GRPC_PORT=8081
9+
WITH_HEALTH_SERVICE=false
10+
SAGITTARIUS_URL='http://localhost:50051'

.env-example

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
REDIS_URL='redis://localhost:6379'
2-
ENVIRONMENT='development'
3-
MODE='static'
1+
ENVIRONMENT='production'
2+
MODE='dynamic'
3+
4+
NATS_URL='nats://localhost:4222'
5+
NATS_BUCKET='flow_store'
6+
47
RUNTIME_TOKEN="<token>"
5-
FLOW_FALLBACK_PATH='../flow/test_flow_one.json'
8+
FLOW_FALLBACK_PATH='./path/to/flow.json'
9+
10+
GRPC_HOST='127.0.0.1'
11+
GRPC_PORT=50051
12+
13+
WITH_HEALTH_SERVICE=false
14+
15+
SAGITTARIUS_URL='http://localhost:50051'

docker-compose.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/.env

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/configuration/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ pub struct Config {
3232
/// URL to the `Sagittarius` Server.
3333
pub backend_url: String,
3434

35+
// Port of the `Aquila` Server
3536
pub grpc_port: u16,
37+
38+
// Host of the `Aquila` Server
39+
pub grpc_host: String,
40+
41+
pub with_health_service: bool,
3642
}
3743

3844
/// Implementation for all relevant `Aquila` startup configurations
@@ -57,8 +63,10 @@ impl Config {
5763
String::from("../flow/test_flow_one.json"),
5864
),
5965
grpc_port: env_with_default("GRPC_PORT", 8081),
66+
grpc_host: env_with_default("GRPC_HOST", String::from("127.0.0.1")),
67+
with_health_service: env_with_default("WITH_HEALTH_SERVICE", false),
6068
runtime_token: env_with_default("RUNTIME_TOKEN", String::from("default_session_token")),
61-
backend_url: env_with_default("BACKEND_URL", String::from("http://localhost:8080")),
69+
backend_url: env_with_default("SAGITTARIUS_URL", String::from("http://localhost:50051")),
6270
}
6371
}
6472

src/server/mod.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ pub struct AquilaGRPCServer {
2727
sagittarius_url: String,
2828
nats_url: String,
2929
address: SocketAddr,
30+
with_health_service: bool,
3031
}
3132

3233
impl AquilaGRPCServer {
3334
pub fn new(config: &Config) -> Self {
34-
let address = match format!("127.0.0.1:{}", config.grpc_port).parse() {
35+
let address = match format!("{}:{}", config.grpc_host, config.grpc_port).parse() {
3536
Ok(addr) => {
3637
info!("Listening on {:?}", &addr);
3738
addr
@@ -43,55 +44,61 @@ impl AquilaGRPCServer {
4344
token: config.runtime_token.clone(),
4445
sagittarius_url: config.backend_url.clone(),
4546
nats_url: config.nats_url.clone(),
47+
with_health_service: config.with_health_service,
4648
address,
4749
}
4850
}
4951

50-
pub async fn start(&self) -> std::result::Result<(), tonic::transport::Error> {
52+
pub async fn start(&self) -> Result<(), tonic::transport::Error> {
5153
let data_type_service = SagittariusDataTypeServiceClient::new_arc(
5254
self.sagittarius_url.clone(),
5355
self.token.clone(),
5456
)
5557
.await;
5658

57-
log::info!("DataTypeService started");
59+
info!("DataTypeService started");
5860

5961
let flow_type_service = SagittariusFlowTypeServiceClient::new_arc(
6062
self.sagittarius_url.clone(),
6163
self.token.clone(),
6264
)
6365
.await;
6466

65-
log::info!("FlowTypeService started");
67+
info!("FlowTypeService started");
6668

6769
let runtime_function_service = SagittariusRuntimeFunctionServiceClient::new_arc(
6870
self.sagittarius_url.clone(),
6971
self.token.clone(),
7072
)
7173
.await;
7274

73-
log::info!("RuntimeFunctionService started");
74-
75-
let health_service = code0_flow::flow_health::HealthService::new(self.nats_url.clone());
76-
log::info!("HealthService started");
75+
info!("RuntimeFunctionService started");
7776

7877
let data_type_server = AquilaDataTypeServiceServer::new(data_type_service.clone());
7978
let flow_type_server = AquilaFlowTypeServiceServer::new(flow_type_service.clone());
8079
let runtime_function_server =
8180
AquilaRuntimeFunctionServiceServer::new(runtime_function_service.clone());
8281

83-
log::info!("Starting gRPC Server...");
82+
info!("Starting gRPC Server...");
83+
84+
if self.with_health_service {
85+
info!("Starting with HealthService");
86+
let health_service = code0_flow::flow_health::HealthService::new(self.nats_url.clone());
8487

85-
Server::builder()
86-
.add_service(tonic_health::pb::health_server::HealthServer::new(
87-
health_service,
88-
))
89-
.add_service(DataTypeServiceServer::new(data_type_server))
90-
.add_service(FlowTypeServiceServer::new(flow_type_server))
91-
.add_service(RuntimeFunctionDefinitionServiceServer::new(
92-
runtime_function_server,
93-
))
94-
.serve(self.address)
95-
.await
88+
Server::builder()
89+
.add_service(tonic_health::pb::health_server::HealthServer::new(health_service))
90+
.add_service(DataTypeServiceServer::new(data_type_server))
91+
.add_service(FlowTypeServiceServer::new(flow_type_server))
92+
.add_service(RuntimeFunctionDefinitionServiceServer::new(runtime_function_server))
93+
.serve(self.address)
94+
.await
95+
} else {
96+
97+
Server::builder()
98+
.add_service(DataTypeServiceServer::new(data_type_server))
99+
.add_service(FlowTypeServiceServer::new(flow_type_server))
100+
.add_service(RuntimeFunctionDefinitionServiceServer::new(runtime_function_server)).serve(self.address)
101+
.await
102+
}
96103
}
97104
}

0 commit comments

Comments
 (0)