Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
labmanager-systemd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto LIVIO BECCARIA
labmanager-systemd
Commits
a718a934
Commit
a718a934
authored
2 years ago
by
Alberto LIVIO BECCARIA
Browse files
Options
Downloads
Patches
Plain Diff
Aggiunto servizio RabbitMQ Client
parent
7f5bf304
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin-ubuntu/rabbitmq-client.py
+78
-0
78 additions, 0 deletions
bin-ubuntu/rabbitmq-client.py
systemd-ubuntu/esame-rabbitmq-client.service
+11
-0
11 additions, 0 deletions
systemd-ubuntu/esame-rabbitmq-client.service
with
89 additions
and
0 deletions
bin-ubuntu/rabbitmq-client.py
0 → 100755
+
78
−
0
View file @
a718a934
#!/usr/bin/env python3
import
pika
import
dbus
from
random
import
randint
from
time
import
sleep
server_host
=
'
rabbitmq.edu-al.unipmn.it
'
;
server_port
=
5672
;
server_username
=
'
labmanager-client
'
;
server_pwd
=
'
3aB7=2zV9:1jN3-4hE2
'
;
server_vhost
=
'
labmanager
'
;
exchange_name
=
'
labmanager-test
'
;
exchange_type
=
'
x-recent-history
'
;
# It's a plugin. Enable with 'rabbitmq-plugins enable rabbitmq_recent_history_exchange'
systemd_getconfig_unit_name
=
'
esame-get-config.service
'
bus
=
dbus
.
SystemBus
()
systemd
=
bus
.
get_object
(
'
org.freedesktop.systemd1
'
,
'
/org/freedesktop/systemd1
'
)
manager
=
dbus
.
Interface
(
systemd
,
'
org.freedesktop.systemd1.Manager
'
)
server_credentials
=
pika
.
PlainCredentials
(
server_username
,
server_pwd
,
True
)
while
True
:
try
:
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
server_host
,
port
=
server_port
,
virtual_host
=
server_vhost
,
credentials
=
server_credentials
)
)
channel
=
connection
.
channel
()
'''
L
'
exchange lo dichiara il publisher
TODO: qui serve sapere se esiste gia
'
e in caso negativo aspettare e ripetere (valutare se usare passive=true)
'''
# channel.exchange_declare(exchange=exchange_name, exchange_type=exchange_type)
result
=
channel
.
queue_declare
(
queue
=
''
,
exclusive
=
True
)
queue_name
=
result
.
method
.
queue
channel
.
queue_bind
(
exchange
=
exchange_name
,
queue
=
queue_name
)
print
(
'
Waiting for RabbitMQ messages
'
)
def
callback
(
ch
,
method
,
properties
,
body
):
# Sleep a random number of seconds (between 1 and 10)
# to avoid all machines reboot at the same time
sleep
(
randint
(
1
,
10
))
print
(
"
RabbitMQ message: %s
"
%
body
.
decode
(
'
UTF-8
'
))
start_unit
=
manager
.
StartUnit
(
systemd_getconfig_unit_name
,
'
fail
'
)
channel
.
basic_consume
(
queue
=
queue_name
,
on_message_callback
=
callback
,
auto_ack
=
True
)
channel
.
start_consuming
()
except
pika
.
exceptions
.
ConnectionClosedByBroker
:
break
# Don't recover on channel errors
except
pika
.
exceptions
.
AMQPChannelError
:
break
# Recover on all other connection errors
except
pika
.
exceptions
.
AMQPConnectionError
:
continue
This diff is collapsed.
Click to expand it.
systemd-ubuntu/esame-rabbitmq-client.service
0 → 100644
+
11
−
0
View file @
a718a934
[Unit]
Description
=
Esame - RabbitMQ client
After
=
network-online.target
Wants
=
network-online.target
[Service]
Type
=
oneshot
ExecStart
=
/usr/bin/python3 /usr/libexec/labmanager/rabbitmq/rabbitmq-client.py
[Install]
WantedBy
=
esame.target esamekiosk.target esameshow.target graphical.target
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment