Skip to content

Commit

Permalink
Improve Protobuf serialization/deserialization Kamelets
Browse files Browse the repository at this point in the history
- Use Protobuf schema resolver from Camel core
- Add YAKS tests for Protobuf serdes
  • Loading branch information
christophd committed May 6, 2024
1 parent 7edcef9 commit b06399e
Show file tree
Hide file tree
Showing 30 changed files with 414 additions and 247 deletions.
2 changes: 1 addition & 1 deletion kamelets/protobuf-deserialize-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
template:
beans:
- name: schemaResolver
type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver"
type: "#class:org.apache.camel.component.jackson.protobuf.transform.ProtobufSchemaResolver"
property:
- key: schema
value: '{{schema:}}'
Expand Down
2 changes: 1 addition & 1 deletion kamelets/protobuf-serialize-action.kamelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
template:
beans:
- name: schemaResolver
type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver"
type: "#class:org.apache.camel.component.jackson.protobuf.transform.ProtobufSchemaResolver"
property:
- key: schema
value: '{{schema:}}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public enum MimeType {
JSON("application/json"),
PROTOBUF("application/protobuf"),
PROTOBUF_BINARY("protobuf/binary"),
PROTOBUF_STRUCT("protobuf/x-struct"),
AVRO("application/avro"),
AVRO_BINARY("avro/binary"),
AVRO_STRUCT("avro/x-struct"),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver;
import org.apache.camel.component.jackson.protobuf.transform.ProtobufSchemaResolver;
import org.apache.camel.component.jackson.transform.JsonSchemaResolver;
import org.apache.camel.kamelets.utils.format.MimeType;
import org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver;
import org.apache.camel.util.ObjectHelper;

/**
Expand Down Expand Up @@ -63,6 +63,8 @@ public void process(Exchange exchange) throws Exception {
private Processor fromMimeType(MimeType mimeType) {
switch (mimeType) {
case PROTOBUF:
case PROTOBUF_BINARY:
case PROTOBUF_STRUCT:
ProtobufSchemaResolver protobufSchemaResolver = new ProtobufSchemaResolver();
protobufSchemaResolver.setSchema(this.schema);
protobufSchemaResolver.setContentClass(this.contentClass);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
template:
beans:
- name: schemaResolver
type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver"
type: "#class:org.apache.camel.component.jackson.protobuf.transform.ProtobufSchemaResolver"
property:
- key: schema
value: '{{schema:}}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
template:
beans:
- name: schemaResolver
type: "#class:org.apache.camel.kamelets.utils.format.schema.protobuf.ProtobufSchemaResolver"
type: "#class:org.apache.camel.component.jackson.protobuf.transform.ProtobufSchemaResolver"
property:
- key: schema
value: '{{schema:}}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@RunWith(Cucumber.class)
@CucumberOptions(
//features = "src/test/resources/openapi",
extraGlue = "org.citrusframework.yaks",
plugin = { "pretty", "org.citrusframework.yaks.report.TestReporter" }
)
Expand Down
10 changes: 5 additions & 5 deletions tests/camel-kamelets-itest/src/test/resources/avro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This test verifies the Avro serialization/deserialization actions

The test verifies the proper Avro serialization and deserialization of Avro.

The test uses two Pipes that interact with each other. The first binding `json-to-avro` periodically creates a test data event as Json and applies the `avro/binary` data type using the schema in [User.avsc](User.avsc).
The test uses two Pipes that interact with each other. The first binding `avro-binary-source-pipe` periodically creates a test data event as Json and applies the `avro/binary` data type using the schema in [User.avsc](User.avsc).

The binary Avro data is then sent to a Http webhook sink that references an Http endpoint that is provided by the 2nd binding `avro-to-log`. The `avro-to-log` binding provides the Http service and deserializes the binary Avro data using the same User schema. The deserialized data is printed to the log output.
The binary Avro data is then sent to a Http webhook sink that references a Http endpoint that is provided by the 2nd binding `avro-deserialize-pipe`. The `avro-deserialize-pipe` binding provides the Http service and deserializes the binary Avro data using the same User schema. The deserialized data is printed to the log output.

The test starts both Pipes and is able to verify the proper log output as an expected outcome.

Expand All @@ -18,8 +18,8 @@ The test performs the following high level steps:

*Avro data type feature*
- Create test data based on the User.avsc Avro schema
- Load and run the `avro-to-log` Pipe
- Load and run the `json-to-avro` Pipe
- Load and run the `avro-deserialize-pipe` Pipe
- Load and run the `avro-binary-source-pipe` Pipe
- Verify that the bindings do interact with each other and the proper test data is logged in the binding output

## Installation
Expand All @@ -36,7 +36,7 @@ You can review the installation steps for the tooling in the documentation:
To run tests with URI based configuration:

```shell script
$ yaks run --local test/avro-serdes-action/avro-serdes-action.feature
$ yaks run --local test/avro/avro-serdes-action.feature
```

You will be provided with the test log output and the test results.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: AWS S3 Source - Http sink
Given Kubernetes timeout is 60000 ms
Given HTTP server timeout is 60000 ms
Given HTTP server "test-service"
Given start HTTP server
Given variables
| aws.s3.bucketNameOrArn | mybucket |
| aws.s3.message | Hello from S3 Kamelet |
Expand Down Expand Up @@ -48,3 +49,4 @@ Feature: AWS S3 Source - Http sink
Given delete Kubernetes service test-service
# Stop LocalStack container
Given stop LocalStack container
And stop HTTP server
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: Earthquake source
Background:
Given HTTP server timeout is 150000 ms
Given HTTP server "test-service"
Given start HTTP server

Scenario: Create Http server
Given create Kubernetes service test-service with target port 8080
Expand All @@ -39,3 +40,4 @@ Feature: Earthquake source
Scenario: Remove Camel K resources
Given delete Pipe earthquake-to-http
And delete Kubernetes service test-service
And stop HTTP server
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ Feature: Kafka Kamelet source
Given delete Pipe kafka-source-pipe
And delete Kubernetes service test-service
And stop Redpanda container
And stop HTTP server
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ Feature: Mail Sink
Scenario: Remove Camel K resources
Given delete Pipe timer-to-mail
And delete Kubernetes service mail-server
And stop server component mail-server
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: REST OpenAPI Kamelet sink
Background:
Given HTTP server timeout is 60000 ms
Given HTTP server "test-service"
Given start HTTP server
Given variable petId is "1000"
Given load variable pet.json

Expand Down Expand Up @@ -64,3 +65,4 @@ Feature: REST OpenAPI Kamelet sink
Scenario: Remove resources
Given delete Pipe rest-openapi-sink-pipe
And delete Kubernetes service test-service
And stop HTTP server
Loading

0 comments on commit b06399e

Please sign in to comment.