Skip to main content

Tool for agent ecosystem

Project description

The goal of this project is to facilitate the creation of microservices interacting via a signal bus and/or queue broker.

The philosophy of this project is to present a microservice as a software agent that directly interacts only with queues and the event bus, and not with other microservices.

Tool is intended for developing:

  • distributed apps with event-driven architecture
  • distributed apps with data-driven architecture
  • multi-processors apps

Tool provide features:

  • running a periodical tasks (interval or as CRON)
  • specification of signals (events), their sending and receiving via the bus (aioredis)
  • description of queues, sending and receiving messages via the queue broker (aioamqp, kafka, aioredis)
  • limited RPC via signal bus
  • launching sub-services (in the same process)
  • launching a group of microagents (each in a separate process)
  • mocks for bus and broker

See MicroAgent documentation.

class Agent(MicroAgent):

    async def setup(self):
        pass  # init connections to DB, REDIS, SMTP and other services

    async def refresh_cache(self):
        pass  # do something periodicly

    @cron('0 */4 * * *')
    async def send_report(self):
        pass  # do something by schedule

    # subscribe to signals (events)
    @receiver(signals.user_updated, signals.user_deleted)
    async def send_notification(self, **kwargs):
        # send signal (event) to bus
        await self.bus.check_something.send(sender='agent', **kwargs)

    # message consumer from queue
    async def send_emails(self, **kwargs):
        # send message to queue

async def main():
    bus = AIORedisSignalBus('redis://localhost/7')
    broker = AIORedisBroker('redis://localhost/7')

    # usage bus and broker separate from agent
    await bus.started.send('user_agent')
    await broker.mailer(data)

    agent = Agent(bus=bus, broker=broker)
    await agent.start()


With aioredis backend provide signal bus and list-based queues:

pip install 'microagent[aioredis]'

With aioamqp backend provide queues over AMQP (RabbitMQ):

pip install 'microagent[amqp]'

With kafka backend provide queues over Kafka (experemental):

pip install 'microagent[kafka]'

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

microagent-1.6.1.tar.gz (26.7 kB view hashes)

Uploaded source

Built Distribution

microagent-1.6.1-py3-none-any.whl (32.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page