diff --git a/consumer_test.go b/consumer_test.go index 48a4a3b..7142760 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -12,7 +12,7 @@ import ( func ExampleDialer_Consumer() { // open connection - dialer, _ := amqpextra.NewDialer(amqpextra.WithURL("amqp://guest:guest@localhost:5672/%2f")) + d, _ := amqpextra.NewDialer(amqpextra.WithURL("amqp://guest:guest@localhost:5672/%2f")) h := consumer.HandlerFunc(func(ctx context.Context, msg amqp.Delivery) interface{} { // process message @@ -21,17 +21,16 @@ func ExampleDialer_Consumer() { return nil }) - c, _ := dialer.Consumer( + c, _ := d.Consumer( consumer.WithQueue("a_queue"), consumer.WithHandler(h), ) // close consumer c.Close() - <-c.NotifyClosed() - // close connection - dialer.Close() + // close dialer + d.Close() // Output: } diff --git a/publisher_test.go b/publisher_test.go index 3df448d..1b93107 100644 --- a/publisher_test.go +++ b/publisher_test.go @@ -3,6 +3,9 @@ package amqpextra_test import ( "log" + "context" + "time" + "github.com/makasim/amqpextra" "github.com/makasim/amqpextra/publisher" "github.com/streadway/amqp" @@ -10,20 +13,18 @@ import ( func ExampleDialer_Publisher() { // open connection - dialer, err := amqpextra.NewDialer(amqpextra.WithURL("amqp://guest:guest@localhost:5672/%2f")) - if err != nil { - log.Fatal(err) - } + d, _ := amqpextra.NewDialer(amqpextra.WithURL("amqp://guest:guest@localhost:5672/%2f")) // create publisher - p, err := dialer.Publisher() - if err != nil { - log.Fatal(err) - } + p, _ := d.Publisher() + + ctx, cancelFunc := context.WithTimeout(context.Background(), time.Millisecond*100) + defer cancelFunc() // publish a message - go p.Publish(publisher.Message{ - Key: "test_queue", + p.Publish(publisher.Message{ + Key: "test_queue", + Context: ctx, Publishing: amqp.Publishing{ Body: []byte(`{"foo": "fooVal"}`), }, @@ -31,10 +32,9 @@ func ExampleDialer_Publisher() { // close publisher p.Close() - <-p.NotifyClosed() // close connection - dialer.Close() + d.Close() // Output: }