Skip to content

Changed API, reconnects

Compare
Choose a tag to compare
@vrslev vrslev released this 31 Jul 17:38
· 63 commits to main since this release

What's Changed

Before:

async with client.enter_transaction() as transaction:
    await client.send(body=b"hi there!", destination="DLQ", transaction=transaction, headers={"persistent": "true"})

After:

async with client.begin() as transaction:
    await transaction.send(body=b"hi there!", destination="DLQ", headers={"persistent": "true"})
  • Change API for subscribing and listening by @vrslev in #43
  1. Now, client starts listening to messages the moment you enter the async-with block (async with stompman.Client() as client). Previously it happened only when async for event in Client.listen(): ... was executed. Client.listen() and "events" are removed.
  2. To handle ERROR frames and heart-beats, pass handlers to Client().
  3. To subscribe to destinations: subscription = await Client.subscribe(destination, handler) (note that it is not a context manager anymore). To unsubscribe: await subscription.unsubscribe().
  4. Client will block at end of async-with block if there are any active subscriptions.

See the README.md for more.

Before:

async with asyncio.TaskGroup() as task_group, client.subscribe("DLQ"):
    async for event in client.listen():
        match event:
            case stompman.MessageEvent(body=body):
                task_group.create_task(event.with_auto_ack(handle_message(body), on_suppressed_exception=print))

After:

await client.subscribe("DLQ", handle_message)

(and listening happens in background)

  • Implement reconnects on writing and reading frames by @vrslev in #45

Before, stompman.ConnectionLostError was raised each time connection had lost. Now, client will attempt to reconnect, if it fails, stompman.FailedAllConnectAttemptsError will be raised. There's also stompman.RepeatedConnectionLostError for case when connection gets lost when trying to do a single operation like send a frame.
I expect the client to have much more stable behavior after this change.

Maintenance

New Contributors

Full Changelog: 0.8.0...1.0.0