---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    funktion.fabric8.io/kind: Connector
  name: avro
data:
  deployment.yml: |
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        funktion.fabric8.io/kind: Subscription
        connector: avro
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            funktion.fabric8.io/kind: Subscription
            connector: avro
        spec:
          containers:
          - image: funktion/connector-avro:${project.version}
            name: connector
  schema.yml: |
    ---
    component:
      kind: component
      scheme: avro
      syntax: avro:transport:host:port/messageName
      title: Avro
      description: Working with Apache Avro for data serialization.
      label: messaging,transformation
      deprecated: false
      async: true
      javaType: org.apache.camel.component.avro.AvroComponent
      groupId: org.apache.camel
      artifactId: camel-avro
      version: 2.18.3
    componentProperties:
      configuration:
        kind: property
        type: object
        javaType: org.apache.camel.component.avro.AvroConfiguration
        deprecated: false
        secret: false
        description: To use a shared AvroConfiguration to configure options once
        order: 0
    properties:
      transport:
        kind: path
        group: common
        required: true
        type: string
        javaType: org.apache.camel.component.avro.AvroTransport
        enum:
        - http
        - netty
        deprecated: false
        secret: false
        description: Transport to use
        order: 0
      port:
        kind: path
        group: common
        required: true
        type: integer
        javaType: int
        deprecated: false
        secret: false
        description: Port number to use
        order: 1
      host:
        kind: path
        group: common
        required: true
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Hostname to use
        order: 2
      messageName:
        kind: path
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: The name of the message to send.
        order: 3
      protocol:
        kind: parameter
        group: common
        type: object
        javaType: org.apache.avro.Protocol
        deprecated: false
        secret: false
        description: Avro protocol to use
        order: 4
      protocolClassName:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Avro protocol to use defined by the FQN class name
        order: 5
      protocolLocation:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Avro protocol location
        order: 6
      reflectionProtocol:
        kind: parameter
        group: common
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be auto detected
        order: 7
      singleParameter:
        kind: parameter
        group: common
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: If true consumer parameter won't be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message
        order: 8
      uriAuthority:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Authority to use (username and password)
        order: 9
      bridgeErrorHandler:
        kind: parameter
        group: consumer
        label: consumer
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: false
        description: Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
        order: 10
      exceptionHandler:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: object
        javaType: org.apache.camel.spi.ExceptionHandler
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
        order: 11
      exchangePattern:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: string
        javaType: org.apache.camel.ExchangePattern
        enum:
        - InOnly
        - RobustInOnly
        - InOut
        - InOptionalOut
        - OutOnly
        - RobustOutOnly
        - OutIn
        - OutOptionalIn
        deprecated: false
        secret: false
        description: Sets the exchange pattern when the consumer creates an exchange.
        order: 12
      synchronous:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
        order: 13
  documentation.adoc: |
    [[avro-AvroComponent]]
    Avro Component
    ~~~~~~~~~~~~~~

    *Available as of Camel 2.10*

    This component provides a dataformat for avro, which allows
    serialization and deserialization of messages using Apache Avro's binary
    dataformat. Moreover, it provides support for Apache Avro's rpc, by
    providing producers and consumers endpoint for using avro over netty or
    http.

    Maven users will need to add the following dependency to their `pom.xml`
    for this component:

    [source,xml]
    ------------------------------------------------------------
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-avro</artifactId>
        <version>x.x.x</version>
        <!-- use the same version as your Camel core version -->
    </dependency>
    ------------------------------------------------------------

    [[avro-ApacheAvroOverview]]
    Apache Avro Overview
    ^^^^^^^^^^^^^^^^^^^^

    Avro allows you to define message types and a protocol using a json like
    format and then generate java code for the specified types and messages.
    An example of how a schema looks like is below.

    [source,xml]
    ------------------------------------------------------------------------------------------
    {"namespace": "org.apache.camel.avro.generated",
     "protocol": "KeyValueProtocol",

     "types": [
         {"name": "Key", "type": "record",
          "fields": [
              {"name": "key",   "type": "string"}
          ]
         },
         {"name": "Value", "type": "record",
          "fields": [
              {"name": "value",   "type": "string"}
          ]
         }
     ],

     "messages": {
         "put": {
             "request": [{"name": "key", "type": "Key"}, {"name": "value", "type": "Value"} ],
             "response": "null"
         },
         "get": {
             "request": [{"name": "key", "type": "Key"}],
             "response": "Value"
         }
     }
    }
    ------------------------------------------------------------------------------------------

    You can easily generate classes from a schema, using maven, ant etc.
    More details can be found at the
    http://avro.apache.org/docs/current/[Apache Avro documentation].

    However, it doesn't enforce a schema first approach and you can create
    schema for your existing classes. *Since 2.12* you can use existing
    protocol interfaces to make RCP calls. You should use interface for the
    protocol itself and POJO beans or primitive/String classes for parameter
    and result types. Here is an example of the class that corresponds to
    schema above:

    [source,java]
    --------------------------------------------------------------
    package org.apache.camel.avro.reflection;

    public interface KeyValueProtocol {
        void put(String key, Value value);
        Value get(String key);
    }

    class Value {
        private String value;
        public String getValue() { return value; }
        public void setValue(String value) { this.value = value; }
    }
    --------------------------------------------------------------

    _Note: Existing classes can be used only for RPC (see below), not in
    data format._

    [[avro-UsingtheAvrodataformat]]
    Using the Avro data format
    ^^^^^^^^^^^^^^^^^^^^^^^^^^

    Using the avro data format is as easy as specifying that the class that
    you want to marshal or unmarshal in your route.

    [source,xml]
    --------------------------------------------------------------------------------
        <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
            <route>
                <from uri="direct:in"/>
                <marshal>
                    <avro instanceClass="org.apache.camel.dataformat.avro.Message"/>
                </marshal>
                <to uri="log:out"/>
            </route>
        </camelContext>
    --------------------------------------------------------------------------------

    An alternative can be to specify the dataformat inside the context and
    reference it from your route.

    [source,xml]
    --------------------------------------------------------------------------------------
        <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
             <dataFormats>
                <avro id="avro" instanceClass="org.apache.camel.dataformat.avro.Message"/>
            </dataFormats>
            <route>
                <from uri="direct:in"/>
                <marshal ref="avro"/>
                <to uri="log:out"/>
            </route>
        </camelContext>
    --------------------------------------------------------------------------------------

    In the same manner you can umarshal using the avro data format.

    [[avro-UsingAvroRPCinCamel]]
    Using Avro RPC in Camel
    ^^^^^^^^^^^^^^^^^^^^^^^

    As mentioned above Avro also provides RPC support over multiple
    transports such as http and netty. Camel provides consumers and
    producers for these two transports.

    [source,java]
    ----------------------------------------
    avro:[transport]:[host]:[port][?options]
    ----------------------------------------

    The supported transport values are currently http or netty.

    *Since 2.12* you can specify message name right in the URI:

    [source,java]
    ------------------------------------------------------
    avro:[transport]:[host]:[port][/messageName][?options]
    ------------------------------------------------------

    For consumers this allows you to have multiple routes attached to the
    same socket. Dispatching to correct route will be done by the avro
    component automatically. Route with no messageName specified (if any)
    will be used as default.

    When using camel producers for avro ipc, the "in" message body needs to
    contain the parameters of the operation specified in the avro protocol.
    The response will be added in the body of the "out" message.

    In a similar manner when using camel avro consumers for avro ipc, the
    requests parameters will be placed inside the "in" message body of the
    created exchange and once the exchange is processed the body of the
    "out" message will be send as a response.

    *Note:* By default consumer parameters are wrapped into array. If you've
    got only one parameter, *since 2.12* you can use `singleParameter` URI
    option to receive it direcly in the "in" message body without array
    wrapping.

    [[avro-AvroRPCURIOptions]]
    Avro RPC URI Options
    ^^^^^^^^^^^^^^^^^^^^





    // component options: START
    The Avro component supports 1 options which are listed below.



    {% raw %}
    [width="100%",cols="2,1m,7",options="header"]
    |=======================================================================
    | Name | Java Type | Description
    | configuration | AvroConfiguration | To use a shared AvroConfiguration to configure options once
    |=======================================================================
    {% endraw %}
    // component options: END






    // endpoint options: START
    The Avro component supports 14 endpoint options which are listed below:

    {% raw %}
    [width="100%",cols="2,1,1m,1m,5",options="header"]
    |=======================================================================
    | Name | Group | Default | Java Type | Description
    | transport | common |  | AvroTransport | *Required* Transport to use
    | port | common |  | int | *Required* Port number to use
    | host | common |  | String | *Required* Hostname to use
    | messageName | common |  | String | The name of the message to send.
    | protocol | common |  | Protocol | Avro protocol to use
    | protocolClassName | common |  | String | Avro protocol to use defined by the FQN class name
    | protocolLocation | common |  | String | Avro protocol location
    | reflectionProtocol | common | false | boolean | If protocol object provided is reflection protocol. Should be used only with protocol parameter because for protocolClassName protocol type will be auto detected
    | singleParameter | common | false | boolean | If true consumer parameter won't be wrapped into array. Will fail if protocol specifies more then 1 parameter for the message
    | uriAuthority | common |  | String | Authority to use (username and password)
    | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
    | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
    | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern when the consumer creates an exchange.
    | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
    |=======================================================================
    {% endraw %}
    // endpoint options: END


    [[avro-AvroRPCHeaders]]
    Avro RPC Headers
    ^^^^^^^^^^^^^^^^

    [width="100%",cols="20%,80%",options="header",]
    |=======================================================================
    |Name |Description

    |`CamelAvroMessageName` |The name of the message to send. In consumer overrides message name from
    URI (if any)
    |=======================================================================

    [[avro-Examples]]
    Examples
    ^^^^^^^^

    An example of using camel avro producers via http:

    [source,xml]
    ---------------------------------------------------------------------------------------------------------------------------
            <route>
                <from uri="direct:start"/>
                <to uri="avro:http:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/>
                <to uri="log:avro"/>
            </route>
    ---------------------------------------------------------------------------------------------------------------------------

    In the example above you need to fill `CamelAvroMessageName` header.
    *Since 2.12* you can use following syntax to call constant messages:

    [source,xml]
    -------------------------------------------------------------------------------------------------------------------------------
            <route>
                <from uri="direct:start"/>
                <to uri="avro:http:localhost:{{avroport}}/put?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/>
                <to uri="log:avro"/>
            </route>
    -------------------------------------------------------------------------------------------------------------------------------

    An example of consuming messages using camel avro consumers via netty:

    [source,xml]
    ------------------------------------------------------------------------------------------------------------------------------
            <route>
                <from uri="avro:netty:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/>
                <choice>
                    <when>
                        <el>${in.headers.CamelAvroMessageName == 'put'}</el>
                        <process ref="putProcessor"/>
                    </when>
                    <when>
                        <el>${in.headers.CamelAvroMessageName == 'get'}</el>
                        <process ref="getProcessor"/>
                    </when>
                </choice>
            </route>
    ------------------------------------------------------------------------------------------------------------------------------

    *Since 2.12* you can set up two distinct routes to perform the same
    task:

    [source,xml]
    -------------------------------------------------------------------------------------------------------------------------------------------------------
            <route>
                <from uri="avro:netty:localhost:{{avroport}}/put?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol">
                <process ref="putProcessor"/>
            </route>
            <route>
                <from uri="avro:netty:localhost:{{avroport}}/get?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol&singleParameter=true"/>
                <process ref="getProcessor"/>
            </route>
    -------------------------------------------------------------------------------------------------------------------------------------------------------

    In the example above, get takes only one parameter, so `singleParameter`
    is used and `getProcessor` will receive Value class directly in body,
    while `putProcessor` will receive an array of size 2 with String key and
    Value value filled as array contents.
