This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from webapp2 import Route, WSGIApplication, RequestHandler | |
import ujson | |
import urllib | |
import base64 | |
import logging | |
class Handler(RequestHandler): | |
def post(self): | |
message = ujson.decode(urllib.unquote(self.request.body).rstrip('='))['message'] | |
attributes = message.get('attributes', {}) | |
data = message.get('data', {}) | |
try: | |
print "data >>", data | |
print "b64decode >>", base64.b64decode(str(message['data'])) | |
print "+" * 72 | |
except Exception as e: | |
print logging.exception(e) | |
def get(self): | |
return self.post() | |
application = WSGIApplication(debug=True, routes=[Route('/', Handler)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile extending the generic Python image with application files for a single application. | |
FROM ubuntu:latest | |
# First we install https transportation for APT. Indeed skewed.de forces https. | |
RUN apt-get update | |
RUN apt-get install -y \ | |
python-pip | |
ADD requirements /tmp/requirements | |
RUN pip install --upgrade pip | |
RUN pip install -r /tmp/requirements | |
ENV GCLOUD_PROJECT my-project | |
ENV GOOGLE_APPLICATION_CREDENTIALS my-cred.json | |
ADD . /app | |
WORKDIR /app | |
CMD gunicorn -b :8080 consumer:application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile extending the generic Python image with application files for a single application. | |
FROM ubuntu:latest | |
# First we install https transportation for APT. Indeed skewed.de forces https. | |
RUN apt-get update | |
RUN apt-get install -y \ | |
python-pip | |
ADD requirements /tmp/requirements | |
RUN pip install --upgrade pip | |
RUN pip install -r /tmp/requirements | |
ENV GCLOUD_PROJECT my-project | |
ENV GOOGLE_APPLICATION_CREDENTIALS my-cred.json | |
ADD . /app | |
WORKDIR /app | |
CMD python producer.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gcloud import pubsub | |
import ujson | |
if __name__ == '__main__': | |
client = pubsub.Client() | |
topic = client.topic('debug-topic') | |
if not topic.exists(): | |
topic.create() | |
subscription = pubsub.subscription.Subscription(name='debug-subscription', topic=topic, push_endpoint='https://my-tunnel.ngrok.io/') | |
if not subscription.exists(): | |
subscription.create() | |
batch = topic.batch() | |
for i in range(10): | |
batch.publish(ujson.encode({'a_string': 'my-val', 'an_int': i}), an_attr=str('a value')) | |
batch.commit() | |
print('topic {0}'.format(topic)) | |
print('subscription {0}'.format(subscription)) | |
print('message_ids {0}'.format(batch.message_ids)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcloud==0.18.3 | |
gunicorn==19.4.5 | |
webapp2==2.5.2 | |
WebOb==1.5.1 | |
Paste==2.0.3 | |
ujson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment