Coder Social home page Coder Social logo

theg6284 / streaming-03-rabbitmq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denisecase/streaming-03-rabbitmq

0.0 0.0 0.0 1.95 MB

Get started with RabbitMQ, a message broker, that enables multiple processes to communicate reliably through an intermediary

Python 100.00%

streaming-03-rabbitmq's Introduction

streaming-03-rabbitmq

Get started with RabbitMQ, a message broker, that enables multiple processes to communicate reliably through an intermediary

Before You Begin

  1. Fork this starter repo into your GitHub.
  2. Clone your repo down to your machine.
  3. In VS Code with Python extension, click on emit_message_v1.py to get VS Code in Python mode.
  4. View / Command Palette - then Python: Select Interpreter
  5. Select your conda environment. See the references below for more.
  6. Use the terminal to install pika into your active environment.

conda install -c conda-forge pika

Read

  1. Read the RabbitMQ Tutorial - Hello, World!
  2. Read the code and comments in this repo.

Execute about,py

  1. Run about.py.
  2. Read about.txt.
  3. Verfiy you have exactly one active, one None env.

Version 1 - Execute the Producer/Sender

  1. Read v1_emit_message.py (and the tutorial)
  2. Run the file.

You'll need to fix an error in the program to get it to run. Once it runs and finishes, we can reuse the terminal.

Version 1 - Execute the Consumer/Listener

  1. Read v1_listen_for_messages.py (and the tutorial)
  2. Run the file.

You'll need to fix an error in the program to get it to run. Once it runs successfully, will it terminate on its own? How do you know? As long as the process is running, we cannot use this terminal for other commands.

Version 1 - Open a New Terminal / Emit More Messages

  1. Open a new terminal window.
  2. Use this new window to emit more messages
  3. In v1_emit_message.py, modify the message.
  4. Execute the script.
  5. Watch what happens in the listening window.
  6. Do this several times to emit at least 3 different messages.

Version 1: Don't Repeat Yourself (DRY)

  1. Did you notice you had to change the message in two places?
    1. You update the actual message sent.
    2. You also update what is displayed to the user.
  2. Fix this by introducting a variable to hold the message.
    1. Use your variable when sending.
    2. Use the variable again when displaying to the user.

To send a new message, you'll only make one change. Updating and improving code is called 'refactoring'. Use your skills to keep coding enjoyable.

Version 2

Now look at the second version of each file. These include more graceful error handling, and a consistent, reusable approach to building code.

Each of the version 2 programs include an error as well.

  1. Find the error and fix it.
  2. Compare the structure of the version 2 files.
  3. Modify the docstrings on all your files.
  4. Include your name and the date.
  5. Imports always go at the top, just after the file docstring.
  6. Imports should be one per line - why?
  7. Then, define your functions.
  8. Functions are reuable logic blocks.
  9. Everything the function needs comes in through the arguments.
  10. A function may - or may not - return a value.
  11. When we open a connection, we should close the connection.
  12. Which of the 4 files will always close() the connection?
  13. Search GitHub for if name == "main":
  14. How many hits did you get?
  15. Learn and understand this common Python idiom.

Reference

Multiple Terminals

My screenshot

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.