Commit 0fc183a7 authored by Sonja Happ's avatar Sonja Happ
Browse files

AMQP: Modify sendAction method

parent f55120df
......@@ -27,7 +27,6 @@ import (
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
......@@ -62,14 +61,14 @@ func sendActionToIC(c *gin.Context) {
return
}
now := time.Now()
//now := time.Now()
for _, action := range actions {
if action.When == 0 {
/*if action.When == 0 {
action.When = float32(now.Unix())
}
err = SendActionAMQP(action, s.UUID)
}*/
*action.UUID = s.UUID
err = SendActionAMQP(action)
if err != nil {
helper.InternalServerError(c, "Unable to send actions to IC: "+err.Error())
return
......
......@@ -46,8 +46,9 @@ type Action struct {
Act string `json:"action"`
When float32 `json:"when"`
Parameters struct{} `json:"parameters"`
Model struct{} `json:"model"`
Results struct{} `json:"results"`
UUID *string `json:"uuid"`
//Model struct{} `json:"model"`
//Results struct{} `json:"results"`
}
type ICUpdate struct {
......@@ -133,7 +134,7 @@ func ConnectAMQP(uri string) error {
return nil
}
func SendActionAMQP(action Action, uuid string) error {
func SendActionAMQP(action Action) error {
payload, err := json.Marshal(action)
if err != nil {
......@@ -149,11 +150,12 @@ func SendActionAMQP(action Action, uuid string) error {
Body: payload,
}
if uuid != "" {
msg.Headers["uuid"] = uuid
msg.Headers["action"] = "ping"
err = CheckConnection()
if err != nil {
return err
}
log.Println("AMQP: Sending message", string(msg.Body))
err = client.channel.Publish(VILLAS_EXCHANGE,
"",
false,
......@@ -168,8 +170,9 @@ func PingAMQP() error {
var a Action
a.Act = "ping"
*a.UUID = ""
err := SendActionAMQP(a, "")
err := SendActionAMQP(a)
return err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment