File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
appengine/flexible/pubsub Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 35
35
# Global list to storage messages received by this instance.
36
36
MESSAGES = []
37
37
38
+ # Initialize the publisher client once to avoid memory leak
39
+ # and reduce publish latency.
40
+ publisher = pubsub_v1 .PublisherClient ()
38
41
39
42
# [START gae_flex_pubsub_index]
40
43
@app .route ('/' , methods = ['GET' , 'POST' ])
@@ -44,9 +47,7 @@ def index():
44
47
45
48
data = request .form .get ('payload' , 'Example payload' ).encode ('utf-8' )
46
49
47
- # Consider initialzing the publisher client outside this function
48
- # for low latency publish.
49
- publisher = pubsub_v1 .PublisherClient ()
50
+ # publisher = pubsub_v1.PublisherClient()
50
51
topic_path = publisher .topic_path (
51
52
current_app .config ['PROJECT' ],
52
53
current_app .config ['PUBSUB_TOPIC' ])
You can’t perform that action at this time.
0 commit comments