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

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DBQueue-Go

DBQueue-Go is a simple, lightweight queue system based on various SQL databases, implemented in Go. It supports MySQL, PostgreSQL, and SQLite, allowing for easy integration with existing database infrastructures.

🚀 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

Opening a Database Connection

To work with DBQueue-Go, you need to open a connection to your preferred SQL database engine:

postgresqlEngine, _ := dbqueue.OpenPostgreSQL(ctx, "host=localhost user=foo password=bar dbname=baz port=5432 sslmode=disable")
mysqlEngine, _ := dbqueue.OpenMySQL(ctx, "foo:bar@tcp(127.0.0.1:3306)/baz")
sqliteEngine, _ := dbqueue.OpenSQLite(ctx, "foo.db")

Creating a Queue

Create a new queue using the engine:

queue, _ := postgresqlEngine.CreateQueue(ctx, "my_queue")

Sending Messages

To send a message to the queue:

_ = queue.SendMessage(ctx, &types.Message{
    Payload:  []byte("Hello, world!"),
    Priority: 1,
})

Sending Messages in Batch

You can also send multiple messages at once:

_ = queue.SendMessageBatch(ctx, []*types.Message{
    {Payload: []byte("Message 1"), Priority: 1},
    {Payload: []byte("Message 2"), Priority: 1},
})

Receiving Messages

Receive messages from the queue:

_ = queue.ReceiveMessage(ctx, func(message types.ReceivedMessage) {
    fmt.Println("Received message:", string(message.Payload))
}, &types.ReceiveMessageOptions{
    MaxNumberOfMessages: common.Ptr(10),
    VisibilityTimeout:   common.Ptr(30 * time.Second),
    WaitTime:            common.Ptr(5 * time.Second),
})

Deleting Messages

Delete a specific message from the queue:

_ = queue.DeleteMessage(ctx, messageID)

You can also delete multiple messages at once:

_ = queue.DeleteMessageBatch(ctx, []uint{messageID1, messageID2})

Changing Message Visibility

Change the visibility timeout of a message:

_ = queue.ChangeMessageVisibility(ctx, messageID, time.Minute*5)

This can also be done in batch:

_ = queue.ChangeMessageVisibilityBatch(ctx, []uint{messageID1, messageID2}, time.Minute*5)

Deleting a Queue

Delete a queue if it is no longer needed:

_ = engineInstance.DeleteQueue(ctx, "my_queue")

Purging a Queue

Purge all messages from a queue:

_ = engineInstance.PurgeQueue(ctx, "my_queue")

🤝 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

Issues

If you encounter any bugs or have suggestions for improvements, please feel free to open an issue. Your feedback is invaluable and helps us improve the project.

Pull Requests

We welcome pull requests for new features, bug fixes, or documentation improvements. Here’s how you can contribute:

📜 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