Skip to content

Database based FIFO queue implementation with the support of Deduplication, Priority and VisibilityTimeout in Go

License

Notifications You must be signed in to change notification settings

yunussandikci/dbqueue-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbqueue-go

dbqueue-go is a simple, lightweight queue system based on various of sql databases, implemented in Go.

🚀 Getting Started

To start using dbqueue-go, simply run the following command in your terminal:

go get github.com/yunussandikci/dbqueue-go

Then, import the dbqueue package in your Go file:

import "github.com/yunussandikci/dbqueue-go/dbqueue"

🎉 Usage

Creating an Instance

sqliteQueue, err := dbqueue.NewSQLite("foo.db")
mysqlQueue, err := dbqueue.NewMySQL("foo:bar@tcp(127.0.0.1:3306)/baz")
postgresqlQueue, err := dbqueue.NewPostgreSQL("host=localhost user=foo password=bar dbname=baz port=5432 sslmode=disable")

Creating the Queue

err := dbqueue.CreateQueue("my_queue")

The CreateQueue function takes one argument:

  • name: The name of the queue to be created.

Sending Messages

message := &dbqueue.Message{
    Payload: []byte("Hello, world!"),
}

err := dbqueue.SendMessage("my_queue", message)

The SendMessage function takes two arguments:

  • queue: The name of the queue to which the message will be sent.
  • message: The message to be sent. It's an instance of the Message struct.

Receiving Messages

options := &dbqueue.ReceiveMessageOptions{
    MaxNumberOfMessages: 10,
    VisibilityTimeout:   time.Minute * 10,
    WaitTime:            time.Second * 5,
}

err := dbqueue.ReceiveMessage("my_queue", func(message dbqueue.Message) {
    fmt.Println(string(message.Payload))
}, options)

The ReceiveMessage function takes three arguments:

  • queue: The name of the queue from which the messages will be received.
  • f: A function that will be called for each received message. It takes a Message as an argument.
  • options: An instance of the ReceiveMessageOptions struct that specifies options for receiving messages.

Deleting Messages

err := dbqueue.DeleteMessage("my_queue", "message_id")

The DeleteMessage function takes two arguments:

  • queue: The name of the queue from which the message will be deleted.
  • messageId: The ID of the message to be deleted.

Purging a Queue

err := dbqueue.PurgeQueue("my_queue")

The PurgeQueue function takes one argument:

  • queue: The name of the queue to be purged.

Changing Message Visibility

err := dbqueue.ChangeMessageVisibility("my_queue", time.Minute*5, "message_id")

The ChangeMessageVisibility function takes three arguments:

  • queue: The name of the queue that contains the message.
  • visibilityTimeout: The new visibility timeout for the message.
  • messageId: The ID of the message whose visibility will be changed.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Database based FIFO queue implementation with the support of Deduplication, Priority and VisibilityTimeout in Go

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published