Git Product home page Git Product logo

notifications-via-rabbitmq's Introduction

Notifications via RabbitMQ

Simple little notifications utility that takes messages from RabbitMQ direct exchange and sends them either to phone (Pushover) or email (SendGrid).

Run

docker compose up

Environment Variables

Key Description
RABBITMQ https://www.rabbitmq.com/
RABBITMQ_HOST Address to the RabbitMQ host, e.g localhost
RABBITMQ_PORT The port that RabbitMQ is running on, default 5672
RABBITMQ_USER The name of the user with which to connect to RabbitMQ
RABBITMQ_PASS The password of the RabbitMQ user
PUSHOVER https://pushover.net/
PUSHOVER_API_KEY The Pushover API key. Found in the control panel
PUSHOVER_USER_KEY Your Pushover user key. Found in the control panel
SENDGRID https://sendgrid.com/
SENDGRID_API_KEY SendGrid API key, created in SendGrid control panel
FROM_EMAIL The email that is listed as sender.

Sending notifications

import os
import dotenv
import pika

dotenv.load_dotenv()

RABBITMQ_HOST = os.getenv("RABBITMQ_HOST")
RABBITMQ_PORT = os.getenv("RABBITMQ_PORT")
RABBITMQ_USERNAME = os.getenv("RABBITMQ_USER")
RABBITMQ_PASSWORD = os.getenv("RABBITMQ_PASS")

connection = pika.BlockingConnection(
    pika.ConnectionParameters(
        host=RABBITMQ_HOST,
        port=RABBITMQ_PORT,
        credentials=pika.PlainCredentials(
            username=RABBITMQ_USERNAME,
            password=RABBITMQ_PASSWORD
        )
    )
)
channel = connection.channel()
channel.exchange_declare(exchange="notifications", exchange_type="direct")

# Send your notification to Pushover
channel.basic_publish(
    exchange="notifications",
    routing_key="phone",
    body=f'{{"body": "Hello World"}}'
)

# Send your notification via email
channel.basic_publish(
    exchange="notifications",
    routing_key="email",
    body=f'{{"recipient": "[email protected]", "subject": "Hello World", "body": "This is a test notification"}}'
)

notifications-via-rabbitmq's People

Contributors

magnuhar avatar dependabot[bot] avatar

Watchers

 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.