azure event bus resuse ServiceBusSender similar to azure event bus java #37916
Open
Description
I was trying to resuse ServiceBusSender for topic so that i can save time to ServiceBusSender instance but sometime i got weird error like
INFO:azure.servicebus._servicebus_sender:AMQP error occurred: (MessageSendFailed('Error condition: ErrorCondition.LinkMessageSizeExceeded\n Error Description: The received message (delivery-id:123456, size:286857 bytes) exceeds the limit (262144 bytes) currently allowed on the link. TrackingId:91b3c20e-31fd-42f9-9c4d-c5acf9baad9d_B11, SystemTracker:NoSystemTracker, Timestamp:2024-10-16T04:19:23')), condition: (<ErrorCondition.LinkMessageSizeExceeded: b'amqp:link:message-size-exceeded'>), description: (b'The received message (delivery-id:123456, size:286857 bytes) exceeds the limit (262144 bytes) currently allowed on the link. TrackingId:91b3c20e-31fd-42f9-9c4d-c5acf9baad9d_B11, SystemTracker:NoSystemTracker, Timestamp:2024-10-16T04:19:23').
ERROR:root:Error sending message for 16: The received message (delivery-id:123456, size:286857 bytes) exceeds the limit (262144 bytes) currently allowed on the link. TrackingId:91b3c20e-31fd-42f9-9c4d-c5acf9baad9d_B11, SystemTracker:NoSystemTracker, Timestamp:2024-10-16T04:19:23 Error condition: amqp:link:message-size-exceeded.
INFO:azure.servicebus._pyamqp.link:Link state changed: <LinkState.ATTACHED: 3> -> <LinkState.ERROR: 6>
INFO:root:Service Bus Sender Created for 17
INFO:root:Size of the string in KB: 152.15 KB
INFO:azure.servicebus._base_handler:AMQP error occurred: (AMQPLinkError("Error condition: amqp:decode-error\n Error Description: The format code '0x30' at frame buffer offset '35' is invalid or unexpected.")), condition: (b'amqp:decode-error'), description: (b"The format code '0x30' at frame buffer offset '35' is invalid or unexpected.").
Here is my code snippet
service_bus_sender = ServiceBusClient.from_connection_string(connectionstring, logging_enable=True).get_topic_sender(topic_name="topic_1", socket_timeout=60)
logging.info("Service Bus Client Created")
for i in range(100):
try:
time.sleep(10)
logging.info("Service Bus Sender Created for %d", i)
body = json.dumps(json_data)
# Get the size of the string in bytes
size_in_bytes = sys.getsizeof(body)
# Convert bytes to kilobytes (KB)
size_in_kb = size_in_bytes / 1024
logging.info(f"Size of the string in KB: {size_in_kb:.2f} KB")
subject = "test.Post.Created"
# time.sleep(100)
service_bus_sender.send_messages(
ServiceBusMessage
(body=body, subject=subject, content_type="application/json"))
logging.info("Message Sent for %d successfully", i)
except Exception as e:
logging.error("Error sending message for %d: %s", i, str(e))
logging.info("End of Azure Event Bus")
Some messages are send successfully and some are wait or got above error not sure why it say size limit exceeded where i just send 152 kb data every time body is same i.e 152.kb. I also tried with java lib whether it's working fine and able to reuse ServiceBus sender bean.
Please suggest best way to use in optimal way so can take less time to send message
Metadata
Assignees
Labels
This issue points to a problem in the data-plane of the library.Messaging crewIssues that are reported by GitHub users external to the Azure organization.This issue requires a new behavior in the product in order be resolved.Workflow: The Azure SDK team believes it to be addressed and ready to close.