Iapetus - Implement ETL for Sales Orders
Iapetus, powered by Apache Camel, simplifies the implementation of various ETL (Extract, Transform, Load) scenarios.
In this tutorial, I'm going to show you how you can implement orders ETL from an instance of the free open source e-commerce OpenCart to your database.
Orders ETL scenario
Let's have the following use cases:
- we have an online store (instance of OpenCart) which sells goods
- we want to regularly replicate all orders from the store to our database for analytic purposes
- OpenCart order amounts are stored in USD
- we want to convert the total amounts from USD to EUR
- only order details like total amount and date added are needed
Implementation steps
Follow the steps below or watch the recorded video.
Start an OpenCart instance using Docker
- create
docker-compose.ymlfile with MariaDB and OpenCart images in a directory with this content. - start images
shell# adjust the path to the docker-compose.yml file path export DOCKER_COMPOSE_PATH='./docker-compose.yml' export OPENCART_USERNAME='myuser' export OPENCART_PASSWORD='myuser' export OPENCART_DATABASE_PORT_NUMBER='3306' export OPENCART_DATABASE_USER='bn_opencart' export OPENCART_DATABASE_PASSWORD='bitnami' export OPENCART_DATABASE_NAME='bitnami_opencart' docker-compose -f "$DOCKER_COMPOSE_PATH" up -d- open created OpenCart instance at http://localhost:80

register a new store user from http://localhost:80/index.php?route=account/register
create a few orders with different products and amounts
you can check all store orders in the OpenCart admin UI.
Use usermyuserand passwordmyuserto login.
- create
Start an Iapetus instance and connect it to the OpenCart's network
shellWORKSPACE_DIR='/tmp/iapetus' IMAGE_VERSION='1.0.1' # use version 1.0.1 or later docker run --name codbex-iapetus --rm -p 8080:80 \ --network opencart_network \ -v "$WORKSPACE_DIR:/target/dirigible" \ ghcr.io/codbex/codbex-iapetus:$IMAGE_VERSIONOpen Iapetus and create a project named
orders-etl
open Iapetus at http://localhost:8080
login using the default user - username:
admin, password:adminright-click on workbench and click on
New Project
type
orders-etlfor project name
click on
Createbuttona blank project will be created

- Create datasource to the OpenCart database which will be used to extract data
- create folder
datasources - create file
OpenCartDB.datasourcein the created folder - and add this content
- Verify that the created data source works
navigate to the
Databaseperspective by clicking on theDatabasebutton
select
OpenCartDBdata source
expand schema
bitnami_opencartexpand
Tablesyou should be able to see all OpenCart tables
here you can find the table
oc_orderwhich contains all ordersverify that you are able to query its content
sqlselect order_id, total, date_added from oc_order;
- Define a table in our application which will hold the replicated orders
create file
orders.tablein folderdbright-click on the file and select
Open With->Code Editorpaste this content
save the file
publish the project by clicking on
Publish Allbutton
after a few seconds, open the
Databaseperspective and check whether the table is created in theDefaultDBdata source
You may need to click on theRefreshbutton to see the newly created table.
- Implement ETL using JDBC
- create folder named
sync - create file named
sync-orders-jdbc.camelin the created folder - open the file
- add cron to trigger the execution regularly
click on
Create routebutton
search for
cronin theComponentstab and select it
set
Trigger Orders Replicationfor descriptionunder component properties set
TriggerOrdersReplicationfor name and add schedule0 * * ? * *(every minute at 0 seconds)
save the file with (cmd + s)
select the route and update the description to
Sync orders from OpenCart
add step which logs that the synchronization has started
add
Logstep after the cron using the arrow button

set
Log startingfor descriptionset
Replicating orders from OpenCart using JDBC...for messagelog level to
INFOset
OpenCartOrdersReplicationforLog Name
save the file
set property for the USD to EUR exchange rate
add
Set Propertystep after the log step
set expression
0.92set
Set USD to EUR exchange rate propertyfor descriptionset
currencyExchangeRatefor name
save the file
next, we have to select all orders from the OpenCart data source
- build the select query
add step
Set Body
set expression
SELECT * FROM oc_orderset description
Create orders SELECT statement
save the file
- execute the select query
add
Spring JDBCstep
set description
Get all ordersset
OpenCartDBfor data source name
save the file
- build the select query
now, the camel body will contain all orders
split the body into single orders
add
Splitstep
set expression to
${body}set
Split to single orderfor description
build merge statement for each order
We are using the extracted data from the OpenCart database to create the statement. Total is converted from USD to EUR using the defined exchange rate property.add
Set Bodystepset the following value for expression
sqlMERGE INTO ORDERS (ID, TOTAL, DATEADDED) KEY(ID) VALUES ( ${body['order_id']}, ${body['total']} * ${exchangeProperty.currencyExchangeRate}, '${body['date_added']}' );set
Create MERGE statementfor description
execute the merge statement
add
Spring JDBCstepset description
Merge orderset
DefaultDBfor data source name
add log step for completed
add log step after the split

set
Log completedfor descriptionset
Successfully replicated orders from OpenCart using JDBCfor messageset logging level to
INFOset
OpenCartOrdersReplicationfor log name
save the file
now the JDBC implementation is done
publish the project from the
Publish Allbuttonverify that the synchronization works
check the console for output from the log steps which we added

go to
Databaseperspective and check the content of tableORDERSinDefaultDBdata source - it should contain the replicated orders with converted total in EUR
Note: if you had problems to model the
sync-orders-jdbc.camel, you can get a working content of the file from here
- create folder named
- Implement ETL using TypeScript
create file
sync-orders-typescript.camelin directorysyncopen the created file
add cron to trigger the execution regularly
click on
Create routebuttonsearch for
Croncomponent and select itset
Trigger Orders Replicationfor descriptionunder component properties set
TriggerOrdersReplicationfor name and add schedule30 * * ? * *(every minute at 30 seconds)
save the file
select the route and update the description to
Sync orders from OpenCart
add step which logs that the synchronization has started
add
Logstep after the cronset
Log startingfor descriptionset
Replicating orders from OpenCart using TypeScript...for messagelog level to
INFOset
OpenCartOrdersReplicationfor log name<img src="/images/2024-08-19-orders-etl/ts-log-starting-config.png" alt="ts-log-starting-config.png">save the file
get all orders from OpenCart and current exchange rate from the frankfurter API using TypeScript
create a folder named
daocreate file
oc_orderRepository.tsin the created folderopen the file
set this content
Note: the code of this dao is automatically generated using another awesome codbex functionality, but I will give you more details about this in another blog post.
create file
get-all-orders.tsinsyncfolder using this contentin
sync-orders-typescript.cameladdSet Propertystepset expression
orders-etl/sync/get-all-orders.tsset description
Set get-all-orders.ts fileset name
resource
add step
Class
set description
Get all OpenCart ordersset bean name
org.eclipse.dirigible.components.engine.camel.invoke.Invoker
now, the camel body will contain all orders
split the body into single orders
add
Splitstepset expression to
${body}set
Split to single orderfor description
merge order using TypeScript
create file
merger-order.tsin foldersyncset this file content
in
sync-orders-typescript.cameladdSet Propertystepset expression
orders-etl/sync/merger-order.tsset description
Set merger-order.ts fileset name
resource
add step
Classset description
Merge orderset bean name
org.eclipse.dirigible.components.engine.camel.invoke.Invoker
add log step for completed
add
Logstep after the splitset
Log completedfor descriptionset
Successfully replicated orders from OpenCart using TypeScriptfor messageset logging level to
INFOset
OpenCartOrdersReplicationfor log name
now the TypeScript implementation is done
publish the project from the
Publish Allbuttonverify that the synchronization works
check the console for output from the log steps which we added

go to
Databaseperspective and check the content of tableORDERSinDefaultDBdata source - it should contain the replicated orders with converted total in EUR
Note: if you had problems to model the
sync-orders-typescript.camel, you can get a working content of the file from here
Congratulations, you have implemented the ETL scenario in two different ways!
Summary
Using Iapetus you can
- easily implement ETL scenarios
- use all available Apache Camel functionalities
- benefit from the codbex platform, tooling and modules
- use the comprehensive codbex SDK which uses different modern open source projects for messaging, jobs scheduling, REST, OData, mails etc.
The project we implemented can be found in this GitHub repository.
I hope you enjoyed this blog. Stay tuned for more great functionality by codbex!
If you have any questions, ideas or want to contribute, feel free to contact us.