Skip to content

Reconnect + send == error #25

@madkote

Description

@madkote

Hi @pedrokiefer ,

Following example is basic.

  • in the loop, client sends message and sleeps for a some period.
  • reconnecting is infinite with reconnect_max_attempts=-1
  • ActiveMQ is started with docker-compose in another terminal

Steps to reproduce

  • set value SLEEP_VALUE to 2.0
  • start ActiveMQ with docker-compose
  • start script (below) with receiver and producer
  • let it run for a few seconds to make sure all messages are arriving
  • stop ActiveMQ with docker-compose
  • start ActiveMQ with docker-compose
  • script will terminate

Problem

  • The reconnect is performing good as such (just increase the SLEEP_VALUE, e.g. to 12.0
  • The real issue occurs when calling methods of the client and there is no connection.

Questions:

  • this was an intention to handle connection error in methods by the user of library?
  • I guess a work around is to let user retry few more times and handle the error.
import sys
import logging
import time
import asyncio
import aiostomp

async def on_message(frame, message):
    print('on_message:', message)
    return True

async def report_error(error):
    print('report_error:', error)

async def run():
    SLEEP_VALUE = 12.0
    client = aiostomp.AioStomp('localhost', 61613, reconnect_max_attempts=-1, error_handler=report_error)
    client.subscribe('/queue/channel', handler=on_message)
    await client.connect(username='guest', password='guest')
    try:
        while True:
            try:
                print('>>> send')
                client.send('/queue/channel', body=u'Thanks %s' % time.time())
                print('<<< sleep')
                await asyncio.sleep(SLEEP_VALUE)
            except KeyboardInterrupt:
                break
    finally:
        client.close()

def main(args):
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run())
    loop.run_forever()

if __name__ == '__main__':
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
    main(sys.argv)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions