imapmq

:inbox_tray: IMAP based message broker client

  • Owner: mikaa123/imapmq
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownermikaa123/imapmq
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2016-10-22 13:00:25
Pushed At2016-11-04 14:47:58
Last Commit At2016-11-04 15:01:40
Release Count0
用户参与
Stargazers Count274
Watchers Count8
Fork Count4
Commits Count12
Has Issues Enabled
Issues Count2
Issue Open Count2
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private