Skip to content

Instantly share code, notes, and snippets.

@claudiokc
Created August 30, 2018 21:40
Show Gist options
  • Save claudiokc/2128c980746c0b1d5a44196771127e6a to your computer and use it in GitHub Desktop.
Save claudiokc/2128c980746c0b1d5a44196771127e6a to your computer and use it in GitHub Desktop.
#########
from google.cloud import pubsub_v1
from django.conf import settings
import os
import json
profile = os.path.join(settings.BASE_DIR, 'pubsub/service_account_profile.json')
search = os.path.join(settings.BASE_DIR, 'pubsub/service_account_search.json')
publisher = pubsub_v1.PublisherClient.from_service_account_file(profile)
messages_element = {'data': json.dumps({
'profileId':'001',
'programId':'0002',
'pathwayId':'11'
}).encode()}
messages = [messages_element]
topic_path = publisher.topic_path('liu-profile-api-qa', 'complete-pathway')
publisher.publish(topic_path, messages)
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path('liu-search-api-dev', 'newsindexing')
data = u'Di algo: {}'.format('hola mundo').encode('utf-8')
publisher.publish(topic_path, data=data)
########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment