Function fleetspeak::send

source ·
pub fn send(message: Message)
Expand description

Sends the message to the Fleetspeak server.

The data is delivered to the server-side service as specified by the message and optionally tagged with a type if specified. This optional message type is irrelevant for Fleetspeak but might be useful for the service the message is delivered to.

In case of any I/O failure or malformed message (e.g. due to encoding problems), an error is reported.

Examples

use fleetspeak::Message;

fleetspeak::send(Message {
    service: String::from("example"),
    kind: None,
    data: String::from("Hello, world!").into_bytes(),
});
Examples found in repository?
examples/hello.rs (lines 19-23)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() {
    fleetspeak::startup("0.0.1");

    loop {
        let packet = fleetspeak::receive_with_heartbeat(Duration::from_secs(1));

        let request = std::str::from_utf8(&packet.data).unwrap();
        let response = format!("Hello, {}!", request);

        fleetspeak::send(Message {
            service: String::from("greeter"),
            kind: None,
            data: response.into_bytes(),
        });
    }
}