File tree 2 files changed +16
-17
lines changed
2 files changed +16
-17
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import (
12
12
13
13
func ExampleDialer_Consumer () {
14
14
// open connection
15
- dialer , _ := amqpextra .NewDialer (amqpextra .WithURL ("amqp://guest:guest@localhost:5672/%2f" ))
15
+ d , _ := amqpextra .NewDialer (amqpextra .WithURL ("amqp://guest:guest@localhost:5672/%2f" ))
16
16
17
17
h := consumer .HandlerFunc (func (ctx context.Context , msg amqp.Delivery ) interface {} {
18
18
// process message
@@ -21,17 +21,16 @@ func ExampleDialer_Consumer() {
21
21
return nil
22
22
})
23
23
24
- c , _ := dialer .Consumer (
24
+ c , _ := d .Consumer (
25
25
consumer .WithQueue ("a_queue" ),
26
26
consumer .WithHandler (h ),
27
27
)
28
28
29
29
// close consumer
30
30
c .Close ()
31
- <- c .NotifyClosed ()
32
31
33
- // close connection
34
- dialer .Close ()
32
+ // close dialer
33
+ d .Close ()
35
34
36
35
// Output:
37
36
}
Original file line number Diff line number Diff line change @@ -3,38 +3,38 @@ package amqpextra_test
3
3
import (
4
4
"log"
5
5
6
+ "context"
7
+ "time"
8
+
6
9
"github.com/makasim/amqpextra"
7
10
"github.com/makasim/amqpextra/publisher"
8
11
"github.com/streadway/amqp"
9
12
)
10
13
11
14
func ExampleDialer_Publisher () {
12
15
// open connection
13
- dialer , err := amqpextra .NewDialer (amqpextra .WithURL ("amqp://guest:guest@localhost:5672/%2f" ))
14
- if err != nil {
15
- log .Fatal (err )
16
- }
16
+ d , _ := amqpextra .NewDialer (amqpextra .WithURL ("amqp://guest:guest@localhost:5672/%2f" ))
17
17
18
18
// create publisher
19
- p , err := dialer .Publisher ()
20
- if err != nil {
21
- log . Fatal ( err )
22
- }
19
+ p , _ := d .Publisher ()
20
+
21
+ ctx , cancelFunc := context . WithTimeout ( context . Background (), time . Millisecond * 100 )
22
+ defer cancelFunc ()
23
23
24
24
// publish a message
25
- go p .Publish (publisher.Message {
26
- Key : "test_queue" ,
25
+ p .Publish (publisher.Message {
26
+ Key : "test_queue" ,
27
+ Context : ctx ,
27
28
Publishing : amqp.Publishing {
28
29
Body : []byte (`{"foo": "fooVal"}` ),
29
30
},
30
31
})
31
32
32
33
// close publisher
33
34
p .Close ()
34
- <- p .NotifyClosed ()
35
35
36
36
// close connection
37
- dialer .Close ()
37
+ d .Close ()
38
38
39
39
// Output:
40
40
}
You can’t perform that action at this time.
0 commit comments