Skip to content

muhammadolammi/gonotify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📨 GoNotify

GoNotify is a lightweight, modular notification system written in Go — designed to handle publishing, consuming, and analyzing notifications efficiently using RabbitMQ and PostgreSQL.

You can run it as standalone services (Publisher, Consumer, Analytics), or import it directly into your own Go programs.


🚀 Features

  • 🧩 Modular architecture (Publisher, Consumer, Analytics)
  • 📬 RabbitMQ integration for reliable message queues
  • 💾 PostgreSQL integration with SQLC
  • 📊 Analytics mode for tracking and insights
  • 📨 Email (SMTP) and SMS (Twilio) delivery support
  • 🧰 Reusable as a Go library

🗂️ Project Structure

gonotify/
├── cmd/
│ ├── analytics/ # Analytics CLI
│ ├── consumer/ # Consumer CLI
│ └── publisher/ # Publisher CLI
├── internal/
│ ├── config/ # Database + environment logic
│ └── database/ # SQLC generated queries
├── pkg/
│ └── notify/ # Reusable notification logic
├── sql/
│ ├── queries/
│ └── schema/
└── sqlc.yaml

⚙️ Installation

To install :

git clone github.com/muhammadolammi/gonotify
cd gonotify

🏃‍♂️ Run as CLI

  1. Publisher

Runs a pool of publisher workers that push messages to RabbitMQ.

go run ./cmd/publisher

💡 You can modify your listener logic by editing the testListenerWorker in cmd/publisher.

  1. Consumer

Consumes messages and handles email/SMS delivery.

go run ./cmd/consumer
  1. Analytics

Provides analytics and query access to stored notifications.

go run ./cmd/analytics -command <cmd> -get-limit <n> -email <email> -phone <number>

Examples:

go run ./cmd/analytics 

This will get and print all notifications in db.

go run ./cmd/analytics -command=get -get-limit=50 

Get all notifications and limit to 50

go run ./cmd/analytics -command=get -get-limit=50 -email=user@example.com

Filter the result by email and limit to 50

go run ./cmd/analytics -command=get -get-limit=50 -phone=+123456789

Filter the result by phone and limit to 50

go run ./cmd/analytics -command=get -email=user@example.com -phone=+123456789

Filter the result by phone and email with no limit

go run ./cmd/analytics -command=get -get-limit=50 -phone=+123456789 -email=user@example.com

Filter the result by phone and email and limit to 50

go run ./cmd/analytics -command=clear 

Delete all notifications in db

All CLI programs load .env variables automatically.

🔧 Environment Variables

Create a .env file in the root directory with the following:

DB_URL=postgres://user:password@localhost:5432/notifydb?sslmode=disable
RABBITMQ_URL=amqp://guest:guest@localhost:5672/
PUBLISHER_POOL=2
CONSUMER_POOL=2

# SMTP (for email)
SMTP_SERVER=smtppro.zoho.com:587 #or your server
SMTP_USERNAME=your_email@example.com
SMTP_PASSWORD=your_password

# Twilio (for SMS)
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MESSAGING_SERVICE_SID=xxxxxxxxxxxxxxxxxxxx
TWILLIO_SENDER_NUMBER=+1234567890

💻 Use as a Library

You can also import and use GoNotify directly inside your Go applications.

Add to your project

go get github.com/muhammadolammi/gonotify@latest

Or with a specific version

go get github.com/muhammadolammi/gonotify@vx.x.x

Example: Publisher

package main

import (
	"log"
	"sync"

	"github.com/muhammadolammi/gonotify/pkg/config"
	"github.com/muhammadolammi/gonotify/pkg/notify"
)

func publisherListener(id int, config *notify.PublisherConfig, wg *sync.WaitGroup){
    // TODO: Replace with your own listener logic.
}
func main() {
	publisherConfig, err := config.InitPublisherConfig()
	if err != nil {
		log.Println("error getting publisher config:", err)
		return
	}

	// Start a listener pool
	publisherConfig.StartPublisherListenerPool(
		publisherConfig.NumPools,
		publisherListener,
	)

	// Or publish directly
	publisherConfig.PublishMessage(notify.Notification{})
}

Example: Consumer

consumerConfig, err := config.InitConsumerConfig()
if err != nil {
	log.Println("error initializing consumer config:", err)
	return
}

consumerConfig.StartConsumerWorkerPool(consumerConfig.NumPools)

Example: Analytics

analyticsConfig, err := config.InitAnalyticsConfig()
if err != nil {
	log.Println("error initializing analytics config:", err)
	return
}

analyticsGetConfig := notify.GetNotificationsConfig{}
analyticsConfig.GetNotifications(analyticsGetConfig)

🧠 Architecture Overview

Publisher → Sends notifications into RabbitMQ

Consumer → Listens for messages and sends via email/SMS

Analytics → Reads and aggregates stored notifications

Each service is independent but shares the same database and queue backend.

📄 License

MIT © Muhammad Olammi

💬 Feedback

Got ideas, suggestions, or issues? Open an issue or start a discussion on GitHub Issues

About

A go package to send notifications.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages