Compare commits
2 Commits
dbb9493bcb
...
60946af1df
Author | SHA1 | Date | |
---|---|---|---|
|
60946af1df
|
||
|
83990cf16a
|
@@ -125,16 +125,15 @@ impl MyceliumClient {
|
|||||||
Destination::Ip(ip) => json!({ "ip": ip.to_string() }),
|
Destination::Ip(ip) => json!({ "ip": ip.to_string() }),
|
||||||
Destination::Pk(pk) => json!({ "pk": pk }),
|
Destination::Pk(pk) => json!({ "pk": pk }),
|
||||||
};
|
};
|
||||||
let message = json!({
|
let mut message = json!({
|
||||||
"dst": dst_v,
|
"dst": dst_v,
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
"payload": payload_b64,
|
"payload": payload_b64,
|
||||||
});
|
});
|
||||||
let mut params = json!({ "message": message });
|
|
||||||
if let Some(rt) = reply_timeout {
|
if let Some(rt) = reply_timeout {
|
||||||
params["reply_timeout"] = json!(rt);
|
message["reply_timeout"] = json!(rt);
|
||||||
}
|
}
|
||||||
params
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
/// pushMessage: send a message with dst/topic/payload. Optional reply_timeout for sync replies.
|
/// pushMessage: send a message with dst/topic/payload. Optional reply_timeout for sync replies.
|
||||||
|
@@ -104,6 +104,10 @@ impl SupervisorClient {
|
|||||||
Ok(BASE64_STANDARD.encode(s.as_bytes()))
|
Ok(BASE64_STANDARD.encode(s.as_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn encode_topic(topic: &[u8]) -> String {
|
||||||
|
BASE64_STANDARD.encode(topic)
|
||||||
|
}
|
||||||
|
|
||||||
fn extract_message_id_from_result(result: &Value) -> Option<String> {
|
fn extract_message_id_from_result(result: &Value) -> Option<String> {
|
||||||
// Two possibilities per Mycelium spec oneOf:
|
// Two possibilities per Mycelium spec oneOf:
|
||||||
// - PushMessageResponseId: { "id": "0123456789abcdef" }
|
// - PushMessageResponseId: { "id": "0123456789abcdef" }
|
||||||
@@ -120,7 +124,12 @@ impl SupervisorClient {
|
|||||||
let payload_b64 = Self::encode_payload(&inner)?;
|
let payload_b64 = Self::encode_payload(&inner)?;
|
||||||
let result = self
|
let result = self
|
||||||
.mycelium
|
.mycelium
|
||||||
.push_message(&self.destination, &self.topic, &payload_b64, None)
|
.push_message(
|
||||||
|
&self.destination,
|
||||||
|
&Self::encode_topic(self.topic.as_bytes()),
|
||||||
|
&payload_b64,
|
||||||
|
None,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(id) = MyceliumClient::extract_message_id_from_result(&result) {
|
if let Some(id) = MyceliumClient::extract_message_id_from_result(&result) {
|
||||||
|
Reference in New Issue
Block a user