Skip to content

Commit e3aa755

Browse files
Merge pull request #20 from hellofresh/feature-rabbit-aliveness-check
RabbitMQ aliveness test example
2 parents 456ffac + 9d0ae38 commit e3aa755

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test:
2121
@sleep 3 && \
2222
HEALTH_GO_PG_DSN="postgres://test:test@`docker-compose port postgres 5432`/test?sslmode=disable" \
2323
HEALTH_GO_MQ_DSN="amqp://guest:guest@`docker-compose port rabbit 5672`/" \
24+
HEALTH_GO_MQ_URL="http://guest:guest@`docker-compose port rabbit 15672`/" \
2425
HEALTH_GO_RD_DSN="redis://`docker-compose port redis 6379`/" \
2526
HEALTH_GO_MG_DSN="`docker-compose port mongo 27017`/" \
2627
HEALTH_GO_MS_DSN="test:test@tcp(`docker-compose port mysql 3306`)/test?charset=utf8" \

_examples/server.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func main() {
1717
Name: "some-custom-check-fail",
1818
Timeout: time.Second * 5,
1919
SkipOnErr: true,
20-
Check: func() error { return errors.New("failed during rabbitmq health check") },
20+
Check: func() error { return errors.New("failed during custom health check") },
2121
})
2222

2323
// custom health check example (success)
@@ -42,7 +42,7 @@ func main() {
4242
Timeout: time.Second * 5,
4343
SkipOnErr: true,
4444
Check: healthPg.New(healthPg.Config{
45-
DSN: `postgres://test:test@0.0.0.0:32807/test?sslmode=disable`,
45+
DSN: `postgres://test:test@0.0.0.0:32783/test?sslmode=disable`,
4646
}),
4747
})
4848

@@ -52,7 +52,20 @@ func main() {
5252
Timeout: time.Second * 5,
5353
SkipOnErr: true,
5454
Check: healthMySql.New(healthMySql.Config{
55-
DSN: `test:test@tcp(0.0.0.0:32802)/test?charset=utf8`,
55+
DSN: `test:test@tcp(0.0.0.0:32778)/test?charset=utf8`,
56+
}),
57+
})
58+
59+
// rabbitmq aliveness test example.
60+
// Use it if your app has access to RabbitMQ management API.
61+
// This endpoint declares a test queue, then publishes and consumes a message. Intended for use by monitoring tools. If everything is working correctly, will return HTTP status 200.
62+
// As the default virtual host is called "/", this will need to be encoded as "%2f".
63+
health.Register(health.Config{
64+
Name: "rabbit-aliveness-check",
65+
Timeout: time.Second * 5,
66+
SkipOnErr: true,
67+
Check: healthHttp.New(healthHttp.Config{
68+
URL: `http://guest:guest@0.0.0.0:32780/api/aliveness-test/%2f`,
5669
}),
5770
})
5871

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package rabbitmq
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/hellofresh/health-go/checks/http"
8+
)
9+
10+
const httpURLEnv = "HEALTH_GO_MQ_URL"
11+
12+
func TestAliveness(t *testing.T) {
13+
if os.Getenv(httpURLEnv) == "" {
14+
t.SkipNow()
15+
}
16+
17+
check := http.New(http.Config{
18+
URL: os.Getenv(httpURLEnv),
19+
})
20+
21+
if err := check(); err != nil {
22+
t.Fatalf("HTTP check failed: %s", err.Error())
23+
}
24+
}

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
image: rabbitmq:3.6-management-alpine
1717
ports:
1818
- "5672"
19+
- "15672"
1920

2021
redis:
2122
image: redis:3.2-alpine

0 commit comments

Comments
 (0)