---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    funktion.fabric8.io/kind: Connector
  name: paho
data:
  deployment.yml: |
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        funktion.fabric8.io/kind: Subscription
        connector: paho
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            funktion.fabric8.io/kind: Subscription
            connector: paho
        spec:
          containers:
          - image: funktion/connector-paho:${project.version}
            name: connector
  schema.yml: |
    ---
    component:
      kind: component
      scheme: paho
      syntax: paho:topic
      title: Paho
      description: Component for communicating with MQTT M2M message brokers using Eclipse Paho MQTT Client.
      label: messaging,iot
      deprecated: false
      async: false
      javaType: org.apache.camel.component.paho.PahoComponent
      groupId: org.apache.camel
      artifactId: camel-paho
      version: 2.18.3
    componentProperties:
      brokerUrl:
        kind: property
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: The URL of the MQTT broker.
        order: 0
      clientId:
        kind: property
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: MQTT client identifier.
        order: 1
      connectOptions:
        kind: property
        type: object
        javaType: org.eclipse.paho.client.mqttv3.MqttConnectOptions
        deprecated: false
        secret: false
        description: Client connection options
        order: 2
    properties:
      topic:
        kind: path
        group: common
        required: true
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Name of the topic
        order: 0
      brokerUrl:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: tcp://localhost:1883
        description: The URL of the MQTT broker.
        order: 1
      clientId:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: MQTT client identifier.
        order: 2
      connectOptions:
        kind: parameter
        group: common
        type: object
        javaType: org.eclipse.paho.client.mqttv3.MqttConnectOptions
        deprecated: false
        secret: false
        description: Client connection options
        order: 3
      filePersistenceDirectory:
        kind: parameter
        group: common
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: Current directory
        description: Base directory used by the file persistence provider.
        order: 4
      persistence:
        kind: parameter
        group: common
        type: string
        javaType: org.apache.camel.component.paho.PahoPersistence
        enum:
        - FILE
        - MEMORY
        deprecated: false
        secret: false
        defaultValue: MEMORY
        description: Client persistence to be used - memory or file.
        order: 5
      qos:
        kind: parameter
        group: common
        type: integer
        javaType: int
        deprecated: false
        secret: false
        defaultValue: "2"
        description: Client quality of service level (0-2).
        order: 6
      retained:
        kind: parameter
        group: common
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Retain option
        order: 7
      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: 8
      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: 9
      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: 10
      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: 11
  documentation.adoc: |+
    [[Paho-PahoComponent]]
    Paho Component
    ~~~~~~~~~~~~~~

    INFO: Available as of Camel 2.16 

    Paho component provides connector for the MQTT messaging protocol using
    the https://eclipse.org/paho/[Eclipse Paho] library. Paho is one of the
    most popular MQTT libraries, so if you would like to integrate it with
    your Java project - Camel Paho connector is a way to go.

    [[Paho-URIformat]]
    URI format
    ^^^^^^^^^^

    [source,java]
    ------------------------
    paho:queueName[?options]
    ------------------------

    For example the following snippet reads messages from the MQTT broker
    installed on the same host as the Camel router:

    [source,java]
    ------------------------
    from("paho:some/queue").
      to("mock:test");
    ------------------------

    While the snippet below sends message to the MQTT broker:

    [source,java]
    -------------------------------
    from("direct:test").
      to("paho:some/target/queue");
    -------------------------------

    You can append query options to the URI in the following
    format: `?option=value&option=value&...` . For example this is how
    to read messages from the remote MQTT broker: 

     

    [source,java]
    -------------------------------------------------------------
    from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883").
      to("mock:test");
    -------------------------------------------------------------

     

    [[Paho-Addingthecomponenttotheproject]]
    Adding the component to the project
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    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-paho</artifactId>
        <version>x.y.z</version>
        <!-- use the same version as your Camel core version -->
    </dependency>
    ------------------------------------------------------------

    Keep in mind that Paho artifacts are not hosted in the Maven Central, so
    you need to add Eclipse Paho repository to your POM xml file:

    [source,xml]
    --------------------------------------------------------------------------
    <repositories>
      <repository>
        <id>eclipse-paho</id>
        <url>https://repo.eclipse.org/content/repositories/paho-releases</url>
        <snapshots>
          <enabled>false</enabled>
        </snapshots>
      </repository>
    </repositories>
    --------------------------------------------------------------------------

    [[Paho-Defaultpayloadtype]]
    Default payload type
    ^^^^^^^^^^^^^^^^^^^^

     

    By default Camel Paho component operates on the binary payloads
    extracted out of (or put into) the MQTT message:

    [source,java]
    ---------------------------------------------------------------------
    // Receive payload
    byte[] payload = (byte[]) consumerTemplate.receiveBody("paho:topic");
     
    // Send payload
    byte[] payload = "message".getBytes();
    producerTemplate.sendBody("paho:topic", payload);
    ---------------------------------------------------------------------

     

    But of course Camel build-in link:type-converter.html[type conversion
    API] can perform the automatic data type transformations for you. In the
    example below Camel automatically converts binary payload into String
    (and conversely):

     

    [source,java]
    --------------------------------------------------------------------------
    // Receive payload
    String payload = consumerTemplate.receiveBody("paho:topic", String.class);
     
    // Send payload
    String payload = "message";
    producerTemplate.sendBody("paho:topic", payload);
    --------------------------------------------------------------------------

    [[Paho-URIOptions]]
    Paho Options
    ^^^^^^^^^^^^



    // component options: START
    The Paho component supports 3 options which are listed below.



    {% raw %}
    [width="100%",cols="2,1m,7",options="header"]
    |=======================================================================
    | Name | Java Type | Description
    | brokerUrl | String | The URL of the MQTT broker.
    | clientId | String | MQTT client identifier.
    | connectOptions | MqttConnectOptions | Client connection options
    |=======================================================================
    {% endraw %}
    // component options: END




    // endpoint options: START
    The Paho component supports 12 endpoint options which are listed below:

    {% raw %}
    [width="100%",cols="2,1,1m,1m,5",options="header"]
    |=======================================================================
    | Name | Group | Default | Java Type | Description
    | topic | common |  | String | *Required* Name of the topic
    | brokerUrl | common | tcp://localhost:1883 | String | The URL of the MQTT broker.
    | clientId | common |  | String | MQTT client identifier.
    | connectOptions | common |  | MqttConnectOptions | Client connection options
    | filePersistenceDirectory | common | Current directory | String | Base directory used by the file persistence provider.
    | persistence | common | MEMORY | PahoPersistence | Client persistence to be used - memory or file.
    | qos | common | 2 | int | Client quality of service level (0-2).
    | retained | common | false | boolean | Retain option
    | 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


    [[Paho-Headers]]
    Headers
    ^^^^^^^

    The following headers are recognized by the Paho component:

    [width="100%",cols="10%,10%,10%,10%,60%",options="header",]
    |=======================================================================
    |Header |Java constant |Endpoint type |Value type |Description

    |`PahoOriginalMessage` |`PahoConstants.HEADER_ORIGINAL_MESSAGE` |Consumer |`org.eclipse.paho.client.mqttv3.MqttMessage` |The original Paho message instance received by the client.
    *Deprecated:*from Camel 2.17 onwards the original MqttMessage is not
    stored as a header but on the
    `org.apache.camel.component.paho.PahoMessage` message that has a getter
    `getMqttMessage`.

    |`CamelMqttTopic` |PahoConstants.MQTT_TOPIC |Consumer |String |*Camel 2.17:*The topic
    |=======================================================================
     

    [[Paho-SeeAlso]]
    See Also
    ^^^^^^^^

    * link:configuring-camel.html[Configuring Camel]
    * link:component.html[Component]
    * link:endpoint.html[Endpoint]
    * link:getting-started.html[Getting Started]

