Skip to content

Commit 781c30f

Browse files
committed
refactor
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent f564d15 commit 781c30f

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# RabbitMQ AMQP 1.0 Golang Client
22

33
This library is meant to be used with RabbitMQ 4.0.
4-
Suitable for testing in pre-production environments.
5-
64

75
## Getting Started
86

97
- [Getting Started](docs/examples/getting_started)
108
- [Examples](docs/examples)
9+
Inside the `docs/examples` directory you will find several examples to get you started.</br>
10+
Also advanced examples like how to use streams, how to handle reconnections, and how to use TLS.
1111
- Getting started Video tutorial: </br>
1212
[![Getting Started](https://img.youtube.com/vi/iR1JUFh3udI/0.jpg)](https://youtu.be/iR1JUFh3udI)
1313

docs/examples/reliable/reliable.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ func main() {
9898

9999
// Consume messages from the queue
100100
go func(ctx context.Context) {
101-
for {
101+
for isRunning {
102102
deliveryContext, err := consumer.Receive(ctx)
103103
if errors.Is(err, context.Canceled) {
104104
// The consumer was closed correctly
105105
return
106106
}
107-
if err != nil {
107+
if err != nil && isRunning {
108108
// An error occurred receiving the message
109109
// here the consumer could be disconnected from the server due to a network error
110110
signalBlock.L.Lock()
@@ -118,7 +118,7 @@ func main() {
118118

119119
atomic.AddInt32(&received, 1)
120120
err = deliveryContext.Accept(context.Background())
121-
if err != nil {
121+
if err != nil && isRunning {
122122
// same here the delivery could not be accepted due to a network error
123123
// we wait for 2_500 ms and try again
124124
time.Sleep(2500 * time.Millisecond)
@@ -135,11 +135,8 @@ func main() {
135135
return
136136
}
137137

138-
wg := &sync.WaitGroup{}
139138
for i := 0; i < 1; i++ {
140-
wg.Add(1)
141139
go func() {
142-
defer wg.Done()
143140
for i := 0; i < 500_000; i++ {
144141
if !isRunning {
145142
rmq.Info("[Publisher]", "Publisher is stopped simulation not running, queue", queueName)
@@ -175,7 +172,6 @@ func main() {
175172
}
176173
}()
177174
}
178-
wg.Wait()
179175

180176
println("press any key to close the connection")
181177

pkg/rabbitmqamqp/life_cycle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func (s StateChanged) String() string {
7777

7878
switch s.To.(type) {
7979
case *StateClosed:
80+
if s.To.(*StateClosed).error == nil {
81+
return fmt.Sprintf("From: %s, To: %s", statusToString(s.From), statusToString(s.To))
82+
}
8083
return fmt.Sprintf("From: %s, To: %s, Error: %s", statusToString(s.From), statusToString(s.To), s.To.(*StateClosed).error)
8184

8285
}

0 commit comments

Comments
 (0)