qweeze / rstream

A Python asyncio-based client for RabbitMQ Streams
MIT License
83 stars 13 forks source link

Migrate amqp library #194

Closed DanielePalaia closed 6 months ago

DanielePalaia commented 6 months ago

This closes #183

The uamqp library has been replaced with the code used here:

https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp

to allow support for ARM architecture and because the uamqp library wouldn't be supported after 2025 anyway.

It seems like this library is also 15/20% faster than the original one.

In this library we are missing the body type which is automatically able to detect the type passed and to the conversion so we need to pass a binary like:

            amqp_message = AMQPMessage(
                body=bytes("hello: {}".format(i), "utf-8"),
            )

Also if you were previously using amqp fields like Properties this are now imported from rstream directly:

Before

import uamqp

message_properties = uamqp.message.MessageProperties("MessageId"+str(i), None, bytes("guest",'utf-8'), None, "CorrelationId"+str(i), "text/plain", "utf-8", None, None, None, None, 9999, "MyReplyToGroupId", None)

Now:

from rstream import
message_properties = Properties(message_id="MessageId"+str(i), user_id=None, to=bytes("guest",'utf-8'), subject=None, correlation_id="CorrelationId"+str(i), content_type="text/plain", content_encoding="utf-8", absolute_expiry_time=None, creation_time=None, reply_to_group_id="MyReplyToGroupId")

This library is also using typing_extensions as dependency which needs to be included in your application (uamqp is not used anymore and can be removed).