Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Protobuf serialization/deserialization Kamelets #2019

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading