Skip to content

Python AMQP structured mode defaults to payload media type application/json #692

Open

Description

@clemensv

Reproducer

Generated with xrcg 0.11.0 / avrotize 3.9.1 using the checked-in NVE Hydro AMQP generation script in clemensv/real-time-sources. No broker is needed:

import json
from nve_hydro_amqp_producer_amqp_producer.producer import NONVEHydrologyAmqpProducer
from nve_hydro_amqp_producer_data import Station

producer = object.__new__(NONVEHydrologyAmqpProducer)
producer.content_mode = "structured"
producer.format_type = "application/json"  # generated constructor default
sent = []
producer._send_via_blocking_sender = sent.append
station = Station(
    station_id="2.11.0", station_name="Bulken", river_name="Vosso",
    latitude=60.68, longitude=6.04, masl=None, council_name=None,
    county_name=None, drainage_basin_area=None,
)
producer.send_station("2.11.0", "vosso", station)
print(sent[0].content_type)
print(sorted(json.loads(sent[0].body)))

Observed:

application/json
['data_base64', 'id', 'source', 'specversion', 'subject', 'time', 'type']

Expected

The AMQP content-type must identify the structured CloudEvents event format, application/cloudevents+json, rather than the payload's application/json.

The generated send method calls to_structured(cloud_event) and then assigns:

amqp_msg.content_type = self.format_type or headers.get("content-type")

Because self.format_type defaults to application/json, it overrides the correct media type returned by the CloudEvents serializer.

Please derive the structured message content type from the selected event format or serializer output, independently of the payload content type. Add a generated-producer test that inspects the actual Proton Message content type.

This is separate from #638: explicitly requesting structured mode still produces the wrong media type even after the endpoint's default-mode selection is corrected. No generated code was hand-edited and no test assertion was weakened.

Spec: https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/amqp-protocol-binding.md#32-structured-content-mode

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions