Repository navigation
feat: #2324 publish Avro binary mock messages on the NATS binding - #2325
Conversation
…ding Mock messages declared with an Avro binary content type were published on NATS as the rendered text of their example, so a consumer decoding Avro read UTF-8 JSON and failed. Only the Kafka binding converted the example to Avro. Move the Avro schema lookup out of produceKafkaAvroMockMessage into a binding-agnostic retrieveAvroSchema, and branch produceNatsMockMessage on Constants.AVRO_BINARY_CONTENT_TYPES the way the Kafka one does. NATSProducerManager gains a byte[] publishMessage overload; both overloads now share a single publish path. NATS has no schema registry integration, so raw Avro binary is the only encoding produced here - there is no equivalent of the Kafka REGISTRY fork. When no schema can be found nothing is published, rather than falling back to the JSON text on a channel the document declares as Avro. Together with the preceding commit this makes both directions work for an AsyncAPI 3.0 document with Avro payloads over NATS: the implementation's messages can be verified against the contract, and the contract's examples can be mocked back to the implementation. testProduceNatsAvroMockMessagesFromAsyncAPI3MultiFormatSchema covers that combination end to end against a real broker - it needs the Multi Format Schema Object unwrapping to resolve the schema and this commit to encode the bytes. Signed-off-by: Drazen Nikolic <[email protected]>
|
Welcome to the Microcks community! 💖 Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly. Hope you have a great time there! |
It's awesome you also did this comprehensive test! Thanks! |
| payload: | ||
| fullName: Laurent Broudoux | ||
| email: "[email protected]" | ||
| age: 41 |
There was a problem hiding this comment.
Ouch! This comes from a long time ago ... I'm way older now 😢
lbroudoux
left a comment
There was a problem hiding this comment.
Looks all good to me. Thanks for taking the time to push this improvement! I'll merge it once the build finished (just to check it's green)
|
You are now a Microcks community contributor! 💖 Thanks and congrats 🚀 on merging your first pull request! We are delighted and very proud of you! 👏 📢 If you're using Microcks in your organization, please add your company name to this list. 🙏 It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact. If you need to know why and how to add yourself to the list, please read the blog post "Join the Microcks Adopters list and Empower the vibrant open source Community 🙌" Kudos and please keep going, we need you 🙌 |
Closes #2324
What this PR does
Mock messages declared with an Avro binary content type (
avro/binary,application/avro,application/octet-stream) were published on NATS as the rendered JSON text of their example, so Avro consumers failed to decode them. Only the Kafka binding converted examples to Avro.This PR makes the NATS binding encode those messages as Avro binary too, reusing the Kafka schema lookup:
ProducerManager: the Avro schema lookup is extracted fromproduceKafkaAvroMockMessageinto a binding-agnosticretrieveAvroSchema(AsyncMockDefinition).produceNatsMockMessagenow branches onConstants.AVRO_BINARY_CONTENT_TYPESand delegates to a newproduceNatsAvroMockMessage.NATSProducerManager: newpublishMessage(String, byte[], Headers)overload; both overloads share a single publish path.Behaviour notes:
REGISTRYencoding).Together with #2320, this makes both directions work for an AsyncAPI 3.0 document with Avro payloads over NATS: implementation messages can be validated against the contract, and the contract's examples can be mocked back.
Tests
ProducerManagerTest: Avro vs. text routing on NATS and the missing-schema case.NATSProducerManagerIT:testProduceNatsAvroMockMessagesFromAsyncAPI3MultiFormatSchemapublishes Avro from an AsyncAPI 3.0 Multi Format Schema document against a real NATS broker and decodes it on the consumer side (new resourceuser-signedup-avro-multiformat-asyncapi-3.0.yaml).Verified locally:
mvn clean installfrom the root: all modules and unit tests pass.mvn -Pit testinminions/async: 28 ITs pass.microcks-uber-async-minionimage built from this branch, used withmicrocks-uber:1.15.0in a downstream project's Testcontainers suite, passes its Avro-over-NATS mocking ITs (the minion publishes Avro, the consumer decodes it) and its contract ITs.AI disclosure
This change was developed with the help of an AI assistant (Claude Code), in line with the AI Contribution Policy. I have reviewed, tested and take responsibility for the code.
🤖 Generated with Claude Code