mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
broker bin using rumqtt
This commit is contained in:
1
broker/.gitignore
vendored
Normal file
1
broker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
12
broker/Cargo.toml
Normal file
12
broker/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "sphinx-key-broker"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rumqttd = "0.11.0"
|
||||||
|
pretty_env_logger = "0.4.0"
|
||||||
|
confy = "0.4.0"
|
||||||
|
tokio = "1.18"
|
||||||
28
broker/config/rumqttd.conf
Normal file
28
broker/config/rumqttd.conf
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Broker id. Used to identify local node of the replication mesh
|
||||||
|
id = 0
|
||||||
|
|
||||||
|
# A commitlog read will pull full segment. Make sure that a segment isn't
|
||||||
|
# too big as async tcp writes readiness of one connection might affect tail
|
||||||
|
# latencies of other connection. Not a problem with preempting runtimes
|
||||||
|
[router]
|
||||||
|
id = 0
|
||||||
|
dir = "/tmp/rumqttd"
|
||||||
|
max_segment_size = 10240
|
||||||
|
max_segment_count = 10
|
||||||
|
max_connections = 10001
|
||||||
|
|
||||||
|
# Configuration of server and connections that it accepts
|
||||||
|
[servers.1]
|
||||||
|
listen = "0.0.0.0:1883"
|
||||||
|
next_connection_delay_ms = 1
|
||||||
|
[servers.1.connections]
|
||||||
|
connection_timeout_ms = 5000
|
||||||
|
max_client_id_len = 256
|
||||||
|
throttle_delay_ms = 0
|
||||||
|
max_payload_size = 5120
|
||||||
|
max_inflight_count = 200
|
||||||
|
max_inflight_size = 1024
|
||||||
|
login_credentials = [ { username = "sphinx-key", password = "sphinx-key-pass" } ]
|
||||||
|
|
||||||
|
[console]
|
||||||
|
listen = "0.0.0.0:3030"
|
||||||
47
broker/src/main.rs
Normal file
47
broker/src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use librumqttd::{async_locallink::construct_broker, Config};
|
||||||
|
use std::thread;
|
||||||
|
use tokio::time::{sleep, Duration};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("start!");
|
||||||
|
pretty_env_logger::init();
|
||||||
|
let config: Config = confy::load_path("config/rumqttd.conf").expect("no conf file");
|
||||||
|
|
||||||
|
let (mut router, console, servers, builder) = construct_broker(config);
|
||||||
|
|
||||||
|
println!("start router now");
|
||||||
|
thread::spawn(move || {
|
||||||
|
router.start().expect("could start broker");
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut runtime = tokio::runtime::Builder::new_multi_thread();
|
||||||
|
runtime.enable_all();
|
||||||
|
runtime
|
||||||
|
.build()
|
||||||
|
.expect("tokio Builder failed")
|
||||||
|
.block_on(async {
|
||||||
|
let (mut tx, _) = builder
|
||||||
|
.connect("localclient", 200)
|
||||||
|
.await
|
||||||
|
.expect("couldnt connect");
|
||||||
|
|
||||||
|
let console_task = tokio::spawn(console);
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
for i in 0..10usize {
|
||||||
|
sleep(Duration::from_millis(1000)).await;
|
||||||
|
let topic = "hello/world";
|
||||||
|
tx.publish(topic, false, vec![i as u8; 1]).await.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
println!("await now");
|
||||||
|
|
||||||
|
servers.await;
|
||||||
|
// pub_task.await.expect("FAIL pub task");
|
||||||
|
// sub_task.await.expect("FAIL sub task");
|
||||||
|
console_task.await.expect("FAIL console task");
|
||||||
|
|
||||||
|
println!("YOYO");
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
pub fn say_hi() {
|
pub fn say_hi() {
|
||||||
println!("hi from signer module!");
|
println!("hi from signer module!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user