-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtonic.rs
33 lines (28 loc) · 1.04 KB
/
tonic.rs
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
use std::env;
use google_api_proto::google::pubsub::v1::{publisher_client::PublisherClient, ListTopicsRequest};
use google_authz::GoogleAuthz;
use tonic::{
transport::{Channel, ClientTlsConfig},
Request,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
let project = env::args().nth(1).expect("cargo run --bin tonic -- <GCP_PROJECT_ID>");
let channel = Channel::from_static("https://pubsub.googleapis.com")
.tls_config(ClientTlsConfig::new().with_native_roots())?
.connect()
.await?;
let channel = GoogleAuthz::new(channel).init().await?;
let mut client = PublisherClient::new(channel);
let response = client
.list_topics(Request::new(ListTopicsRequest {
project: format!("projects/{}", project),
page_size: 10,
..Default::default()
}))
.await?;
println!("response = {:#?}", response);
Ok(())
}