imapmq

:inbox_tray: IMAP based message broker client

  • 所有者: mikaa123/imapmq
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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

主要指標

概覽
名稱與所有者mikaa123/imapmq
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-10-22 13:00:25
推送於2016-11-04 14:47:58
最后一次提交2016-11-04 15:01:40
發布數0
用户参与
星數274
關注者數8
派生數4
提交數12
已啟用問題?
問題數2
打開的問題數2
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?