Skip to content

Commit 9b41918

Browse files
committed
Update readme and rabbitmq
1 parent db5ef82 commit 9b41918

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

README.md

+46-18
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ A health check in microservices is a mechanism that ensures each service is func
5555
## Implementation of [core-go/health](https://github.com/core-go/health)
5656
#### Core Library
5757
- <b>Purpose</b>: Provides basic health check functionalities
58-
- <b>Features:
58+
- <b>Features</b>:
5959
- Define standard health check interfaces.
6060
- Model [Health](https://github.com/core-go/health/blob/main/health.go)
61-
```json
61+
```go
6262
package health
6363

6464
type Health struct {
@@ -67,8 +67,9 @@ A health check in microservices is a mechanism that ensures each service is func
6767
Details map[string]Health `json:"details,omitempty"`
6868
}
6969
```
70+
7071
- Allow custom health checks with this standard interface [Checker](https://github.com/core-go/health/blob/main/checker.go):
71-
```json
72+
```go
7273
package health
7374
7475
import "context"
@@ -79,8 +80,9 @@ A health check in microservices is a mechanism that ensures each service is func
7980
Build(ctx context.Context, data map[string]interface{}, err error) map[string]interface{}
8081
}
8182
```
83+
8284
- Build the response JSON from many custom health checks by this GO function [Check](https://github.com/core-go/health/blob/main/check.go)
83-
- This function can be called by http handler ([gin](https://github.com/gin-gonic/gin), [echo](https://github.com/labstack/echo), [mux](https://github.com/gorilla/mux), [go-chi](https://github.com/go-chi/chi))
85+
- This function can be called by http handler ([gin](https://github.com/gin-gonic/gin), [echo](https://github.com/labstack/echo), [mux](https://github.com/gorilla/mux), [go-chi](https://github.com/go-chi/chi))
8486
- Implement basic checks
8587
- CPU, memory, disk space: not yet implemented.
8688
- Cache (Redis, Memcached)
@@ -101,44 +103,38 @@ A health check in microservices is a mechanism that ensures each service is func
101103
- <b>Features</b>:
102104
- Check connectivity to cache servers (Redis, Memcached).
103105
- Redis: support [go-redis/redis](https://github.com/core-go/health/blob/main/redis/v9/health_checker.go) and [garyburd/redigo](https://github.com/core-go/health/blob/main/redigo/health_checker.go). The sample is at [go-admin](https://github.com/project-samples/go-admin).
104-
- nodejs library for Redis is at [redis-plus](https://www.npmjs.com/package/redis-plus)
105106
- Validate cache hit/miss ratio and performance metrics.
106107

107-
#### Database Health Check Library
108+
#### Database Health Check Libraries
108109
- <b>Purpose</b>: Monitors the health of database connections
109110
- <b>Features</b>:
110111
- Check connectivity and response time for various databases (SQL, NoSQL).
111112
- [sql](https://github.com/core-go/health/blob/main/sql/health_checker.go). The sample is at [go-sql-sample](https://github.com/go-tutorials/go-sql-sample).
112-
- nodejs library for My SQL is at [mysql2-core](https://www.npmjs.com/package/mysql2-core). The sample is at [sql-modular-sample](https://github.com/source-code-template/sql-modular-sample).
113-
- nodejs library for Oracle is at [oracle-core](https://www.npmjs.com/package/oracle-core).
114-
- nodejs library for Postgres is at [pg-extension](https://www.npmjs.com/package/pg-extension).
115-
- nodejs library for MS SQL is at [mssql-core](https://www.npmjs.com/package/mssql-core).
116113
- [mongo](https://github.com/core-go/health/blob/main/mongo/health_checker.go). The sample is at [go-mongo-sample](https://github.com/go-tutorials/go-mongo-sample).
117-
- nodejs library for mongo is at [mongodb-extension](https://www.npmjs.com/package/mongodb-extension). The sample is at [mongo-modular-sample](https://github.com/source-code-template/mongo-modular-sample).
118114
- [dynamodb](https://github.com/core-go/health/blob/main/dynamodb/health_checker.go). The sample is at [go-dynamodb-tutorial](https://github.com/go-tutorials/go-dynamodb-tutorial).
119115
- [firestore](https://github.com/core-go/health/blob/main/firestore/health_checker.go). The sample is at [go-firestore-sample](https://github.com/go-tutorials/go-firestore-sample).
120116
- [elasticsearch](https://github.com/core-go/health/blob/main/elasticsearch/v8/health_checker.go). The sample is at [go-elasticsearch-sample](https://github.com/go-tutorials/go-elasticsearch-sample).
121117
- [cassandra](https://github.com/core-go/health/blob/main/cassandra/health_checker.go). The sample is at [go-cassandra-sample](https://github.com/go-tutorials/go-cassandra-sample).
122118
- [hive](https://github.com/core-go/health/blob/main/hive/health_checker.go). The sample is at [go-hive-sample](https://github.com/go-tutorials/go-hive-sample).
123119
- Provide detailed status messages and error handling.
124120

125-
#### Message Queue Health Check Library
121+
#### Message Queue Health Check Libraries
126122
- <b>Purpose</b>: Ensures message queues are operational.
127123
- <b>Features</b>:
128124
- Check connectivity and queue depth for different message brokers.
129125
- [Amazon SQS](https://github.com/core-go/health/blob/main/sqs/health_checker.go). The sample is at [go-amazon-sqs-sample](https://github.com/project-samples/go-amazon-sqs-sample).
130126
- [Google Pub/Sub](https://github.com/core-go/health/blob/main/pubsub/health_checker.go). The sample is at [go-pubsub-sample](https://github.com/project-samples/go-pubsub-sample).
131-
- health check for nodejs is at [google-pubsub](https://www.npmjs.com/package/google-pubsub). The sample is at [pubsub-sample](https://github.com/typescript-tutorial/pubsub-sample).
127+
- health check for nodejs is at [google-pubsub](https://www.npmjs.com/package/google-pubsub). The sample is at [pubsub-sample](https://github.com/typescript-tutorial/pubsub-sample).
132128
- [Kafka](https://github.com/core-go/health/blob/main/kafka/health_checker.go). The sample is at [go-kafka-sample](https://github.com/project-samples/go-kafka-sample).
133-
- health check for nodejs is at [kafka-plus](https://www.npmjs.com/package/kafka-plus). The sample is at [kafka-sample](https://github.com/typescript-tutorial/kafka-sample).
129+
- health check for nodejs is at [kafka-plus](https://www.npmjs.com/package/kafka-plus). The sample is at [kafka-sample](https://github.com/typescript-tutorial/kafka-sample).
134130
- [NATS](https://github.com/core-go/health/blob/main/nats/health_checker.go). The sample is at [go-nats-sample](https://github.com/project-samples/go-nats-sample).
135-
- health check for nodejs is at [NATS](https://www.npmjs.com/package/nats-plus). The sample is at [nats-sample](https://github.com/typescript-tutorial/nats-sample)
131+
- health check for nodejs is at [NATS](https://www.npmjs.com/package/nats-plus). The sample is at [nats-sample](https://github.com/typescript-tutorial/nats-sample)
136132
- [Active MQ](https://github.com/core-go/health/blob/main/activemq/health_checker.go). The sample is at [go-active-mq-sample](https://github.com/project-samples/go-active-mq-sample).
137-
- health check for nodejs is at [activemq](https://www.npmjs.com/package/activemq). The sample is at [activemq-sample](https://github.com/typescript-tutorial/activemq-sample)
133+
- health check for nodejs is at [activemq](https://www.npmjs.com/package/activemq). The sample is at [activemq-sample](https://github.com/typescript-tutorial/activemq-sample)
138134
- [RabbitMQ](https://github.com/core-go/health/blob/main/rabbitmq/health_checker.go). The sample is at [go-rabbit-mq-sample](https://github.com/project-samples/go-rabbit-mq-sample).
139135
- health check for nodejs is at [rabbitmq-ext](https://www.npmjs.com/package/rabbitmq-ext). The sample is at [rabbitmq-sample](https://github.com/typescript-tutorial/rabbitmq-sample)
140136
- [IBM MQ](https://github.com/core-go/health/blob/main/ibmmq/health_checker.go). The sample is at [go-ibm-mq-sample](https://github.com/project-samples/go-ibm-mq-sample).
141-
- health check for nodejs is at [ibmmq-plus](https://www.npmjs.com/package/ibmmq-plus). The sample is at [ibmmq-sample](https://github.com/typescript-tutorial/ibmmq-sample).
137+
- health check for nodejs is at [ibmmq-plus](https://www.npmjs.com/package/ibmmq-plus). The sample is at [ibmmq-sample](https://github.com/typescript-tutorial/ibmmq-sample).
142138
- Monitor message lag and processing time (Not yet implemented)
143139

144140
### Future Libraries to develop
@@ -163,7 +159,39 @@ A health check in microservices is a mechanism that ensures each service is func
163159
- [handler](https://github.com/core-go/health/blob/main/handler.go), to support [Gorilla mux](https://github.com/gorilla/mux) and [Go-chi](https://github.com/go-chi/chi). The sample is at [go-sql-sample](https://github.com/go-tutorials/go-sql-sample).
164160
- [echo handler](https://github.com/core-go/health/blob/main/echo/handler.go) to support [Echo](https://github.com/labstack/echo). The sample is at [go-sql-echo-sample](https://github.com/go-tutorials/go-sql-echo-sample).
165161
- [gin handler](https://github.com/core-go/health/blob/main/gin/handler.go) to support [Gin](https://github.com/gin-gonic/gin). The sample is at is at [go-sql-gin-sample](https://github.com/go-tutorials/go-sql-gin-sample).
166-
- for nodejs, we have [express-ext](https://www.npmjs.com/package/express-ext) to integrate with [express](https://www.npmjs.com/package/express). The sample is at is at [mongo-modular-sample](https://github.com/source-code-template/mongo-modular-sample).
162+
163+
### Benefits and Challenges:
164+
#### Benefits:
165+
- Improved Reliability: Continuous monitoring of services ensures quick detection and resolution of issues.
166+
- Scalability: Supports growth by maintaining health across distributed systems.
167+
- Better Resource Management: Helps optimize resource usage and prevent failures.
168+
169+
#### Challenges:
170+
- Overhead: Adding health checks can introduce some performance overhead.
171+
- Complexity: Requires careful planning and integration to avoid false positives and negatives.
172+
- Maintenance: Health check implementations need regular updates to stay relevant and effective.
173+
174+
## Appendix
175+
### Health Check for nodejs
176+
#### Database Health Check Libraries
177+
- Redis: [redis-plus](https://www.npmjs.com/package/redis-plus), to wrap and simplify [redis](https://www.npmjs.com/package/redis).
178+
- Mongo: [mongodb-extension](https://www.npmjs.com/package/mongodb-extension), to wrap and simplify [mongodb](https://www.npmjs.com/package/mongodb). The sample is at [mongo-modular-sample](https://github.com/source-code-template/mongo-modular-sample).
179+
- My SQL: [mysql2-core](https://www.npmjs.com/package/mysql2-core), to wrap and simplify [mysql2](https://www.npmjs.com/package/mysql2). The sample is at [sql-modular-sample](https://github.com/source-code-template/sql-modular-sample).
180+
- Oracle: [oracle-core](https://www.npmjs.com/package/oracle-core), to wrap and simplify [oracledb](https://www.npmjs.com/package/oracledb).
181+
- Postgres: [pg-extension](https://www.npmjs.com/package/pg-extension), to wrap and simplify [pg](https://www.npmjs.com/package/pg).
182+
- MS SQL: [mssql-core](https://www.npmjs.com/package/mssql-core), to wrap and simplify [mssql](https://www.npmjs.com/package/mssql).
183+
- SQLite: [sqlite3-core](https://www.npmjs.com/package/sqlite3-core) to wrap and simplify [sqlite3](https://www.npmjs.com/package/sqlite3).
184+
185+
#### Message Queue Health Check Libraries
186+
- Kafka: [kafka-plus](https://www.npmjs.com/package/kafka-plus), to wrap and simplify [kafkajs](https://www.npmjs.com/package/kafkajs). The sample is at [kafka-sample](https://github.com/typescript-tutorial/kafka-sample).
187+
- RabbitMQ: [rabbitmq-ext](https://www.npmjs.com/package/rabbitmq-ext), to wrap and simplify [amqplib](https://www.npmjs.com/package/amqplib). The sample is at [rabbitmq-sample](https://github.com/typescript-tutorial/rabbitmq-sample).
188+
- Google Pub/Sub: [google-pubsub](https://www.npmjs.com/package/google-pubsub), to wrap and simplify [@google-cloud/pubsub](https://www.npmjs.com/package/@google-cloud/pubsub). The sample is at [pubsub-sample](https://github.com/typescript-tutorial/pubsub-sample)
189+
- IBM MQ: [ibmmq-plus](https://www.npmjs.com/package/ibmmq-plus), to wrap and simplify [ibmmq](https://www.npmjs.com/package/ibmmq). The sample is at [ibmmq-sample](https://github.com/typescript-tutorial/ibmmq-sample).
190+
- Active MQ: [activemq](https://www.npmjs.com/package/activemq), to wrap and simplify [amqplib](https://www.npmjs.com/package/amqplib). The sample is at [activemq-sample](https://github.com/typescript-tutorial/activemq-sample).
191+
- NATS: [nats-plus](https://www.npmjs.com/package/nats-plus), to wrap and simplify [nats](https://www.npmjs.com/package/nats). The sample is at [nats-sample](https://github.com/typescript-tutorial/nats-sample).
192+
193+
#### Integration with Existing Systems
194+
- for nodejs, we have [express-ext](https://www.npmjs.com/package/express-ext) to integrate with [express](https://www.npmjs.com/package/express). The sample is at is at [mongo-modular-sample](https://github.com/source-code-template/mongo-modular-sample).
167195

168196
## Installation
169197
Please make sure to initialize a Go module before installing core-go/health:

http/health_checker.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"net/http"
109
"time"
@@ -43,7 +42,7 @@ func (s *HealthChecker) Check(ctx context.Context) (map[string]interface{}, erro
4342
} else if err != nil {
4443
return res, err
4544
}
46-
_, _ = io.Copy(ioutil.Discard, resp.Body)
45+
_, _ = io.Copy(io.Discard, resp.Body)
4746
_ = resp.Body.Close()
4847
if resp.StatusCode >= 500 {
4948
return res, fmt.Errorf("status code is: %d", resp.StatusCode)
@@ -56,7 +55,7 @@ func (s *HealthChecker) Build(ctx context.Context, data map[string]interface{},
5655
return data
5756
}
5857
if data == nil {
59-
data = make(map[string]interface{}, 0)
58+
data = make(map[string]interface{})
6059
}
6160
data["error"] = err.Error()
6261
return data

rabbitmq/channel.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package rabbitmq
22

33
import (
4-
"github.com/streadway/amqp"
54
"time"
5+
6+
amqp "github.com/rabbitmq/amqp091-go"
67
)
78

89
func NewChannel(url string) (*amqp.Channel, error) {
@@ -24,4 +25,3 @@ func NewChannelWithTimeOut(url string, timeout time.Duration) (*amqp.Channel, er
2425
}
2526
return conn.Channel()
2627
}
27-

0 commit comments

Comments
 (0)