forked from kayleg/cloud-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_message.rs
More file actions
34 lines (30 loc) · 921 Bytes
/
send_message.rs
File metadata and controls
34 lines (30 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use cloud_pubsub::Client;
use serde_derive::Deserialize;
use std::sync::Arc;
#[derive(Deserialize)]
struct Config {
topic: String,
google_application_credentials: String,
}
#[tokio::main]
async fn main() {
let parsed_env = envy::from_env::<Config>();
if let Err(e) = parsed_env {
eprintln!("ENV is not valid: {}", e);
std::process::exit(1);
}
let config = parsed_env.unwrap();
let pubsub = match Client::new(config.google_application_credentials).await {
Err(e) => panic!("Failed to initialize pubsub: {}", e),
Ok(p) => Arc::new(p),
};
let topic = Arc::new(pubsub.topic(config.topic.clone()));
match topic.clone().publish("🔥").await {
Ok(response) => {
println!("{:?}", response);
pubsub.stop();
std::process::exit(0);
}
Err(e) => eprintln!("Failed sending message {}", e),
}
}