| # [START index] | |
| @app.route('/', methods=['GET', 'POST']) def index(): | |
| if request.method == 'GET': | |
| return render_template('index.html', messages=MESSAGES) | |
| data = request.form.get('payload', 'Example payload').encode('utf-8') | |
| publisher = pubsub_v1.PublisherClient() | |
| topic_path = publisher.topic_path( | |
| current_app.config['PROJECT'], | |
| current_app.config['PUBSUB_TOPIC']) | |
| publisher.publish(topic_path, data=data) | |
| return 'OK', 200 | |
| # [END index] |
Enter code here...
@app.route('/', methods=['GET', 'POST'])def index(): if request.method == 'GET': return 'OK', 200
data = request.form.get('payload', 'Example payload').encode('utf-8')
try: future = publish_client.publish(topic,data) message_id=future.result() print('Published. Google Pubsub message ID: {}.'.format(message_id)) return 'OK', 200 except Exception as e: print("Exception that occurred:", e) raise# [END index]--
You received this message because you are subscribed to the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/680df1b8-341e-44f8-8845-20b9ea7ac6c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kir Titievsky | Product Manager | Google Cloud Pub/Sub
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/680df1b8-341e-44f8-8845-20b9ea7ac6c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.