1
1
use std:: { collections:: HashMap , sync:: Arc } ;
2
2
3
+ use google_cloud_gax:: conn:: Environment ;
3
4
use google_cloud_googleapis:: pubsub:: v1:: PubsubMessage ;
4
5
use google_cloud_pubsub:: {
5
6
client:: { Client , ClientConfig } ,
@@ -48,6 +49,9 @@ pub fn writer_loop(
48
49
retry_policy : & retry:: Policy ,
49
50
ordering_key : & str ,
50
51
attributes : & GenericKV ,
52
+ emulator : bool ,
53
+ emulator_endpoint : & Option < String > ,
54
+ emulator_project_id : & Option < String > ,
51
55
utils : Arc < Utils > ,
52
56
) -> Result < ( ) , crate :: Error > {
53
57
let rt = tokio:: runtime:: Builder :: new_current_thread ( )
@@ -56,7 +60,16 @@ pub fn writer_loop(
56
60
. build ( ) ?;
57
61
58
62
let publisher: Publisher = rt. block_on ( async {
59
- let client = Client :: new ( ClientConfig :: default ( ) ) . await ?;
63
+ let client_config = if emulator {
64
+ ClientConfig {
65
+ project_id : Some ( emulator_project_id. clone ( ) . unwrap_or_default ( ) ) ,
66
+ environment : Environment :: Emulator ( emulator_endpoint. clone ( ) . unwrap_or_default ( ) ) ,
67
+ ..Default :: default ( )
68
+ }
69
+ } else {
70
+ ClientConfig :: default ( )
71
+ } ;
72
+ let client = Client :: new ( client_config) . await ?;
60
73
let topic = client. topic ( topic_name) ;
61
74
Result :: < _ , crate :: Error > :: Ok ( topic. new_publisher ( None ) )
62
75
} ) ?;
0 commit comments