Replies: 1 comment
-
|
As @gxuu stated, YMQ has a Python interface, implementing using Python's C API, compatible with Python 3.8+. This interface mimics YMQ's C++ interface closely such that code written using either interface should appear quite similar. YMQ's Python interface supports both asyncio and synchronous invocations, async methods are named matching the C++ API e.g. Example from scaler.io.ymq import ymq
context = ymq.IOContext(num_threads=6)
socket = await context.createIOSocket("identity", ymq.IOSocketType.Connector)
# sync and async methods can be mixed freely
# (although this is rarely wise, be careful not to block the async executor)
socket.connect_sync("tcp://127.0.0.1:3333")
await socket.send(ymq.Message(None, b"payload"))YMQ's Python interface offers the following types:
The interface includes a few types for error handling:
try:
msg = await socket.recv()
except YMQException as e:
if e.code == ErrorCode.ConnectorSocketClosedByRemoteEnd:
return # not an error for our use case, we can exit
raise # re-raise all other errors |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion provides documentation for YMQ. It contains some architecture graphs, execution flowcharts, and API descriptions.
YMQis one of the network backend forscaler. It provideszmqlike utilities such as guarantee message delivery, automatic reconnect, binder model, and pub/sub model (namedUNICASTandMULTICAST), etc. Here's the general architecture and execution flowchart of the library:User of
YMQinteracts mainly with these APIs:IOContext.createIOSocketthat generates a handle to anIOSocketIOContext.removeIOSocketreturns the handle back to the systemIOContext.requestIOSocketStopsends a stop request to anIOSocketfrom possibly another thread.IOSocket.bindTo,IOSocket.connectTothat turns anIOSocketinto a Server or Client like object. The first one bind to an address and the second one connect to an address.IOSocket.sendMessage,IOSocket.recvMessagesends and receive aYMQ Message.IOSocket.closeConnectioncloses a underlying connection with the matched identity.All of above APIs are asynchronous and completion are notified with a callback. Be noted that some callbacks are completed very fast, even before the actual completion is completed. This is expected, and user can make subsequent call even before the previous operation is really completed. For example,
will work as expected regardless the
callback1is being called or is completed or not.callback2will be called, however, only after the system decides the underlying connection is established.Sometimes, asynchronous APIs are very wordy, one might choose to use the APIs provided in
simple_interface.h.YMQalso bundled with an easy to use Python interface, @magniloquency is responsible to write this part.Beta Was this translation helpful? Give feedback.
All reactions