Added in GET /connections to update restarting node

During a temporary service re-hydration, this allows the recovering service to:

1.) Sub to /connections for all incoming connections
then
2.) Get a list of all connections that exist rn.

This is useful for rebuilding caches and if any of your edge-workers need to be restarted, they can. It also allows for you not to have a 100% coupling in Redis or any other MQ stream. There are still no routes for the MQ streams to get all conns on connect, when we migrate to this we will add in this support as well
This commit is contained in:
Scott Joseph Spitler II
2022-09-23 16:57:26 -04:00
parent b2e79c3bea
commit 3aea177ea8

View File

@@ -4,10 +4,19 @@ import (
"github.com/gin-gonic/gin"
)
const (
CONNECTIONS = "api/v1/connections"
)
type resp struct {
Code int `json:"code,omitempty"`
Clients []string `json:"clients,omitempty"`
}
func InitHTTPMoniter(b *Broker) {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.DELETE("api/v1/connections/:clientid", func(c *gin.Context) {
router.DELETE(CONNECTIONS + "/:clientid", func(c *gin.Context) {
clientid := c.Param("clientid")
cli, ok := b.clients.Load(clientid)
if ok {
@@ -16,10 +25,17 @@ func InitHTTPMoniter(b *Broker) {
conn.Close()
}
}
resp := map[string]int{
"code": 0,
}
c.JSON(200, &resp)
r := resp{Code: 0}
c.JSON(200, &r)
})
router.GET(CONNECTIONS, func(c *gin.Context) {
conns := make([]string, 0)
b.clients.Range(func (k, v interface{}) bool {
conns = append(conns, v.(*client).info.clientID)
return true
})
r := resp{Clients: conns}
c.JSON(200, &r)
})
router.Run(":" + b.config.HTTPPort)