streadway / amqp

Go client for AMQP 0.9.1
http://godoc.org/github.com/streadway/amqp
BSD 2-Clause "Simplified" License
4.88k stars 621 forks source link

Add package-wide example usage #368

Closed harrisonturton closed 5 years ago

harrisonturton commented 6 years ago

This adds an example Queue implementation. It features:

I could add auto-ack stuff through Consume function with a func(d Delivery) bool handler function, like:

func (queue *Queue) Consume(handler func(d Delivery) bool) {
    for {
        msg <- messages
        if handler(msg) {
             msg.Ack(false)
        }
    }
}

But this makes it harder to use the queue, especially with complex client logic. Manually acking outgoing messages isn't difficult, so I left it.

I had some trouble with GoDoc. I simply want to display the Queue file, but I was forced to include an Example() function. This is a bit annoying, but it works.

Happy to refactor is need be. I know there is an _examples directory, but GoDoc wouldn't let me put the package-wide example there.

lukebakken commented 6 years ago

@michaelklishin if you have a second to review this it would be appreciated.

michaelklishin commented 5 years ago

I'd like to make some edits (these docs use some non-standard and potentially confusing terminology) but they can happen after the merge. Thank you.

streadway commented 5 years ago

@harrisonturton can you link to the online examples that leaked goroutines?

streadway commented 5 years ago

@lukebakken @harrisonturton This example has a number of data races, writes from handleReconnect and reads from other methods. Can you please make it output something and test the output so data races can be caught from CI?