Skip to content

Commit cbef6fc

Browse files
committed
migrate to kafka properties file
1 parent d5b9371 commit cbef6fc

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ TIPS_INGRESS_ADDRESS=0.0.0.0
33
TIPS_INGRESS_PORT=8080
44
TIPS_INGRESS_RPC_MEMPOOL=http://localhost:2222
55
TIPS_INGRESS_DUAL_WRITE_MEMPOOL=false
6-
TIPS_INGRESS_KAFKA_BROKERS=localhost:9092
7-
TIPS_INGRESS_KAFKA_TOPIC=tips-audit
6+
TIPS_INGRESS_KAFKA_INGRESS_PROPERTIES_FILE=/app/docker/ingress-kafka-properties
7+
TIPS_INGRESS_KAFKA_INGRESS_TOPIC=tips-ingress-rpc
88
TIPS_INGRESS_LOG_LEVEL=info
9-
TIPS_INGRESS_KAFKA_QUEUE_TOPIC=tips-ingress-rpc
109
TIPS_INGRESS_SEND_TRANSACTION_DEFAULT_LIFETIME_SECONDS=10800
1110

1211
# Audit service configuration

crates/ingress-rpc/src/main.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use jsonrpsee::server::Server;
44
use op_alloy_network::Optimism;
55
use rdkafka::ClientConfig;
66
use rdkafka::producer::FutureProducer;
7+
use std::fs;
78
use std::net::IpAddr;
89
use tracing::{info, warn};
910
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@@ -35,24 +36,16 @@ struct Config {
3536
dual_write_mempool: bool,
3637

3738
/// Kafka brokers for publishing mempool events
38-
#[arg(long, env = "TIPS_INGRESS_KAFKA_BROKERS")]
39-
kafka_brokers: String,
40-
41-
/// Kafka topic for publishing mempool events
42-
#[arg(
43-
long,
44-
env = "TIPS_INGRESS_KAFKA_TOPIC",
45-
default_value = "mempool-events"
46-
)]
47-
kafka_topic: String,
39+
#[arg(long, env = "TIPS_INGRESS_KAFKA_INGRESS_PROPERTIES_FILE")]
40+
ingress_kafka_properties: String,
4841

4942
/// Kafka topic for queuing transactions before the DB Writer
5043
#[arg(
5144
long,
52-
env = "TIPS_INGRESS_KAFKA_QUEUE_TOPIC",
45+
env = "TIPS_INGRESS_KAFKA_INGRESS_TOPIC",
5346
default_value = "tips-ingress-rpc"
5447
)]
55-
queue_topic: String,
48+
ingress_topic: String,
5649

5750
#[arg(long, env = "TIPS_INGRESS_LOG_LEVEL", default_value = "info")]
5851
log_level: String,
@@ -106,12 +99,22 @@ async fn main() -> anyhow::Result<()> {
10699
.network::<Optimism>()
107100
.connect_http(config.mempool_url);
108101

109-
let queue_producer: FutureProducer = ClientConfig::new()
110-
.set("bootstrap.servers", &config.kafka_brokers)
111-
.set("message.timeout.ms", "5000")
112-
.create()?;
102+
let kafka_properties = fs::read_to_string(&config.ingress_kafka_properties)?;
103+
let mut client_config = ClientConfig::new();
104+
105+
for line in kafka_properties.lines() {
106+
let line = line.trim();
107+
if line.is_empty() || line.starts_with('#') {
108+
continue;
109+
}
110+
if let Some((key, value)) = line.split_once('=') {
111+
client_config.set(key.trim(), value.trim());
112+
}
113+
}
114+
115+
let queue_producer: FutureProducer = client_config.create()?;
113116

114-
let queue = KafkaQueuePublisher::new(queue_producer, config.queue_topic);
117+
let queue = KafkaQueuePublisher::new(queue_producer, config.ingress_topic);
115118

116119
let service = IngressService::new(
117120
provider,

docker-compose.tips.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
- "8080:8080"
99
env_file:
1010
- .env.docker
11+
volumes:
12+
- ./docker/ingress-kafka-properties:/app/docker/ingress-kafka-properties:ro
1113
restart: unless-stopped
1214

1315
audit:

docker/ingress-kafka-properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kafka configuration properties for ingress service
2+
bootstrap.servers=host.docker.internal:9092
3+
message.timeout.ms=5000

0 commit comments

Comments
 (0)