Skip to content

SqueueLite is a persistant queue based on SQLite completely written in Go

License

Notifications You must be signed in to change notification settings

nfoerster/squeuelite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

squeuelite - a persistent queue based on SQLite written in Go

Go

description

SQueueLite is a persistant queue based on SQLite. It uses a reliable persistent file-based battle-tested solution known as SQLite.

usage

subscriber mode

package squeuelite

//main routine
q, err := squeuelite.NewPQueue("test.db", 10)
if err != nil {
    log.Fatal(err)
}
defer q.Close()

err = q.Subscribe(func(m *PMessage) error {
        log.Printf("message received:%v",m.Data)
        errint := processMsg(m.Data) //your process function
        if errint != nil{
            //message will be marked as failed and not again delivered
            return err
        }
        //message will be deleted from persistent storage
		return nil
	})
if err != nil {
    log.Fatal(err)
}

//put routine
payload := []byte("Payload")
err = q.Put(payload)
if err != nil {
    log.Fatal(err)
}

manual mode

package squeuelite

//main routine
q, err := squeuelite.NewPQueue("test.db", 10)
if err != nil {
    log.Fatal(err)
}
defer q.Close()

payload := []byte("Payload")
err = q.Put(payload)
if err != nil {
    log.Fatal(err)
}

m, err := q.Peek()
if err != nil {
    log.Fatal(err)
}
log.Printf("message received:%v",m.Data)
err = processMsg(m.Data) //your process function
if err != nil{
    errint := q.MarkFailed(m.MessageID)
    if errint != nil{
        //handle db errors setting msg to fail
    }
} else {
    errint := q.Done(m.MessageID)
    if errint != nil{
        //handle db errors deleting completed msg
    }
}

contributors

related projects

Inital code was taken from https://github.com/litements/litequeue, which offers a persistent queue using SQLite in Python, translated to Go and adapted accordingly.

About

SqueueLite is a persistant queue based on SQLite completely written in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages