Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASweb-backend-go
Commits
0fc183a7
Commit
0fc183a7
authored
Oct 13, 2020
by
Sonja Happ
Browse files
AMQP: Modify sendAction method
parent
f55120df
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
amqp/amqp_endpoints.go
View file @
0fc183a7
...
...
@@ -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
...
...
amqp/amqpclient.go
View file @
0fc183a7
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment