Skip to main content

Python client for ForestMQ

Project description

ForestMQ Python

Python client for ForestMQ

Read The Docs

Install

pip install forestmq

Running ForestMQ

docker run -p 8005:8005 josefdigital/forestmq:0.6.2

Examples

Using the provider API

from forestmq import ForestMQ


def sync_example():
    fmq = ForestMQ(domain="http://localhost:8005")
    result = fmq.provider.send_msg_sync({
        "name": "Sync message",
    })
    print(result)

sync_example()  # {'queue_length': 38, 'message_size': 5120, 'message': {'name': 'Sync message'}}

Using the provider's async client

import asyncio
from forestmq import ForestMQ

async def async_example():
    fmq = ForestMQ(domain="http://localhost:8005")
    result = await fmq.provider.send_msg({
        "name": "Async message!",
    })
    print(result)

asyncio.run(async_example())  # {'queue_length': 39, 'message_size': 5120, 'message': {'name': 'Async message!'}}

Using the consumer API

import asyncio

from forestmq import ForestMQ


def callback(message: dict) -> None:
    print(f"Consumer message: {message['message']}")


if __name__ == "__main__":
    fmq = ForestMQ(domain="http://localhost:8005", interval=1)
    asyncio.run(fmq.consumer.poll_sync(callback))

Async consumer example

import asyncio

from forestmq import ForestMQ


async def callback(message: dict) -> None:
    await asyncio.sleep(1)
    print(f"Consumer message: {message['message']}")


if __name__ == "__main__":
    fmq = ForestMQ(domain="http://localhost:8005", interval=1)
    asyncio.run(fmq.consumer.poll(callback))

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

forestmq-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

forestmq-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file forestmq-0.2.0.tar.gz.

File metadata

  • Download URL: forestmq-0.2.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for forestmq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d2e860ac29d2c9745c77d6379a54fc4cc460fa22f4ee8166df79ca2456ec85a0
MD5 526f9fedc161a6738c83ede1bb4d1632
BLAKE2b-256 69f25d8a4da4d900078cc0d46ee5b7758b3c5fba790cfae37b6dcd0f86c41060

See more details on using hashes here.

File details

Details for the file forestmq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: forestmq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for forestmq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51a3b2b49df54a7d71797795399399d14c63617c970e5c0f0cc6fa3cbfb26ad0
MD5 7a167d897d20c3af44bc0f48e4f946c1
BLAKE2b-256 32376c4791777d8f4ae2bb5f2da596a519df942a7b68f4656bf150f2e1a802d3

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