davsclaus opened a new pull request, #3275:
URL: https://github.com/apache/camel-kamelets/pull/3275

   Part of #3117: default data types on the Messaging and Kafka Kamelets where 
the body is fixed. The Citrus tests of these families came in #3265 and #3268; 
this PR updates the body types they expect.
   
   | Kamelet | `in` | `out` | What changes |
   |---|---|---|---|
   | `pulsar-sink`, `mqtt5-sink` | `binary` | | Before sending, the body is 
turned into `byte[]` and `Content-Type` is set to `application/octet-stream`. 
Pulsar and the MQTT broker get the same bytes as before, as the producers 
already turned the body into bytes and send no headers. A route that goes on 
after the sink now sees `byte[]` and that `Content-Type` |
   | `value-to-key-action`, `message-timestamp-router-action` | | `json` | The 
body is `byte[]` instead of a stream (`InputStreamCache`), with `Content-Type: 
application/json`. `value-to-key-action` now also does this for a message 
without `Content-Type: application/json` |
   
   Also: the description of `kafka-batch-source` now says that each entry of 
the `List` is a Camel `Exchange` for one record, read with 
`getMessage().getBody()`. It used to say "a message of its own", which a test 
in #3265 found misleading.
   
   ### No defaults on the sources, because of a Camel bug
   A source's `out` data type does not run where #3117 expects.
   - **When it runs:** Camel applies it as the output type of the Kamelet's 
route, after the route has finished. A source hands each message on through 
`kamelet:sink`, which runs the consuming route inside it. So the transformer 
runs only after the consuming route has ended:
     - The next step never sees the declared type.
     - When the consuming route ends with a body the transformer cannot 
convert, the message fails at the end, for example a `Map` with `binary`: 
`CamelExecutionException: Failed to convert body to 'java:[B' ... at 
ContractAdvice.after`. A broker source then gets the message again.
   - **Checked** with `camel run` on 4.24.0-SNAPSHOT, with a test source 
declaring `out: binary`: the next step saw `java.lang.String` and no 
`Content-Type`, and a route ending with a `Map` failed as above.
   - **Already affected:** the 16 sources that declare an `out` default today, 
such as `aws-s3-source` and `aws-sqs-source`.
   - **What I am doing about it:** I noted it on #3117. It needs a fix in 
Camel: apply the output type when the message is handed to `kamelet:sink`. 
Until then, no new source defaults.
   
   Sink `in` defaults and action defaults are not affected. They run where 
expected, as the tests of #3263 and this PR show.
   
   ### No default, and why
   - **JMS sources:** the body is a `String`, `byte[]` or `Map`, depending on 
the JMS message type, and the sender's `Content-Type` arrives as a property, 
which `binary` would replace.
   - **JMS sinks:** `binary` would turn a text message into a bytes message.
   - **`spring-rabbitmq-sink`:** `binary` would change the content type of text 
messages from `text/plain` to `application/octet-stream`.
   - **`nats-source` and `nats-sink`:** the `Content-Type` travels as a NATS 
header, and would be replaced or sent on.
   - **`smpp-source`:** the body is text, bytes or none.
   - **`smpp-sink`:** with `alphabet` 4, it sends bytes as they are.
   - **`kafka-source`:** a tombstone has no body, and the record headers can 
carry the sender's `Content-Type`.
   - **`kafka-sink`:** the body goes through the String serializer or the 
schema registry, and `Content-Type` would be sent as a record header.
   - **`kafka-batch-source`:** the body is a `List`.
   - **The header-only Kafka actions:** they pass the body on unchanged.
   
   ### Upgrade note
   For #3190, under the data types, when this is merged:
   - `pulsar-sink` and `mqtt5-sink` turn the body into `byte[]` with 
`Content-Type: application/octet-stream`. What reaches the broker is unchanged.
   - `value-to-key-action` and `message-timestamp-router-action` give `byte[]` 
instead of a stream.
   
   ### Tests
   - **Citrus:** `MessagingIT#pulsar` and `CommonIT#kafkaRouter`: 9 of 9 pass.
     - The `pulsar-sink` test checks the text through an `X-Body` header, as 
Citrus reads `application/octet-stream` as bytes.
     - `mqtt5-sink` was checked by hand against `eclipse-mosquitto:2`: the 
subscriber got the same text, because the `mqtt5` Citrus tests are disabled 
since #2925.
   - **Build:** `./mvnw clean install` from the root passes, run twice.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to