Skip to main content

PyZMQ server/client implementing asyncio freelance protocol based on Min RK's starter code

Project description

zmqflp

Improvements to the Freelance protocol-based zeromq server/client (Python) The client and server talk using cbor2, so the api accepts dictionaries as input.

To create a zmqflp server:

# create the server object (it runs in an asyncio zmq context)
self.server = zmqflp_server.ZMQFLPServer(self.config.identity, self.config.zmq_port)

# use the following code to process messages received by the server and send them back
async def process_messages(self):
    (serialized_request, orig_headers) = await self.server.receive()
    if serialized_request == 'EXIT':
        await self.server.send(orig_headers, 'exiting')
        return False
    elif serialized_request != "PING":
        try:
            request = serialized_request
            response = self.process_request(request)
            await self.server.send(orig_headers, response)
            return True
        except Exception as e:
            logging.exception(e)
            return False
    return True

To create a client without using a context manager:

# create the client object (this does NOT run in an asyncio context)
self.client = zmqflp_client.ZMQFLPClient(self.config.list_of_servers)

# to send and receive with the client
msg_to_send = {'message': 'hello!', 'other-key': 'stuff goes here'}
status = self.client.send_and_receive(msg_to_send)

To create a client using a context manager (for example, to run on AWS Lambda):

# create the client object (this does NOT run in an asyncio context)
with zmqflp_client.ZMQFLPClient(self.config.list_of_servers) as client:
    # to send and receive with the client
    msg_to_send = {'message': 'hello!', 'other-key': 'stuff goes here'}
    status = client.send_and_receive(msg_to_send)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zmqflp-0.8.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zmqflp-0.8.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file zmqflp-0.8.3.tar.gz.

File metadata

  • Download URL: zmqflp-0.8.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.0

File hashes

Hashes for zmqflp-0.8.3.tar.gz
Algorithm Hash digest
SHA256 793c793168a1869b660c80caa71bb2c3fde921cea59a6f4e29d856e51e343bfb
MD5 79607bf4ba6c3759d849d33ab1aa791f
BLAKE2b-256 8df4d165176c39462b266946d143cdc922387d01cc316c9f69dd914690e3a5a9

See more details on using hashes here.

File details

Details for the file zmqflp-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: zmqflp-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.7.0

File hashes

Hashes for zmqflp-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 476a39bf26c74869bdc9a5b38fffcde1d1887aaee630c3a8b4b6172313c333e8
MD5 a1d7f4217482041f116ed80710e36ab7
BLAKE2b-256 a2a6a3f595c18c3ef2c3619411249d29018cd192e19885fcf3d3ab2f363430e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page