Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A library that implements the outboxer pattern in go

License

NotificationsYou must be signed in to change notification settings

italolelis/outboxer

Repository files navigation

Build StatuscodecovGo Report CardGoDoc

Outboxer is a go library that implements theoutbox pattern.

Getting Started

Outboxer simplifies the challenging work of orchestrating message reliability. Essentially we are trying to solve this question:

How can producers reliably send messages when the broker/consumer is unavailable?

If you have a distributed system architecture and especially mainly dealwithEvent Driven Architecture, you mightwant to useoutboxer.

The first thing to do is include the package in your project.

go get github.com/italolelis/outboxer

Usage

Let's setup a simple example where you are using Google'sPubSub andPostgres as your outbox pattern components:

ctx,cancel:=context.WithCancel(context.Background())defercancel()db,err:=sql.Open("postgres",os.Getenv("DS_DSN"))iferr!=nil {fmt.Printf("could not connect to amqp: %s",err)return}// we need to create a data store instance firstds,err:=postgres.WithInstance(ctx,db)iferr!=nil {fmt.Printf("could not setup the data store: %s",err)return}deferds.Close()// we create an event stream passing the pusub connectionclient,err:=pubsub.NewClient(ctx,os.Getenv("GCP_PROJECT_ID"))iferr!=nil {fmt.Printf("failed to connect to gcp: %s",err)return}es:=pubsubOut.New(client)// now we create an outboxer instance passing the data store and event streamo,err:=outboxer.New(outboxer.WithDataStore(ds),outboxer.WithEventStream(es),outboxer.WithCheckInterval(1*time.Second),outboxer.WithCleanupInterval(5*time.Second),outboxer.WithCleanUpBefore(time.Now().AddDate(0,0,-5)),)iferr!=nil {fmt.Printf("could not create an outboxer instance: %s",err)return}// here we initialize the outboxer checks and cleanup go rotineso.Start(ctx)defero.Stop()// finally we are ready to send messagesiferr=o.Send(ctx,&outboxer.OutboxMessage{Payload: []byte("test payload"),Options:map[string]interface{}{amqpOut.ExchangeNameOption:"test",amqpOut.ExchangeTypeOption:"topic",amqpOut.RoutingKeyOption:"test.send",    },});err!=nil {fmt.Printf("could not send message: %s",err)return}// we can also listen for errors and ok messages that were sendfor {select {caseerr:=<-o.ErrChan():fmt.Printf("could not send message: %s",err)case<-o.OkChan():fmt.Printf("message received")return    }}

Features

Outboxer comes with a few implementations of Data Stores and Event Streams.

Data Stores

Event Streams

Contributing

Please readCONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see theLICENSE file for details

About

A library that implements the outboxer pattern in go

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp