Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
16
Issue boards
Milestones
Wiki
Code
Merge requests
9
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
rc
rabbitmq_agents
Merge requests
!3
Adding following agents
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adding following agents
github/fork/rtripath89/test_infra
into
develop
Overview
1
Commits
28
Pipelines
0
Changes
7
Merged
Ravi Tripathi
requested to merge
github/fork/rtripath89/test_infra
into
develop
5 years ago
Overview
1
Commits
28
Pipelines
0
Changes
7
Expand
Created by: rtripath89
ohpc_account_create
ood_account_create
slurm_add_account
👍
0
👎
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
66d24a02
28 commits,
1 year ago
7 files
+
297
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
flask_producer.py
0 → 100644
+
60
−
0
Options
import
pika
import
sys
import
socket
import
json
import
rabbit_config
as
rcfg
if
len
(
sys
.
argv
)
<
3
:
sys
.
stderr
.
write
(
"
Usage: {} TAG USERNAME
"
.
format
(
sys
.
argv
[
0
]))
exit
(
1
)
node
=
sys
.
argv
[
1
]
user_name
=
sys
.
argv
[
2
]
message
=
{
"
username
"
:
user_name
,
"
fullname
"
:
"
Full Name
"
,
"
reason
"
:
"
Reason1, Reason2.
"
}
hostname
=
socket
.
gethostname
().
split
(
"
.
"
,
1
)[
0
]
connect_host
=
rcfg
.
Server
if
hostname
!=
rcfg
.
Server
else
"
localhost
"
# Set up credentials to connect to RabbitMQ server
credentials
=
pika
.
PlainCredentials
(
rcfg
.
User
,
rcfg
.
Password
)
parameters
=
pika
.
ConnectionParameters
(
connect_host
,
rcfg
.
Port
,
rcfg
.
VHost
,
credentials
)
# Establish connection to RabbitMQ server
connection
=
pika
.
BlockingConnection
(
parameters
)
channel
=
connection
.
channel
()
channel
.
exchange_declare
(
exchange
=
rcfg
.
Exchange
,
exchange_type
=
'
direct
'
)
channel
.
basic_publish
(
exchange
=
rcfg
.
Exchange
,
routing_key
=
node
,
body
=
json
.
dumps
(
message
))
print
(
"
[x] Sent {}: {}
"
.
format
(
node
,
json
.
dumps
(
message
)))
# creates a named queue
result
=
channel
.
queue_declare
(
queue
=
user_name
,
exclusive
=
False
)
# bind the queue with exchange
channel
.
queue_bind
(
exchange
=
rcfg
.
Exchange
,
queue
=
user_name
,
routing_key
=
user_name
)
def
work
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
print
(
"
Received message from {}:
\n\t
{}
"
.
format
(
method
.
routing_key
,
msg
))
#queue_unbind(queue, exchange=None, routing_key=None, arguments=None, callback=None)
channel
.
queue_delete
(
method
.
routing_key
)
# ingest messages, and assume delivered via auto_ack
channel
.
basic_consume
(
queue
=
sys
.
argv
[
2
],
on_message_callback
=
work
,
auto_ack
=
True
)
print
(
"
Subscribing to queue: {}
"
.
format
(
sys
.
argv
[
2
]))
# initiate message ingestion
try
:
channel
.
start_consuming
()
except
KeyboardInterrupt
:
print
(
"
Disconnecting from broker.
"
)
channel
.
stop_consuming
()
connection
.
close
()
Loading