Skip to content

Commit c0c4ff7

Browse files
committed
Publish events to RabbitMQ queue if events-rabbitmq feature is enabled.
1 parent 769799d commit c0c4ff7

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

ldk-server/ldk-server.config

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
// Bitcoin Core's RPC endpoint.
1515
"bitcoind_rpc_address": "127.0.0.1:18444",
1616

17-
// Bitcoin Core's RPC user.
18-
"bitcoind_rpc_user": "polaruser",
17+
// RabbitMQ connection string. (only required if using RabbitMQ based events using `events-rabbitmq` feature)
18+
"rabbitmq_connection_string": "",
19+
20+
// RabbitMQ exchange name. (only required if using RabbitMQ based events using `events-rabbitmq` feature)
21+
"rabbitmq_exchange_name": ""
1922

20-
// Bitcoin Core's RPC password.
21-
"bitcoind_rpc_password": "polarpass"
2223
}

ldk-server/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use hyper::server::conn::http1;
1414
use hyper_util::rt::TokioIo;
1515

1616
use crate::io::events::event_publisher::{EventPublisher, NoopEventPublisher};
17+
#[cfg(feature = "events-rabbitmq")]
18+
use crate::io::events::rabbitmq::{RabbitMqConfig, RabbitMqEventPublisher};
1719
use crate::io::persist::paginated_kv_store::PaginatedKVStore;
1820
use crate::io::persist::sqlite_store::SqliteStore;
1921
use crate::io::persist::{
@@ -103,6 +105,15 @@ fn main() {
103105

104106
let event_publisher: Arc<dyn EventPublisher> = Arc::new(NoopEventPublisher);
105107

108+
#[cfg(feature = "events-rabbitmq")]
109+
let event_publisher: Arc<dyn EventPublisher> = {
110+
let rabbitmq_config = RabbitMqConfig {
111+
connection_string: config_file.rabbitmq_connection_string,
112+
exchange_name: config_file.rabbitmq_exchange_name,
113+
};
114+
Arc::new(RabbitMqEventPublisher::new(rabbitmq_config))
115+
};
116+
106117
println!("Starting up...");
107118
match node.start_with_runtime(Arc::clone(&runtime)) {
108119
Ok(()) => {},

ldk-server/src/util/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct Config {
1616
pub bitcoind_rpc_addr: SocketAddr,
1717
pub bitcoind_rpc_user: String,
1818
pub bitcoind_rpc_password: String,
19+
pub rabbitmq_connection_string: String,
20+
pub rabbitmq_exchange_name: String,
1921
}
2022

2123
impl TryFrom<JsonConfig> for Config {
@@ -45,6 +47,16 @@ impl TryFrom<JsonConfig> for Config {
4547
)
4648
})?;
4749

50+
#[cfg(feature = "events-rabbitmq")]
51+
if json_config.rabbitmq_connection_string.as_deref().map_or(true, |s| s.is_empty())
52+
|| json_config.rabbitmq_exchange_name.as_deref().map_or(true, |s| s.is_empty())
53+
{
54+
return Err(io::Error::new(
55+
io::ErrorKind::InvalidInput,
56+
"Both `rabbitmq_connection_string` and `rabbitmq_exchange_name` must be configured if enabling `events-rabbitmq` feature.".to_string(),
57+
));
58+
}
59+
4860
Ok(Config {
4961
listening_addr,
5062
network: json_config.network,
@@ -53,6 +65,8 @@ impl TryFrom<JsonConfig> for Config {
5365
bitcoind_rpc_addr,
5466
bitcoind_rpc_user: json_config.bitcoind_rpc_user,
5567
bitcoind_rpc_password: json_config.bitcoind_rpc_password,
68+
rabbitmq_connection_string: json_config.rabbitmq_connection_string.unwrap_or_default(),
69+
rabbitmq_exchange_name: json_config.rabbitmq_exchange_name.unwrap_or_default(),
5670
})
5771
}
5872
}
@@ -67,6 +81,8 @@ pub struct JsonConfig {
6781
bitcoind_rpc_address: String,
6882
bitcoind_rpc_user: String,
6983
bitcoind_rpc_password: String,
84+
rabbitmq_connection_string: Option<String>,
85+
rabbitmq_exchange_name: Option<String>,
7086
}
7187

7288
/// Loads the configuration from a JSON file at the given path.
@@ -130,6 +146,8 @@ mod tests {
130146
bitcoind_rpc_addr: SocketAddr::from_str("127.0.0.1:8332").unwrap(),
131147
bitcoind_rpc_user: "bitcoind-testuser".to_string(),
132148
bitcoind_rpc_password: "bitcoind-testpassword".to_string(),
149+
rabbitmq_connection_string: "".to_string(),
150+
rabbitmq_exchange_name: "".to_string(),
133151
}
134152
)
135153
}

0 commit comments

Comments
 (0)