Camel Components

Huawei Distributed Message Service (DMS)

Since Camel 3.12

Only producer is supported

Huawei Cloud Distributed Message Service (DMS) component allows you to integrate with DMS provided by Huawei Cloud.

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

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-huaweicloud-dms</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI Format

hwcloud-dms:operation[?options]

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Huawei Distributed Message Service (DMS) component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The Huawei Distributed Message Service (DMS) endpoint is configured using URI syntax:

hwcloud-dms:operation

With the following path and query parameters:

Path Parameters

Name Description Default Type

operation (producer)

Required The operation that the producer performs: createInstance, deleteInstance, listInstances, queryInstance or updateInstance. The CamelHwCloudDmsOperation exchange property replaces this option.

String

Query Parameters

Name Description Default Type

accessKey (producer)

Required The access key ID (AK) of the Huawei Cloud credentials. It is not used when the serviceKeys option is set.

String

accessUser (producer)

The user name of a new RabbitMQ instance, required for createInstance of a RabbitMQ instance from the options. The CamelHwCloudDmsAccessUser exchange property replaces this option.

String

availableZones (producer)

The IDs of the availability zones of the new instance, separated by commas, required for createInstance from the options. The CamelHwCloudDmsAvailableZones exchange property replaces this option.

String

endpoint (producer)

The endpoint URL of DMS, for example https://dms.cn-north-4.myhuaweicloud.com. When set, the client uses it and the region option is not used. Without a scheme, https:// is added.

String

engine (producer)

The message engine: kafka or rabbitmq. It is required for createInstance from the options, and for listInstances it lists only the instances of this engine, or all instances if not set. The CamelHwCloudDmsEngine exchange property replaces this option.

Enum values:

  • kafka

  • rabbitmq

String

engineVersion (producer)

The version of the message engine of the new instance, required for createInstance from the options. The CamelHwCloudDmsEngineVersion exchange property replaces this option.

String

instanceId (producer)

The ID of the instance, required for deleteInstance, queryInstance and updateInstance. The CamelHwCloudDmsInstanceId exchange property replaces this option.

String

kafkaManagerPassword (producer)

The password for logging in to Kafka Manager of a new Kafka instance, required for createInstance of a Kafka instance from the options. The CamelHwCloudDmsKafkaManagerPassword exchange property replaces this option.

String

kafkaManagerUser (producer)

The user name for logging in to Kafka Manager of a new Kafka instance, required for createInstance of a Kafka instance from the options. The CamelHwCloudDmsKafkaManagerUser exchange property replaces this option.

String

name (producer)

The name of the new instance, required for createInstance from the options. updateInstance takes the name from the body only. The CamelHwCloudDmsName exchange property replaces this option.

String

partitionNum (producer)

The maximum number of partitions of a new Kafka instance. It must be greater than 0 for createInstance of a Kafka instance from the options. The CamelHwCloudDmsPartitionNum exchange property replaces this option.

int

password (producer)

The password of the accessUser of a new RabbitMQ instance, required for createInstance of a RabbitMQ instance from the options. The CamelHwCloudDmsPassword exchange property replaces this option.

String

productId (producer)

The ID of the product (the instance flavor) of the new instance, required for createInstance from the options. The CamelHwCloudDmsProductId exchange property replaces this option.

String

projectId (producer)

Required The ID of the Huawei Cloud project of the DMS instances. The producer uses it in the path of every request.

String

proxyHost (producer)

The host name or IP address of the proxy server. The producer uses a proxy only when this option and the proxyPort option are set.

String

proxyPassword (producer)

The password to authenticate with the proxy server. It is used only when the proxyUser option is set.

String

proxyPort (producer)

The port of the proxy server. The producer uses a proxy only when this option is greater than 0 and the proxyHost option is set.

int

proxyUser (producer)

The user name to authenticate with the proxy server. It is used only when the proxyHost and proxyPort options are set.

String

region (producer)

Required The region ID of DMS, for example cn-north-4. The client uses the endpoint of this region when the endpoint option is not set. Only af-south-1, ap-southeast-1, ap-southeast-2, ap-southeast-3, cn-east-2, cn-east-3, cn-north-1, cn-north-4, cn-south-1 and cn-southwest-2 are known: for another region, set the endpoint option.

String

secretKey (producer)

Required The secret access key (SK) of the Huawei Cloud credentials. It is not used when the serviceKeys option is set.

String

securityGroupId (producer)

The ID of the security group of the new instance, required for createInstance from the options. The CamelHwCloudDmsSecurityGroupId exchange property replaces this option.

String

serviceKeys (producer)

The AK/SK pair as an org.apache.camel.component.huaweicloud.common.models.ServiceKeys. When set, its accessKey and its secretKey are used, and the accessKey and secretKey options are not.

ServiceKeys

specification (producer)

The baseline bandwidth of a new Kafka instance, for example 100MB. It is required for createInstance of a Kafka instance from the options. The CamelHwCloudDmsSpecification exchange property replaces this option.

String

storageSpace (producer)

The message storage space of the new instance in GB. It must be greater than 0 for createInstance from the options. The CamelHwCloudDmsStorageSpace exchange property replaces this option.

int

storageSpecCode (producer)

The storage I/O specification of the new instance, for example dms.physical.storage.high. It is required for createInstance from the options. The CamelHwCloudDmsStorageSpecCode exchange property replaces this option.

String

subnetId (producer)

The ID of the subnet of the new instance, required for createInstance from the options. The CamelHwCloudDmsSubnetId exchange property replaces this option.

String

vpcId (producer)

The ID of the VPC of the new instance, required for createInstance from the options. The CamelHwCloudDmsVpcId exchange property replaces this option.

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

ignoreSslVerification (security)

Whether to skip the verification of the TLS certificate of the server. This makes the connection insecure: use it only for testing.

false

boolean

Message Body

The message body at each side of the Huawei Distributed Message Service (DMS) component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

any

Not used by deleteInstance, listInstances and queryInstance, which take the instance id and the engine from the options or exchange properties such as CamelHwCloudDmsInstanceId. createInstance takes a CreateInstanceRequestBody or its JSON as text, bytes, a stream, a file or a Map (such as JSON unmarshalled by an earlier step), and with no body (or an empty one) creates the instance from the options: another body fails. updateInstance needs an UpdateInstanceRequestBody or its JSON as text, bytes, a stream, a file or a Map: another body fails.

  • With operation=createInstance: text, bytes, stream, file, map, pojo or null

  • With operation=updateInstance: text, bytes, stream, file, map or pojo

Producer output

unchanged

The JSON of the response as text: the id of the new instance for createInstance, the array of the instances for listInstances and the instance for queryInstance. Unchanged after deleteInstance and updateInstance, which set the CamelHwCloudDmsInstanceDeleted or CamelHwCloudDmsInstanceUpdated exchange property to true. The CamelHwCloudDmsOperation exchange property overrides the operation.

  • With operation=createInstance: text (java.lang.String)

  • With operation=listInstances: text (java.lang.String)

  • With operation=queryInstance: text (java.lang.String)

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Message properties evaluated by the DMS producer

Header Type Description

CamelHwCloudDmsOperation

String

Name of operation to invoke

CamelHwCloudDmsEngine

String

The message engine. Either kafka or rabbitmq

CamelHwCloudDmsInstanceId

String

Instance ID to invoke operation on

CamelHwCloudDmsName

String

The name of the instance for creating and updating an instance

CamelHwCloudDmsEngineVersion

String

The version of the message engine

CamelHwCloudDmsSpecification

String

The baseline bandwidth of a Kafka instance

CamelHwCloudDmsStorageSpace

int

The message storage space

CamelHwCloudDmsPartitionNum

int

The maximum number of partitions in a Kafka instance

CamelHwCloudDmsAccessUser

String

The username of a RabbitMQ instance

CamelHwCloudDmsPassword

String

The password of a RabbitMQ instance

CamelHwCloudDmsVpcId

String

The VPC ID

CamelHwCloudDmsSecurityGroupId

String

The security group which the instance belongs to

CamelHwCloudDmsSubnetId

String

The subnet ID

CamelHwCloudDmsAvailableZones

List<String>

The ID of an available zone

CamelHwCloudDmsProductId

String

The product ID

CamelHwCloudDmsKafkaManagerUser

String

The username for logging in to the Kafka Manager

CamelHwCloudDmsKafkaManagerPassword

String

The password for logging in to the Kafka Manager

CamelHwCloudDmsStorageSpecCode

String

The storage I/O specification

If any of the above properties are set, they will override their corresponding query parameter.

Message properties set by the DMS producer

Header Type Description

CamelHwCloudDmsInstanceDeleted

boolean

Set as true when the deleteInstance operation is successful

CamelHwCloudDmsInstanceUpdated

boolean

Set as true when the updateInstance operation is successful

List of Supported DMS Operations

  • createInstance

  • deleteInstance

  • listInstances

  • queryInstance

  • updateInstance

Create Instance

To create an instance, you can pass the parameters through the endpoint, the exchange properties, and the exchange body as a CreateInstanceRequestBody object or a valid JSON representation of it. Refer to this for the Kafka parameters and the RabbitMQ parameters. If you choose to pass these parameters through the endpoint or through exchange properties, you can only input the mandatory parameters shown in those links. If you would like to have access to all the parameters, you must pass a CreateInstanceRequestBody object or a valid JSON representation of it through the exchange body, as shown below:

Java-only: requires SDK CreateInstanceRequestBody builder
from("direct:triggerRoute")
 .setBody(constant(new CreateInstanceRequestBody().withName("new-instance").withDescription("description").with*)) // add remaining options
 .to("hwcloud-dms:createInstance?region=cn-north-4&accessKey=********&secretKey=********&projectId=*******")
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .setBody(constant("{\"name\":\"new-instance\",\"description\":\"description\"}")) // add remaining options
 .to("hwcloud-dms:createInstance?region=cn-north-4&accessKey=********&secretKey=********&projectId=*******")
<route>
  <from uri="direct:triggerRoute"/>
  <setBody>
    <constant>{"name":"new-instance","description":"description"}</constant>
  </setBody>
  <to uri="hwcloud-dms:createInstance?region=cn-north-4&amp;accessKey=********&amp;secretKey=********&amp;projectId=*******"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setBody:
            constant: '{"name":"new-instance","description":"description"}'
        - to:
            uri: hwcloud-dms:createInstance
            parameters:
              region: cn-north-4
              accessKey: "********"
              secretKey: "********"
              projectId: "*******"

The JSON can be text, bytes, a stream or a file, such as the body of an HTTP request or the file of a file consumer, or a Map with the same field names, such as the JSON unmarshalled by an earlier step. The instance is created from the endpoint parameters and the exchange properties only when the exchange has no body, or an empty one. Any other body is the request: a body that is not a CreateInstanceRequestBody or a valid JSON representation of it fails the exchange with an IllegalArgumentException.

Update Instance

To update an instance, you must pass the parameters through the exchange body as an UpdateInstanceRequestBody or a valid JSON representation of it, as text, bytes, a stream, a file or a Map. Another body fails the exchange with an IllegalArgumentException. Refer to this for the Kafka parameters and the RabbitMQ parameters. An example of how to do this is shown below:

Java-only: requires SDK UpdateInstanceRequestBody builder
from("direct:triggerRoute")
 .setBody(constant(new UpdateInstanceRequestBody().withName("new-instance").withDescription("description").with*)) // add remaining options
 .to("hwcloud-dms:updateInstance?instanceId=******&region=cn-north-4&accessKey=********&secretKey=********&projectId=*******")
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .setBody(constant("{\"name\":\"new-instance\",\"description\":\"description\"}")) // add remaining options
 .to("hwcloud-dms:updateInstance?instanceId=******&region=cn-north-4&accessKey=********&secretKey=********&projectId=*******")
<route>
  <from uri="direct:triggerRoute"/>
  <setBody>
    <constant>{"name":"new-instance","description":"description"}</constant>
  </setBody>
  <to uri="hwcloud-dms:updateInstance?instanceId=******&amp;region=cn-north-4&amp;accessKey=********&amp;secretKey=********&amp;projectId=*******"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - setBody:
            constant: '{"name":"new-instance","description":"description"}'
        - to:
            uri: hwcloud-dms:updateInstance
            parameters:
              instanceId: "******"
              region: cn-north-4
              accessKey: "********"
              secretKey: "********"
              projectId: "*******"

Using ServiceKey Configuration Bean

Access key and secret keys are required to authenticate against cloud DMS service. You can avoid having them being exposed and scattered over in your endpoint uri by wrapping them inside a bean of class org.apache.camel.component.huaweicloud.common.models.ServiceKeys. Add it to the registry and let Camel look it up by referring the object via endpoint query parameter serviceKeys.

Check the following code snippets:

<bean id="myServiceKeyConfig" class="org.apache.camel.component.huaweicloud.common.models.ServiceKeys">
   <property name="accessKey" value="your_access_key" />
   <property name="secretKey" value="your_secret_key" />
</bean>
  • Java

  • XML

  • YAML

from("direct:triggerRoute")
 .to("hwcloud-dms:listInstances?region=cn-north-4&serviceKeys=#myServiceKeyConfig")
<route>
  <from uri="direct:triggerRoute"/>
  <to uri="hwcloud-dms:listInstances?region=cn-north-4&amp;serviceKeys=#myServiceKeyConfig"/>
</route>
- route:
    from:
      uri: direct:triggerRoute
      steps:
        - to:
            uri: hwcloud-dms:listInstances
            parameters:
              region: cn-north-4
              serviceKeys: "#myServiceKeyConfig"