def publish_message(client, args):
    topic = get_full_topic_name(args.project_name, args.topic)
    message = base64.b64encode(str(args.message))
    body = {'messages': [{'data': message}]}
    resp = client.projects().topics().publish(
        topic=topic, body=body).execute(num_retries=NUM_RETRIES)
    print ('Published a message "{}" to a topic {}. The message_id was {}.'
           .format(args.message, topic, resp.get('messageIds')[0]))
Publish a message to a given topic.
dataset/ETHPy150Open GoogleCloudPlatform/cloud-pubsub-samples-python/cmdline-pull/pubsub_sample.py/publish_message