Skip to content

Commit 14c7212

Browse files
committed
Fix implementation of discovery message
Has been wrong the whole time, and so was the test...
1 parent 7b071cc commit 14c7212

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"mocha": "^2.4.5",
3232
"amqplib": "^0.4.2",
3333
"mqtt": "1.4.x",
34-
"msgflo": "^0.7.6"
34+
"msgflo": "^0.8.0"
3535
}
3636
}

src/participant.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ impl InfoBuilder {
6464
}
6565
}
6666

67+
#[derive(Debug, RustcDecodable, RustcEncodable, Clone)]
68+
struct DiscoveryMessage {
69+
pub payload: Info,
70+
pub command: String,
71+
pub protocol: String,
72+
}
73+
74+
impl DiscoveryMessage {
75+
pub fn new(info: Info) -> DiscoveryMessage {
76+
DiscoveryMessage {
77+
protocol: "discovery".to_string(),
78+
command: "participant".to_string(),
79+
payload: info,
80+
}
81+
}
82+
}
83+
6784
pub trait Participant : Sync {
6885
fn info(&self) -> Info;
6986
fn process(&self, Vec<u8>) -> Result<Vec<u8>, Vec<u8>>;
@@ -94,7 +111,8 @@ fn create_queue_and_send(channel: &mut Channel, queue_name: &str, payload: Strin
94111
fn send_discovery(channel: &mut Channel, info: &Info) {
95112
let queue_name = "fbp"; // TODO: use an exchange istead, requires protocol change in msgflo
96113

97-
let payload = json::encode(&info).unwrap();
114+
let msg = DiscoveryMessage::new(info.clone());
115+
let payload = json::encode(&msg).unwrap();
98116
create_queue_and_send(channel, queue_name, payload);
99117
info!("sent participant discovery: {} {}({})", info.id, info.role, info.component);
100118
}

0 commit comments

Comments
 (0)