4

Tooling guide for Getting Started with Apache Camel in 2021

 3 years ago
source link: http://wei-meilin.blogspot.com/2021/05/tooling-guide-for-getting-started-with.html?utm_campaign=Feed%3A+blogspot%2FhFXzh+%28Christina+%E7%9A%84+J%E8%80%81%E9%97%86%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Design & Implementation

There are several different IDEs out there that have language support for Camel. My current goto is the Visual Code Studio. VS Code itself has very primitive support for Java developers, but it comes with a large variety of extensions for you to customize it, and install all the tools you need. Speaking of extension, there is a must have… “Extension Pack for Apache Camel by Red Hat”. It contains the essentials for developing Camel. I recommend checking out the Aurélien Pupier youtube channel for updates! 

To begin a project, it’s always good to have some help to set the basic structure. You can either use the Project Initializer that comes with the Apache Camel by Red Hat Extension in VS Code that will generate the base project for you. Or you can always go to the Quarkus start coding page, adding the Camel dependencies to create the base project, but one downside of the Quarkus start coding page, it will not create the template extended RouteBuilder class for you. 

No matter what runtime you choose, you are still writing Camel DSL (Domain Specific Language), you have the latest and greatest support from the camel extension, where it will help you with autocomplete, validating your Camel code.  

Mapping data between formats can be tedious, especially with larger documents or more complex structure. But using the

tooling can help you map between two data sources with a drag and drop user interface, so you will be able to visualize the mappings. The tool will generate an “.adm” file, place the file into your Camel project. You can then use the camel-atlasmap components to run the mapping.  
from("servicenow:xxxxxx....")

  .split().body()

    .marshal().json()

    .to("atlasmap:servicenow.adm")

    .to("kafka:xxx?brokersxxx")

RESTful API is another popular implementation in Camel, I highly recommend you take advantage of the Apicurio project, where it provides a GUI interface for designing the API contract. Making contract first application development a lot easier. For more details, take a look at my previous blog

Another nice complements to the toolset is the Camel Designer, this is another extension in VS Code by Bruno, this can help you visualize the design of camel processing flow. So you will be able to see what your camel route does in a quick glance.

Testing 

Camel can easily wire up unit tests in your preferred testing framework. My past experience has been great with using JUnit for creating my test cases.  

What I normally would do is create a java Class for each test case (Extend “CamelTestSupport” class). Where it can kick off your camel route with mock endpoints, loading set of data or even stub out the actual endpoint

When testing integration, introducing Behavior-Driven Development(BDD) Testing is a development practice, as it’s black box testing nature allows it to better mimic user input and expectation, and can test more complex scenarios when compared to Test-Driven Development(TDD). Consider using the “Citrus Testing Framework” for building out BDD test cases. You can define the test scenario descriptions with a "Given-When-Then" structure in a feature file, as well as a simple setup for mimicking the common endpoints such as Kafka, AMQP, JMS, REST… etc.  

Feature: integration runs

  Background:

    Given load variables namespace.properties

    Given URL: http://camel-hello-quarkus.${namespace}.svc.cluster.local:8080

  Scenario: Checking GET Method

    When send GET /prescription?profileid=123456

    Then verify HTTP response body: {"profileid": 123456, "pharmancy": "CVS" }

    Then receive HTTP 200 OK

I have also been using a spinoff project from Citrus called YAKs to do my BDD testing on Kubernetes(OpenShift) platform. And I LOVED it. Simply because 1st, the lifecycle of the test was managed by the YAKs operator, meaning the test was run on a separate instance, that is where the client supposed the call, and also the YAKs operator takes in the feature, and does the test based on it. You can run it separately or plug it into your CI/CD pipeline.

Platform

I have been using OpenShift(Kunerenets) for managing all the running instances. It's just easier when there are hundreds of Camels running, it manages the scaling, resources, configuration and load-balancing for me. As well as a better deployment module (images). There are so many articles out there talking about the benefits of running a container & container management, so I won’t dive into it. 

CI/CD

Jenkin was on my list for a long time when it comes to building the pipeline for my Camel application. Basically using the maven jenkins plugin for compiling and deploying, and using the OpenShift plugin to do the canary releases. And recently, I have been using the Tekton pipeline, it’s built-in on OpenShift, so there is no need to install a separate instance and manage it. The Kubernetes platform itself will become the CI/CD platform itself. Here is an example of how it works with the Camel projects. I will write another deep dive into how it works.

Monitoring

With Camel 3, in order to collect and export the metrics, you will need to specifically add the microprofile-metrics dependency. And by using Prometheus to scrape metrics on the platform. It stores all scraped samples locally and aggregate the time series data. I then use Grafana to visualize the collected data, and create a dashboard to monitor all the camel routes.

Also checkout this video and see how things work:

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK