Camel Components

Stitch

Since Camel 3.8

Only producer is supported

Stitch is a cloud ETL service, a developer-focused platform for rapidly moving and replicates data from more than 90 applications and databases. It integrates various data sources into a central data warehouse. Stitch has integrations for many enterprise software data sources, and can receive data via WebHooks and an API (Stitch Import API) which Camel Stitch Component uses to produce the data to Stitch ETL.

For more info, feel free to visit their website

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

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

URI format

stitch:[tableName]//[?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 Stitch component supports the following options which are listed below.

Name Description Default Type

configuration (producer)

The shared configuration of the endpoints. Each endpoint gets a copy, and the options and the table name of the endpoint URI override its values.

StitchConfiguration

keyNames (producer)

The Primary Key fields of the source table, as a comma separated list without spaces. Stitch uses them to de-duplicate the records when it loads them, and loads the table append-only when there are none. The CamelStitchKeyNames header overrides it, and the names are added to the key_names of a StitchRequestBody or Map body.

String

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

region (producer)

The region of the Stitch account, which selects the host of the Import API: EUROPE (api.eu-central-1.stitchdata.com) or NORTH_AMERICA (api.stitchdata.com). Not used when stitchClient is set.

Enum values:

  • NORTH_AMERICA

  • EUROPE

EUROPE

StitchRegion

stitchSchema (producer)

Autowired The JSON schema that describes the records of the batch; Stitch rejects records that do not conform to it. The CamelStitchSchema header overrides it, and it overrides the schema of a StitchRequestBody or Map body.

StitchSchema

connectionProvider (producer (advanced))

Autowired A Reactor Netty ConnectionProvider, for example a pool with a maximum number of connections, that the endpoint creates its HttpClient with. Not used when httpClient or stitchClient is set.

ConnectionProvider

httpClient (producer (advanced))

Autowired A custom Reactor Netty HttpClient that sends the requests. The endpoint still sets the host of the region and the Authorization and Content-Type headers on it, and does not use connectionProvider. Not used when stitchClient is set.

HttpClient

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

stitchClient (advanced)

Autowired A custom implementation of the org.apache.camel.component.stitch.client.StitchClient interface that sends the batches. When set, the region, httpClient and connectionProvider options are not used, and the endpoint does not close the client when it stops.

StitchClient

token (security)

Required The access token of the Stitch Import API, sent as a Bearer token. It is required, also when stitchClient is set.

String

Endpoint Options

The Stitch endpoint is configured using URI syntax:

stitch:tableName

With the following path and query parameters:

Path Parameters

Name Description Default Type

tableName (producer)

The name of the destination table that the records are loaded into. The CamelStitchTableName header overrides it, and it overrides the table_name of a StitchRequestBody or Map body. Table names must be unique in each destination schema, and Stitch rejects the data when the name is longer than the destination allows.

String

Query Parameters

Name Description Default Type

keyNames (producer)

The Primary Key fields of the source table, as a comma separated list without spaces. Stitch uses them to de-duplicate the records when it loads them, and loads the table append-only when there are none. The CamelStitchKeyNames header overrides it, and the names are added to the key_names of a StitchRequestBody or Map body.

String

region (producer)

The region of the Stitch account, which selects the host of the Import API: EUROPE (api.eu-central-1.stitchdata.com) or NORTH_AMERICA (api.stitchdata.com). Not used when stitchClient is set.

Enum values:

  • NORTH_AMERICA

  • EUROPE

EUROPE

StitchRegion

stitchSchema (producer)

Autowired The JSON schema that describes the records of the batch; Stitch rejects records that do not conform to it. The CamelStitchSchema header overrides it, and it overrides the schema of a StitchRequestBody or Map body.

StitchSchema

connectionProvider (producer (advanced))

Autowired A Reactor Netty ConnectionProvider, for example a pool with a maximum number of connections, that the endpoint creates its HttpClient with. Not used when httpClient or stitchClient is set.

ConnectionProvider

httpClient (producer (advanced))

Autowired A custom Reactor Netty HttpClient that sends the requests. The endpoint still sets the host of the region and the Authorization and Content-Type headers on it, and does not use connectionProvider. Not used when stitchClient is set.

HttpClient

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

stitchClient (advanced)

Autowired A custom implementation of the org.apache.camel.component.stitch.client.StitchClient interface that sends the batches. When set, the region, httpClient and connectionProvider options are not used, and the endpoint does not close the client when it stops.

StitchClient

token (security)

Required The access token of the Stitch Import API, sent as a Bearer token. It is required, also when stitchClient is set.

String

Message Headers

The Stitch component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelStitchTableName (producer)

Constant: TABLE_NAME

The name of the destination table that the records are loaded into. It overrides the table name of the endpoint URI.

String

CamelStitchSchema (producer)

Constant: SCHEMA

The JSON schema that describes the records, as a StitchSchema or as a Map of JSON schema keywords. It overrides the stitchSchema option; a value of another type is ignored.

StitchSchema or Map

CamelStitchKeyNames (producer)

Constant: KEY_NAMES

The Primary Key fields of the source table, as a comma separated String without spaces. It overrides the keyNames option.

Collection

CamelStitchCode (producer)

Constant: CODE

The HTTP status code of the response of the Stitch Import API. Set only when the request succeeds: a status code of 300 or more fails the exchange with a StitchException.

Integer

CamelStitchHeaders (producer)

Constant: HEADERS

The HTTP headers of the response of the Stitch Import API, by header name. Set only when the request succeeds.

Map

CamelStitchStatus (producer)

Constant: STATUS

The status field of the JSON response of the Stitch Import API, empty when the response has none. Set only when the request succeeds.

String

Message Body

The message body at each side of the Stitch 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

pojo, map or list

A StitchRequestBody, a StitchMessage, a Map of the Stitch batch JSON (table_name, schema, messages, key_names as a list or a comma separated String), or a List of StitchMessage, Map of a message, StitchRequestBody, Message or Exchange. Text, bytes, a stream or no body fails. The tableName, keyNames and schema options or headers set the rest of the batch.

Producer output

text (java.lang.String)

The message of the response of Stitch, empty when it has none; the HTTP status code, the status and the response headers are in the CamelStitchCode, CamelStitchStatus and CamelStitchHeaders headers.

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

Prerequisites

You must have a valid Stitch account, you will need to enable Stitch Import API and generate a token for the integration, for more info, please find more info here.

Async Producer

This component implements the async Consumer and producer.

This allows camel route to consume and produce events asynchronously without blocking any threads.

Example showing how to produce data to Stitch from a custom processor:
from("direct:sendStitch")
     .process(exchange -> {
         final StitchMessage stitchMessage = StitchMessage.builder()
               .withData("field_1", "stitchMessage2-1")
               .build();

         final StitchRequestBody stitchRequestBody = StitchRequestBody.builder()
                .addMessage(stitchMessage)
                .withSchema(StitchSchema.builder().addKeyword("field_1", "string").build())
                .withTableName("table_1")
                .withKeyNames(Collections.singleton("field_1"))
                .build();

                exchange.getMessage().setBody(stitchRequestBody);
     })
.to("stitch:table_1?token=RAW({{token}})");

Message body type

Currently, the component supports the following types for the body message on the producer side when producing a message to Stitch component:

  • org.apache.camel.component.stitch.client.models.StitchRequestBody: This represents this Stitch JSON Message. However, StitchRequestBody includes a type safe builder that helps on building the request body. Please note that, tableName, keyNames and stitchSchema options are no longer required if you send the data with StitchRequestBody, if you still set these options, they override whatever being set in message body StitchRequestBody.

  • org.apache.camel.component.stitch.client.models.StitchMessage: This represents this Stitch message structure. If you choose to send your message as StitchMessage, you will need to add tableName, keyNames and stitchSchema options to either the Exchange headers or through the endpoint options.

  • Map: You can also send the data as Map, the data structure must follow this JSON Message structure which is similar to StitchRequestBody but with drawback losing on all the type safety builder that is included with StitchRequestBody.

  • Iterable: You can send multiple Stitch messages that are aggregated by Camel or aggregated through custom processor. These aggregated messages can be type of StitchMessage, StitchRequestBody or Map but this Map here is similar to StitchMessage.

Examples

Here is list of examples showing data that can be proceeded to Stitch:

Input body type org.apache.camel.component.stitch.client.models.StitchRequestBody:

Java-only: Java lambda Processor with Stitch SDK builders
from("direct:sendStitch")
     .process(exchange -> {
         final StitchMessage stitchMessage = StitchMessage.builder()
               .withData("field_1", "stitchMessage2-1")
               .build();

         final StitchRequestBody stitchRequestBody = StitchRequestBody.builder()
                .addMessage(stitchMessage)
                .withSchema(StitchSchema.builder().addKeyword("field_1", "string").build())
                .withTableName("table_1")
                .withKeyNames(Collections.singleton("field_1"))
                .build();

                exchange.getMessage().setBody(stitchRequestBody);
     })
.to("stitch:table_1?token=RAW({{token}})");

Input body type org.apache.camel.component.stitch.client.models.StitchMessage:

Java-only: Java lambda Processor with Stitch SDK API
from("direct:sendStitch")
     .process(exchange -> {
         exchange.getMessage().setHeader("CamelStitchSchema", StitchSchema.builder().addKeyword("field_1", "string").build());
         exchange.getMessage().setHeader("CamelStitchKeyNames", "field_1");
         exchange.getMessage().setHeader("CamelStitchTableName", "table_1");

         final StitchMessage stitchMessage = StitchMessage.builder()
               .withData("field_1", "stitchMessage2-1")
               .build();

                exchange.getMessage().setBody(stitchMessage);
     })
.to("stitch:table_1?token=RAW({{token}})");

Input body type Map:

Java-only: Java lambda Processor with Map construction
from("direct:sendStitch")
     .process(exchange -> {
        final Map<String, Object> properties = new LinkedHashMap<>();
        properties.put("id", Collections.singletonMap("type", "integer"));
        properties.put("name", Collections.singletonMap("type", "string"));
        properties.put("age", Collections.singletonMap("type", "integer"));
        properties.put("has_magic", Collections.singletonMap("type", "boolean"));

        final Map<String, Object> data = new LinkedHashMap<>();
        data.put(StitchRequestBody.TABLE_NAME, "my_table");
        data.put(StitchRequestBody.SCHEMA, Collections.singletonMap("properties", properties));
        data.put(StitchRequestBody.MESSAGES,
                Collections.singletonList(Collections.singletonMap("data", Collections.singletonMap("id", 2))));
        data.put(StitchRequestBody.KEY_NAMES, Collections.singletonList("test_key"));

        exchange.getMessage().setBody(data);
     })
.to("stitch:table_1?token=RAW({{token}})");

In YAML, a Groovy map has the same structure. The keys are those of the Stitch JSON message: table_name, schema, messages and key_names. The key_names can be a list, or a String with one key name or comma separated key names. The sequence of a message can be any number, and when it is not set, it is the time the message is built (in millis):

- route:
    from:
      uri: direct:sendStitch
      steps:
        - setBody:
            expression:
              groovy:
                expression: |
                  [table_name: 'my_table',
                   schema    : [properties: [id: [type: 'integer'], name: [type: 'string']]],
                   messages  : [[data: [id: 2, name: 'Camel']]],
                   key_names : ['id']]
        - to:
            uri: stitch:my_table
            parameters:
              token: "RAW({{stitch.token}})"

Input body type Iterable:

Java-only: Java lambda Processor with Iterable construction
from("direct:sendStitch")
     .process(exchange -> {
         exchange.getMessage().setHeader("CamelStitchSchema", StitchSchema.builder().addKeyword("field_1", "string").build());
         exchange.getMessage().setHeader("CamelStitchKeyNames", "field_1");
         exchange.getMessage().setHeader("CamelStitchTableName", "table_1");

        final StitchMessage stitchMessage1 = StitchMessage.builder()
                .withData("field_1", "stitchMessage1")
                .build();

        final StitchMessage stitchMessage2 = StitchMessage.builder()
                .withData("field_1", "stitchMessage2-1")
                .build();

        final StitchRequestBody stitchMessage2RequestBody = StitchRequestBody.builder()
                .addMessage(stitchMessage2)
                .withSchema(StitchSchema.builder().addKeyword("field_1", "integer").build())
                .withTableName("table_1")
                .withKeyNames(Collections.singleton("field_1"))
                .build();

        final Map<String, Object> stitchMessage3 = new LinkedHashMap<>();
        stitchMessage3.put(StitchMessage.DATA, Collections.singletonMap("field_1", "stitchMessage3"));

        final StitchMessage stitchMessage4 = StitchMessage.builder()
                .withData("field_1", "stitchMessage4")
                .build();

        final Exchange stitchMessage4Exchange = new DefaultExchange(context);
        stitchMessage4Exchange.getMessage().setBody(stitchMessage4);

        final StitchMessage stitchMessage5 = StitchMessage.builder()
                .withData("field_1", "stitchMessage5")
                .build();

        final Message stitchMessage5Message = new DefaultExchange(context).getMessage();
        stitchMessage5Message.setBody(stitchMessage5);

        final List<Object> inputMessages = new LinkedList<>();
        inputMessages.add(stitchMessage1);
        inputMessages.add(stitchMessage2RequestBody);
        inputMessages.add(stitchMessage3);
        inputMessages.add(stitchMessage4Exchange);
        inputMessages.add(stitchMessage5Message);

        exchange.getMessage().setBody(inputMessages);
     })
.to("stitch:table_1?token=RAW({{token}})");

Development Notes (Important)

When developing on this component, you will need to obtain a Stitch token to run the integration tests. In addition to the mocked unit tests, you will need to run the integration tests with every change you make To run the integration tests, in this component directory, run the following maven command:

mvn verify -Dtoken=stitchToken

Whereby token is your Stitch token generated for Stitch Import API integration.