Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Wiki
Code
Merge requests
8
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
Commits
29ad8ead
Commit
29ad8ead
authored
5 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Plain Diff
Merge branch 'feat-redesign-mq' into feat-subscribe-mail-lists
parents
ed4d9510
495e522a
No related branches found
No related tags found
6 merge requests
!147
Merge previous default branch feat-cod-rmq into main
,
!85
kill nginx process running under user from login node
,
!51
Fix acct create wait
,
!39
WIP:Feat cod rmq
,
!38
WIP: Feat cod rmq
,
!30
Feat subscribe mail lists
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
create_account.py
+17
-0
17 additions, 0 deletions
create_account.py
rc_rmq.py
+8
-10
8 additions, 10 deletions
rc_rmq.py
rc_util.py
+6
-4
6 additions, 4 deletions
rc_util.py
with
34 additions
and
14 deletions
README.md
+
3
−
0
View file @
29ad8ead
...
@@ -41,7 +41,10 @@ def callback_function(ch, method, properties, body):
...
@@ -41,7 +41,10 @@ def callback_function(ch, method, properties, body):
# start consume messagre from queue with callback function
# start consume messagre from queue with callback function
rc_rmq.start_consume({
rc_rmq.start_consume({
'queue': 'queue_name',
'queue': 'queue_name',
'routing_key: 'your_key',
'cb': callback_function
'cb': callback_function
})
})
# don't forget to close connection
rc_rmq.disconnect()
```
```
This diff is collapsed.
Click to expand it.
create_account.py
0 → 100755
+
17
−
0
View file @
29ad8ead
#!/usr/bin/env python
import
sys
import
rc_util
if
len
(
sys
.
argv
)
<
2
:
print
(
"
Usage: {} USERNAME [FULL_NAME] [REASON]
"
.
format
(
sys
.
argv
[
0
]),
file
=
sys
.
stderr
)
exit
(
1
)
user_name
=
sys
.
argv
[
1
]
full_name
=
sys
.
argv
[
2
]
if
len
(
sys
.
argv
)
>=
3
else
''
reason
=
sys
.
argv
[
3
]
if
len
(
sys
.
argv
)
>=
4
else
''
rc_util
.
add_account
(
user_name
,
full
=
full_name
,
reason
=
reason
)
print
(
"
Account requested for user: {}
"
.
format
(
user_name
))
print
(
"
Waiting for confirmation...
"
)
rc_util
.
consume
(
user_name
)
This diff is collapsed.
Click to expand it.
rc_rmq.py
+
8
−
10
View file @
29ad8ead
...
@@ -65,15 +65,16 @@ class RCRMQ(object):
...
@@ -65,15 +65,16 @@ class RCRMQ(object):
exchange_type
=
self
.
EXCHANGE_TYPE
,
exchange_type
=
self
.
EXCHANGE_TYPE
,
durable
=
True
)
durable
=
True
)
if
self
.
QUEUE
is
not
None
:
def
bind_queue
(
self
)
:
self
.
_channel
.
queue_declare
(
queue
=
self
.
QUEUE
,
durable
=
self
.
DURABLE
)
self
.
_channel
.
queue_declare
(
queue
=
self
.
QUEUE
,
durable
=
self
.
DURABLE
)
self
.
_channel
.
queue_bind
(
exchange
=
self
.
EXCHANGE
,
self
.
_channel
.
queue_bind
(
exchange
=
self
.
EXCHANGE
,
queue
=
self
.
QUEUE
,
queue
=
self
.
QUEUE
,
routing_key
=
self
.
ROUTING_KEY
)
routing_key
=
self
.
ROUTING_KEY
)
def
disconnect
(
self
):
def
disconnect
(
self
):
self
.
_channel
.
close
()
self
.
_channel
.
close
()
self
.
_connection
.
close
()
self
.
_connection
.
close
()
self
.
_connection
=
None
def
delete_queue
(
self
):
def
delete_queue
(
self
):
self
.
_channel
.
queue_delete
(
self
.
QUEUE
)
self
.
_channel
.
queue_delete
(
self
.
QUEUE
)
...
@@ -89,9 +90,6 @@ class RCRMQ(object):
...
@@ -89,9 +90,6 @@ class RCRMQ(object):
routing_key
=
self
.
ROUTING_KEY
,
routing_key
=
self
.
ROUTING_KEY
,
body
=
json
.
dumps
(
obj
[
'
msg
'
]))
body
=
json
.
dumps
(
obj
[
'
msg
'
]))
if
not
self
.
_consuming
:
self
.
disconnect
()
def
start_consume
(
self
,
obj
):
def
start_consume
(
self
,
obj
):
if
'
queue
'
in
obj
:
if
'
queue
'
in
obj
:
self
.
QUEUE
=
obj
[
'
queue
'
]
self
.
QUEUE
=
obj
[
'
queue
'
]
...
@@ -105,6 +103,8 @@ class RCRMQ(object):
...
@@ -105,6 +103,8 @@ class RCRMQ(object):
if
self
.
_connection
is
None
:
if
self
.
_connection
is
None
:
self
.
connect
()
self
.
connect
()
self
.
bind_queue
()
self
.
_consumer_tag
=
self
.
_channel
.
basic_consume
(
self
.
QUEUE
,
obj
[
'
cb
'
])
self
.
_consumer_tag
=
self
.
_channel
.
basic_consume
(
self
.
QUEUE
,
obj
[
'
cb
'
])
self
.
_consuming
=
True
self
.
_consuming
=
True
try
:
try
:
...
@@ -112,7 +112,5 @@ class RCRMQ(object):
...
@@ -112,7 +112,5 @@ class RCRMQ(object):
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
self
.
_channel
.
stop_consuming
()
self
.
_channel
.
stop_consuming
()
self
.
disconnect
()
def
stop_consume
(
self
):
def
stop_consume
(
self
):
self
.
_channel
.
basic_cancel
(
self
.
_consumer_tag
)
self
.
_channel
.
basic_cancel
(
self
.
_consumer_tag
)
This diff is collapsed.
Click to expand it.
rc_util.py
+
6
−
4
View file @
29ad8ead
...
@@ -13,6 +13,7 @@ def add_account(username, full='', reason=''):
...
@@ -13,6 +13,7 @@ def add_account(username, full='', reason=''):
"
reason
"
:
reason
"
reason
"
:
reason
}
}
})
})
rc_rmq
.
disconnect
()
def
worker
(
ch
,
method
,
properties
,
body
):
def
worker
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
msg
=
json
.
loads
(
body
)
...
@@ -27,17 +28,18 @@ def worker(ch, method, properties, body):
...
@@ -27,17 +28,18 @@ def worker(ch, method, properties, body):
print
(
"
{} is not done yet.
"
.
format
(
key
))
print
(
"
{} is not done yet.
"
.
format
(
key
))
done
=
False
done
=
False
if
done
:
if
done
:
c
onfirm
_rmq
.
stop_consume
()
r
c_rmq
.
stop_consume
()
c
onfirm
_rmq
.
delete_queue
()
r
c_rmq
.
delete_queue
()
def
consume
(
username
,
callback
,
debug
=
False
):
def
consume
(
username
,
callback
=
worker
,
debug
=
False
):
if
debug
:
if
debug
:
sleep
(
5
)
sleep
(
5
)
else
:
else
:
c
onfirm
_rmq
.
start_consume
({
r
c_rmq
.
start_consume
({
'
queue
'
:
username
,
'
queue
'
:
username
,
'
routing_key
'
:
'
confirm.
'
+
username
,
'
routing_key
'
:
'
confirm.
'
+
username
,
'
cb
'
:
callback
'
cb
'
:
callback
})
})
rc_rmq
.
disconnect
()
return
{
'
success
'
:
True
}
return
{
'
success
'
:
True
}
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