mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
AMQP: Modify sendAction method
This commit is contained in:
parent
f55120df52
commit
0fc183a70b
2 changed files with 15 additions and 13 deletions
|
@ -27,7 +27,6 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
|
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
|
||||||
|
@ -62,14 +61,14 @@ func sendActionToIC(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
//now := time.Now()
|
||||||
|
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
if action.When == 0 {
|
/*if action.When == 0 {
|
||||||
action.When = float32(now.Unix())
|
action.When = float32(now.Unix())
|
||||||
}
|
}*/
|
||||||
|
*action.UUID = s.UUID
|
||||||
err = SendActionAMQP(action, s.UUID)
|
err = SendActionAMQP(action)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.InternalServerError(c, "Unable to send actions to IC: "+err.Error())
|
helper.InternalServerError(c, "Unable to send actions to IC: "+err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
@ -46,8 +46,9 @@ type Action struct {
|
||||||
Act string `json:"action"`
|
Act string `json:"action"`
|
||||||
When float32 `json:"when"`
|
When float32 `json:"when"`
|
||||||
Parameters struct{} `json:"parameters"`
|
Parameters struct{} `json:"parameters"`
|
||||||
Model struct{} `json:"model"`
|
UUID *string `json:"uuid"`
|
||||||
Results struct{} `json:"results"`
|
//Model struct{} `json:"model"`
|
||||||
|
//Results struct{} `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ICUpdate struct {
|
type ICUpdate struct {
|
||||||
|
@ -133,7 +134,7 @@ func ConnectAMQP(uri string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendActionAMQP(action Action, uuid string) error {
|
func SendActionAMQP(action Action) error {
|
||||||
|
|
||||||
payload, err := json.Marshal(action)
|
payload, err := json.Marshal(action)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -149,11 +150,12 @@ func SendActionAMQP(action Action, uuid string) error {
|
||||||
Body: payload,
|
Body: payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
if uuid != "" {
|
err = CheckConnection()
|
||||||
msg.Headers["uuid"] = uuid
|
if err != nil {
|
||||||
msg.Headers["action"] = "ping"
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("AMQP: Sending message", string(msg.Body))
|
||||||
err = client.channel.Publish(VILLAS_EXCHANGE,
|
err = client.channel.Publish(VILLAS_EXCHANGE,
|
||||||
"",
|
"",
|
||||||
false,
|
false,
|
||||||
|
@ -168,8 +170,9 @@ func PingAMQP() error {
|
||||||
|
|
||||||
var a Action
|
var a Action
|
||||||
a.Act = "ping"
|
a.Act = "ping"
|
||||||
|
*a.UUID = ""
|
||||||
|
|
||||||
err := SendActionAMQP(a, "")
|
err := SendActionAMQP(a)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue