Skip to content

Commit 9c5eac9

Browse files
committed
Publish events to RabbitMQ queue if events-rabbitmq feature is enabled.
1 parent 7feca16 commit 9c5eac9

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

ldk-server/ldk-server.config

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@
1818
"bitcoind_rpc_user": "polaruser",
1919

2020
// Bitcoin Core's RPC password.
21-
"bitcoind_rpc_password": "polarpass"
21+
"bitcoind_rpc_user": "polarpass",
22+
23+
// RabbitMQ connection string. (only required if using RabbitMQ based events using `events-rabbitmq` feature)
24+
"rabbitmq_connection_string": "",
25+
26+
// RabbitMQ exchange name. (only required if using RabbitMQ based events using `events-rabbitmq` feature)
27+
"rabbitmq_exchange_name": ""
28+
2229
}

ldk-server/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use hyper_util::rt::TokioIo;
1515

1616
use crate::io::events::event_publisher::{EventPublisher, NoopEventPublisher};
1717
use crate::io::events::get_event_name;
18+
#[cfg(feature = "events-rabbitmq")]
19+
use crate::io::events::rabbitmq::{RabbitMqConfig, RabbitMqEventPublisher};
1820
use crate::io::persist::paginated_kv_store::PaginatedKVStore;
1921
use crate::io::persist::sqlite_store::SqliteStore;
2022
use crate::io::persist::{
@@ -106,6 +108,15 @@ fn main() {
106108

107109
let event_publisher: Arc<dyn EventPublisher> = Arc::new(NoopEventPublisher);
108110

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

ldk-server/src/util/config.rs

Lines changed: 20 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.
@@ -114,6 +130,8 @@ mod tests {
114130
"bitcoind_rpc_address":"127.0.0.1:8332", // comment-1
115131
"bitcoind_rpc_user": "bitcoind-testuser",
116132
"bitcoind_rpc_password": "bitcoind-testpassword",
133+
"rabbitmq_connection_string": "rabbitmq_connection_string",
134+
"rabbitmq_exchange_name": "rabbitmq_exchange_name",
117135
"unknown_key": "random-value"
118136
// comment-2
119137
}"#;
@@ -130,6 +148,8 @@ mod tests {
130148
bitcoind_rpc_addr: SocketAddr::from_str("127.0.0.1:8332").unwrap(),
131149
bitcoind_rpc_user: "bitcoind-testuser".to_string(),
132150
bitcoind_rpc_password: "bitcoind-testpassword".to_string(),
151+
rabbitmq_connection_string: "rabbitmq_connection_string".to_string(),
152+
rabbitmq_exchange_name: "rabbitmq_exchange_name".to_string(),
133153
}
134154
)
135155
}

0 commit comments

Comments
 (0)