Skip to main content

AMQP layer for communicating with the ESB.

Project description

Client side implementation of an ESB via Amazon SQS.

Simple Usage

uri = 'sqs://LOGIN:PASSWORD@'
transport = {
    'region': 'eu-west-1',
    'exchange': 'swarm',
    'queue_name_prefix': 'dev-%(hostname)s-',
    'office_hours': False,
    'use_priorities': True,
    'priorities': ['low', 'high']
}
queues = {
  'my_queue': {
      'route': 'my.queue.route',  # Specific route
      'sleep': 60,                # Seconds before next call to SQS
      'visibility': 1800,         # Visibility message in queue
      'wait': 10                  # Long polling seconds
  },
  'my_second_queue': {}           # Will be automaticaly filled/completed
}

bus = AMQP(uri, transport, queues)
bus.connect()

# We purge a known queue
bus.purge_queue('my_queue')

# Now we add a new queue on the fly
bus.register_queue('new_queue', {'wait': 20})

bus.close()

Using as a producer

with AMQP(uri, transport, queues) as producer:
    producer.publish(
        'my_queue',
        {'id': 42},
        1  # Optional, specify 'high' priority queue
    )

Using as a consumer

def print_routing_key(body, message):
    id_ = body['id']
    rk = message.delivery_info['routing_key']
    print("[x] %r:%r" % (rk, id_))

def ack_message(body, message):
    message.ack()

def error_handler(body, message):
    raise ValueError('Error while processing message')

with AMQP(uri, transport, queues) as consumer:
    consumer.consume(
        'my_queue',
        [print_routing_key, ack_message],
        error_handler
    )

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

swarm-bus-3.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

swarm_bus-3.3-py2-none-any.whl (8.0 kB view details)

Uploaded Python 2

File details

Details for the file swarm-bus-3.3.tar.gz.

File metadata

  • Download URL: swarm-bus-3.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.5.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.12

File hashes

Hashes for swarm-bus-3.3.tar.gz
Algorithm Hash digest
SHA256 cd53ea3f6c16e3b3edbeeccfaded2a3a0ae98e57d969d8ec75f68ec606f3003f
MD5 68da654c29176df61273c087c24ab3a4
BLAKE2b-256 aefa1d58e1fb3292c89843a9b3dddd0288c593d36e07ef021bf1249dab1182e9

See more details on using hashes here.

File details

Details for the file swarm_bus-3.3-py2-none-any.whl.

File metadata

  • Download URL: swarm_bus-3.3-py2-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/36.5.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.12

File hashes

Hashes for swarm_bus-3.3-py2-none-any.whl
Algorithm Hash digest
SHA256 cf0a629afa173eb3a15dce23566cf2bfaf9c41d4887faa90e10cf7048beaa654
MD5 33f14e81ce18d0feaa46618ed7be0a37
BLAKE2b-256 5971241c58b6ee78613607572922724508a43b882e43d785321e0e1a9c61dec0

See more details on using hashes here.

Supported by

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