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

Enhance application-x-struct data type #1638

Conversation

christophd
Copy link
Contributor

  • Support empty message body value and initialize the application-x-struct data type with empty JsonNode {} value
  • Allows follow-up action Kamelets such as insert-field-action to add more fields to the empty JsonNode body

Example:

  1. webhook-source creates empty message body
  2. application-x-struct data-type used as output data type initializes empty JsonNode
  3. insert-field action Kamelet uses header fields to set fields on the JsonNode
  4. Json struct gets serialized to String value as outcome

- Support empty message body value and initialize the application-x-struct data type with empty JsonNode {} value
- Allows follow-up action Kamelets such as insert-field-action to add more fields to the empty JsonNode body
@christophd
Copy link
Contributor Author

Webhook called with http://localhost:8080/bookings?name=foo&amount=100
result in Json {"name": "foo", "amount": "100"} on Kafka sink

apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
  name: webhook-source-booking-pipe
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: webhook-source
    properties:
      subpath: bookings
    dataTypes:
      out:
        format: application-x-struct
  steps:
    - ref:
        kind: Kamelet
        apiVersion: camel.apache.org/v1
        name: insert-field-action
      properties:
        field: fruit
        value: ${header[name]}
    - ref:
        kind: Kamelet
        apiVersion: camel.apache.org/v1
        name: insert-field-action
      properties:
        field: amount
        value: ${header[amount]}
  sink:
    ref:
      kind: KafkaTopic
      apiVersion: kafka.strimzi.io/v1beta2
      name: bookings
    properties:
      brokers: localhost:9092
    dataTypes:
      in:
        format: plain-text

@christophd christophd merged commit bb84c2f into apache:main Sep 18, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants