Skip to content

Small, user-friendly library for consuming PGQ from Go.

License

Notifications You must be signed in to change notification settings

furdarius/pgqgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Build Status Go Report Card

PGQ consuming from Go

Small, user-friendly library for consuming PGQ.

Install

go get github.com/furdarius/pgqgo

Adding as dependency by "go dep"

$ dep ensure -add github.com/furdarius/pgqgo

Usage

Usage example:

// LogProcessor used to output received batch id, it's size and data.
// Implements pgqgo.BatchProcessor.
type LogProcessor struct{}

// Process consequentially output to stdout each events data from batch.
func (p *LogProcessor) Process(ctx context.Context, batchID int, events []pgqgo.Event) ([]pgqgo.RetryEvent, error) {
	log.Printf("batch received: batch_id = %d, size = %d\n", batchID, len(events))

	for _, event := range events {
		fmt.Println(event)
	}

	return nil, nil
}

func main() {
	db, _ := sql.Open("postgres", "postgres:https://postgres:[email protected]:5432/postgres?sslmode=disable")

	// Create consumer with batch processor.
	processor := &LogProcessor{}
	consumer := pgqgo.NewConsumer(db, processor, "consumer_name")

	queue := "queue_name"
	
	err = consumer.Register(ctx, queue)
	if err != nil && err != pgqgo.ErrAlreadyExists {
		log.Fatalf("failed to register pgq consumer: %v", err)
	}

	err = consumer.Start(ctx, queue)
	if err != nil && err != context.Canceled {
		log.Fatalf("failed to start pgq consumer: %v", err)
	}
}

More examples here

About

Small, user-friendly library for consuming PGQ from Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages