dapper91 / pjrpc Goto Github PK
View Code? Open in Web Editor NEWpython json-rpc client/server without boilerplate
Home Page: https://pjrpc.readthedocs.io
License: The Unlicense
python json-rpc client/server without boilerplate
Home Page: https://pjrpc.readthedocs.io
License: The Unlicense
When examples/kombu_server.py
and kombu_client.py
communicate, the communication suddenly stops:
while true;do python examples/kombu_client.py;echo;sleep 1;done
After a few iterations of the loop, the client no longer prints the output of the sum(1,2)
RPC calls.
DEBUG:amqp:Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@sf314', 'copyright': 'Copyright (c) 2007-2022 VMware, Inc. or its affiliates.', 'information': 'Licensed under the MPL 2.0. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 24.2.2', 'product': 'RabbitMQ', 'version': '3.9.13'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']
DEBUG:amqp:using channel_id: 1
DEBUG:amqp:Channel open
1 + 2 = 3
I see in the rabbitmq log that server and client stay connected, but the client does not continue sending requests:
In the kombu_server log, I see that the server sends the response for the sum method, but the client does not have any logger calls about sending requests or receiving responses.
This is with a kombu_client.py which requests one sum(1,2)
and sends one tick()
. The tick after the sum is not received:
DEBUG:pjrpc.server.request:request received: {"jsonrpc": "2.0", "method": "sum", "id": 1, "params": [1, 2]}
DEBUG:pjrpc.server.response:response sent: {"jsonrpc": "2.0", "id": 1, "result": 3}
DEBUG:pjrpc.server.request:request received: {"jsonrpc": "2.0", "method": "tick"}
received tick
DEBUG:pjrpc.server.request:request received: {"jsonrpc": "2.0", "method": "sum", "id": 1, "params": [1, 2]}
DEBUG:pjrpc.server.response:response sent: {"jsonrpc": "2.0", "id": 1, "result": 3}
DEBUG:amqp.connection.Connection.heartbeat_tick:heartbeat_tick : for connection 658eb70988e8400d9bdfb55a26b12b35
DEBUG:amqp.connection.Connection.heartbeat_tick:heartbeat_tick : for connection 658eb70988e8400d9bdfb55a26b12b35
DEBUG:amqp.connection.Connection.heartbeat_tick:heartbeat_tick : for connection 658eb70988e8400d9bdfb55a26b12b35
The server still receives heartbeats and and answers to other clients.
Just a suggestion / hint for diagnosis: I think logging of requests and responses shoud be added to the kombu client to aid in tracing,
and
logging.basicConfig(level=logging.DEBUG)
should be added to server and client: For kombu, the even the debug logging is not too verbose.
When using the latest python-openapi-us-bundle for Swagger, the UI always shows Petstore OpenAPI instead of the API defined by the app.
The reason is rather simple - in
pjrpc/pjrpc/server/specs/openapi.py
Line 937 in badd7eb
index.html
is patched, and it is expected that SwaggerUIBundle
initialization is embedded into it. However, the index.html
in the latest bundle version does not have this code embedded anymore. Instead, it is laid out into swagger-initialization.js
, see https://github.com/dapper91/python-openapi-ui-bundles/blob/master/openapi_ui_bundles/swagger_ui/vendor/index.htmlimport asyncio
from pjrpc.client.backend import aio_pika as pjrpc_client
async def main():
client = pjrpc_client.Client('amqp://guest:guest@localhost:5672/v1', 'jsonrpc')
await client.connect()
await client.close()
if __name__ == "__main__":
asyncio.run(main())
with 1.6.0, this results in:
File "aio_pika_client-close-test.py", line 9, in main
await client.close()
File "/home/autonoma/flowhub/pjrpc/pjrpc/client/backend/aio_pika.py", line 86, in close
assert self._result_queue is not None, "client is not initialized"
AssertionError: client is not initialized
self._result_queue
is always none, unless the Client is costructed to use a fixed result_queue like this:
kwargs["result_queue_name"] = "jsonrpc-responses"
kwargs["result_queue_args"] = {
"exclusive": False,
"auto_delete": False,
"durable": True,
"arguments": None,
}
client = xjsonrpc_client.Client(
URL("amqp://guest:guest@localhost:5672/"),
"jsonrpc-requests",
**kwargs,
)
But for the majority of uses, a fixed result queue is not needed and a temporary result queue is used for each call (which is easier if you want to run more than one RPC client)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.