Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rmqplus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
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
OpenVMS
WASD
rmqplus
Commits
b8fc36fc0196
Commit
b8fc36fc0196
authored
4 years ago
by
Jean-Francois Pieronne
Browse files
Options
Downloads
Patches
Plain Diff
Example of a Python rpc server
parent
2c56970a9641
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rpc_server.py
+55
-0
55 additions, 0 deletions
rpc_server.py
with
55 additions
and
0 deletions
rpc_server.py
0 → 100644
+
55
−
0
View file @
b8fc36fc
# -*- coding: iso-8859-15 -*-
#!/usr/bin/env python
#
# For request like:
# http://server/rmqplus/?FirstField=for&SecondField=this
# return value:firstfield + ' ' + secondfield, status:1
# in the upper request: "for this"
# Any error: return status:0
#
import
pika
import
cjson
import
sys
from
pprint
import
pprint
host
=
sys
.
argv
[
1
]
user
=
sys
.
argv
[
2
]
pwd
=
sys
.
argv
[
3
]
credentials
=
pika
.
PlainCredentials
(
user
,
pwd
)
connection
=
pika
.
BlockingConnection
(
pika
.
ConnectionParameters
(
host
=
host
,
credentials
=
credentials
))
channel
=
connection
.
channel
()
channel
.
queue_declare
(
queue
=
'
rpc_queue
'
,
durable
=
True
)
def
execute
(
din
,
dout
):
try
:
dout
[
'
value
'
]
=
din
[
'
FORM_FIRSTFIELD
'
]
+
'
'
+
din
[
'
FORM_SECONDFIELD
'
]
dout
[
'
status
'
]
=
1
except
:
dout
[
'
status
'
]
=
0
def
on_request
(
ch
,
method
,
props
,
body
):
# print "\nReceived '%s'" % (body,)
response
=
cjson
.
decode
(
body
)
pprint
(
response
[
'
in
'
])
execute
(
response
[
'
in
'
],
response
[
'
out
'
])
ch
.
basic_publish
(
exchange
=
''
,
routing_key
=
props
.
reply_to
,
properties
=
pika
.
BasicProperties
(
correlation_id
=
\
props
.
correlation_id
),
body
=
cjson
.
encode
(
response
[
'
out
'
]))
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
channel
.
basic_qos
(
prefetch_count
=
1
)
channel
.
basic_consume
(
queue
=
'
rpc_queue
'
,
on_message_callback
=
on_request
)
print
(
"
[x] Awaiting RPC requests
"
)
channel
.
start_consuming
()
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