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
3ffc835a
Commit
3ffc835a
authored
Jan 28, 2021
by
Sonja Happ
Browse files
AMQP: use separate send and recv channels
parent
ae4436be
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
routes/infrastructure-component/ic_amqpclient.go
View file @
3ffc835a
...
...
@@ -37,8 +37,8 @@ const VILLAS_EXCHANGE = "villas"
type
AMQPclient
struct
{
connection
*
amqp
.
Connection
channel
*
amqp
.
Channel
re
plies
<-
chan
amqp
.
Delivery
sendCh
*
amqp
.
Channel
re
cvCh
*
amqp
.
Channel
}
type
Action
struct
{
...
...
@@ -94,13 +94,13 @@ func ConnectAMQP(uri string) error {
return
fmt
.
Errorf
(
"AMQP: failed to connect to RabbitMQ broker %v, error: %v"
,
uri
,
err
)
}
// create
channel
client
.
channel
,
err
=
client
.
connection
.
Channel
()
// create
sendCh
client
.
sendCh
,
err
=
client
.
connection
.
Channel
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"AMQP: failed to open a
channel
, error: %v"
,
err
)
return
fmt
.
Errorf
(
"AMQP: failed to open a
sendCh
, error: %v"
,
err
)
}
// declare exchange
err
=
client
.
channel
.
ExchangeDeclare
(
VILLAS_EXCHANGE
,
err
=
client
.
sendCh
.
ExchangeDeclare
(
VILLAS_EXCHANGE
,
"headers"
,
true
,
false
,
...
...
@@ -112,7 +112,7 @@ func ConnectAMQP(uri string) error {
}
// add a queue for the ICs
ICQueue
,
err
:=
client
.
channel
.
QueueDeclare
(
"infrastructure_components"
,
ICQueue
,
err
:=
client
.
sendCh
.
QueueDeclare
(
"infrastructure_components"
,
true
,
false
,
false
,
...
...
@@ -122,13 +122,19 @@ func ConnectAMQP(uri string) error {
return
fmt
.
Errorf
(
"AMQP: failed to declare the queue, error: %v"
,
err
)
}
err
=
client
.
channel
.
QueueBind
(
ICQueue
.
Name
,
""
,
VILLAS_EXCHANGE
,
false
,
nil
)
err
=
client
.
sendCh
.
QueueBind
(
ICQueue
.
Name
,
""
,
VILLAS_EXCHANGE
,
false
,
nil
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"AMQP: failed to bind the queue, error: %v"
,
err
)
}
// consume deliveries
client
.
replies
,
err
=
client
.
channel
.
Consume
(
ICQueue
.
Name
,
// create receive channel
client
.
recvCh
,
err
=
client
.
connection
.
Channel
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"AMQP: failed to open a recvCh, error: %v"
,
err
)
}
// start deliveries
messages
,
err
:=
client
.
recvCh
.
Consume
(
ICQueue
.
Name
,
""
,
true
,
false
,
...
...
@@ -136,19 +142,18 @@ func ConnectAMQP(uri string) error {
false
,
nil
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"AMQP: failed to
consume
deliveries
, error
: %v"
,
err
)
return
fmt
.
Errorf
(
"AMQP: failed to
start
deliveries: %v"
,
err
)
}
// consum
ing queue
// consum
e deliveries
go
func
()
{
for
{
for
message
:=
range
client
.
repli
es
{
for
message
:=
range
messag
es
{
err
=
processMessage
(
message
)
if
err
!=
nil
{
log
.
Println
(
err
.
Error
())
log
.
Println
(
"AMQP: Error processing message: "
,
message
,
err
.
Error
())
}
}
time
.
Sleep
(
2
)
// sleep for 2 sek
}
}()
...
...
@@ -193,7 +198,7 @@ func sendActionAMQP(action Action) error {
}
//log.Println("AMQP: Sending message", string(msg.Body))
err
=
client
.
channel
.
Publish
(
VILLAS_EXCHANGE
,
err
=
client
.
sendCh
.
Publish
(
VILLAS_EXCHANGE
,
""
,
false
,
false
,
...
...
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