01
Identify the producer and consumer contracts
The Python Queue SDK’s default policy does not Base64-encode outgoing messages. A consumer explicitly configured with TextBase64DecodePolicy expects encoded text. Azure Functions queue bindings have their own extension settings; inspect those instead of assuming every consumer has the same default.
Our producer first sent raw JSON containing an order field. The Base64-configured consumer could not decode that payload. The send itself had succeeded because storage acceptance and application decoding were different stages.
02
Preserve the first decoding evidence
Inspect the full exception chain, not just its final line. In the tested package combination, incorrect Base64 padding was followed by an AttributeError about PipelineResponse.reason while the SDK tried to construct its decoding exception.
That secondary failure can distract from malformed input. We did not assume that every SDK version produces the same final exception, or that upgrading would fix the payload contract. The positive test used the same installed packages and a correctly encoded message.
03
Encode text deliberately when the consumer expects Base64
For this contract, configure the producer with TextBase64EncodePolicy. The following construction uses an already approved credential and intended queue endpoint. Do not change the production identity as a side effect of repairing message encoding.
Send the original JSON text through the encoding policy once. Manually Base64-encoding it and also enabling the policy would encode it twice, leaving the consumer with encoded text instead of the JSON it expects.
from azure.storage.queue import QueueClient, TextBase64EncodePolicy
producer = QueueClient(
account_url=account_url, queue_name=queue_name, credential=credential,
message_encode_policy=TextBase64EncodePolicy(),
)
producer.send_message('{"order":1}')04
Verify the consumer’s decoded content
For a Python SDK consumer, configure the matching decoder. In a Functions application, inspect the actual queue extension version and messageEncoding setting instead; this SDK example is not a Functions host integration test.
Our matched-policy test retrieved exactly {"order":1}. It verified the producer’s encoded send and the consumer’s decoded text against the same emulator, without changing the application’s JSON structure.
from azure.storage.queue import QueueClient, TextBase64DecodePolicy
consumer = QueueClient(
account_url=account_url, queue_name=queue_name, credential=credential,
message_decode_policy=TextBase64DecodePolicy(),
)
message = next(consumer.receive_messages())
assert message.content == '{"order":1}'05
Plan for messages already in the queue
A producer fix does not rewrite existing malformed messages. Classify the affected backlog through the application’s normal poison-message, retry, or remediation workflow, preserving evidence and avoiding repeated side effects.
Keep serialization, encoding, and business validation separate in tests. A message can be valid Base64 yet contain invalid JSON, or valid JSON that fails a business rule. Record which stage failed before changing retry counts or queue visibility settings.
Sınırları bil
Tested with Azurite, azure-storage-queue 12.18.0, and azure-core 1.41.0 using API version 2023-11-03. Plain JSON failed Base64 decoding; explicit Base64 production and consumption returned the original text. This SDK combination also exposed a secondary AttributeError while wrapping the malformed-input error. The Functions host was not run.
Kaynaklar ve ileri okuma
CoreTrailKit tarafından hazırlanan teknik yayın.
Bütün yazıları keşfet