SQueueLite is a persistant queue based on SQLite. It uses a reliable persistent file-based battle-tested solution known as SQLite.
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)
}
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
}
}
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.