Git Product home page Git Product logo

techtalk_pubsub's Introduction

TechTalk - Maio/ Junho /2020

Projeto para demonstracao das funcionalidade do PUBSUB com Python Autor : Claudio Lisboa Referencias: https://cloud.google.com/pubsub/docs

Projeto PYTHON para demonstração de consumo API Google PubSub

Preparacao do Ambiente GCP Desenvolvimento. Versao 1.00- 30/05/2020 Google Cloub Pub/Sub Pyhton configuracao de ambiente


Preparando o ambiente para execucao local.

Referência: https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu

Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk
Inicializar o SDK

Use o comando abaixo para executar várias tarefas comuns de configuração do SDK. entre elas: autorizar as ferramentas do SDK a acessar o Google Cloud Platform usando as credenciais da sua conta de usuário e definir a configuração padrão do SDK.

Para iniciar o SDK:

gcloud init
Definindo o projeto DEFAULT
gcloud config set project projeto-pubsub

Exportar a chave de servico para funcionar as autenticacoes: https://cloud.google.com/docs/authentication/getting-started

Este passo é importante para configurar o local da chave de segurança IAM para autenticação das ferramentas do google
export GOOGLE_APPLICATION_CREDENTIALS="/home/lisboa/cglsoft/gcp_Carrefour/key.json"

PYTHON INSTALL UBUNTU CONFIGURATION

Step 1: Update your repositories
sudo apt-get update
Step 2: Install pip for Python 3
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
sudo apt install python3-pip
Step 3: Use pip to install virtualenv
sudo pip3 install virtualenv
Step 4: Launch your Python 3 virtual environment, here the name of my virtual environment will be env3
virtualenv -p python3 env3
Step 5: Activate your new Python 3 environment. There are two ways to do this
. env3/bin/activate #####  or source env3/bin/activate which does exactly the same thing
you can make sure you are now working with Python 3
python -- version
this command will show you what is going on: the python executable you are using is now located inside your virtualenv repository
which python
Step 6: code your stuff
Step 7: done? leave the virtual environment

Acessar o Terminal e preparar o ambiente para testar a solucao:
Criar diretorio para simular os testes:

Criacao do ambiente virtual PYTHON

python -m virtualenv env

Ativar o ambiente virtual

source env/bin/activate

Instalacao biblioteca Pub/Sub PYTHON

pip install --upgrade google-cloud-pubsub

Comandos SHELL para verificar os tópicos

gcloud pubsub topics create my-topic
gcloud pubsub subscriptions create my-sub --topic my-topic

Comandos pubsub Listar topicos e subscriptions

gcloud pubsub topics list
gcloud pubsub subscriptions list
gcloud info
Execucao em dois terminais diferentes para validar a solução de publicação e consumo de informações:
TOPIC - Testes

Check com os programas Publisher e Subscriber - Python:

python publisher3.py projeto-pubsub my-topic
SUBSCRIBER - Testes
python subscriber.py projeto-pubsub my-topic

Comandos gerais PubSub

Comandos terminal para PUB/SUB para apagar Subscriptions e TOPIC

gcloud pubsub subscriptions delete my-sub
gcloud pubsub topics delete my-topic

Author

Claudio Lisboa

License

Copyright © 2008-2020, CGLSOFT Desenvolvimento. Released under the MIT License.


techtalk_pubsub's People

Watchers

Claudio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.