Coder Social home page Coder Social logo

imapmq's Introduction

IMAPMQ is an IMAP based message broker client. It provides a simple interface for publishing, subscribing and dequeuing messages. It also supports concurrent access to the same message queue. Based on go-imap.

Go Report Card GoDoc

How it works

IMAPMQ treats IMAP mailboxes as queues. In order to add a message to a queue, IMAPMQ appends an email to the mailbox.

Features

  • IMAPMQ can connect to any IMAPv4rev1 server with the CONDSTORE extension
  • Publish/Subscribe
  • Message Queue
  • Message format agnostic
  • No polling, the IMAP server notifies the client of new messages thanks to the IDLE command
  • Concurrency aware: multiple dequeuing instances can work on the same queue
  • Bring your own GUI: any IMAP client would do

Installing

$ go get github.com/mikaa123/imapmq

Example: A simple chat

The following example connects to an IMAP account, and creates a queue based on the INBOX mailbox. It spawns a goroutine that subscribes to the "chat" topic and listens to the returned channel. Anytime a user writes something and press enter, a new "chat" message is published to the queue.

You need to have an IMAP server to connect to. If you don't, you can create a gmail account. Make sure you enable IMAP (more info here) if you do.

package main

import (
	"bufio"
	"log"
	"os"

	"github.com/mikaa123/imapmq"
)

func main() {
	// Create a new IMAPMQ client
	mq, err := imapmq.New(imapmq.Config{
		Login: "login",
		Passwd: "password",
		URL: "imap.gmail.com",
	})
	if err != nil {
		log.Panic(err)
	}
	defer mq.Close()

	// Create a queue based on INBOX
	q, err := mq.Queue("INBOX")
	if err != nil {
		log.Panic(err)
	}

	go func() {
		// Subscribe to messages with the "chat" subject
		c := q.Sub("chat")
		for msg := range c { // msg is a mail.Message instance.
			log.Printf("%s", msg.Header.Get("Subject"))
		}
	}()

	// We scan stdin for user input
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		// Publish a message with the "chat" subject in the INBOX queue
		q.Pub("chat", []byte(scanner.Text()))
	}
}

Documentation

https://godoc.org/github.com/mikaa123/imapmq

License

MIT © Michael Sokol

imapmq's People

Contributors

mikaa123 avatar

Watchers

Willem 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.