Get Countries and split
#
IntroductionAfter Logging the countries to the Execution Log you notice that the output is not so friendly to the eyes. That is where the Splitter comes into play. The Splitter component processes a message and breaks it apart into pieces to process the messages individually. We will also use an aggregation strategy to help display the returned output clearly in the Execution Logs. That way, when VisionsCorp looks at the returned data, they can visually filter through to see what they need quickly.
#
Integration Ingredients:- GET method (created in a previous lesson)
- SQL (created in the last lesson)
- Splitter
- Process
- Marshal
- Log
#
Goals:- Learn how to use a Splitter
- Learn how to use an Aggregation Strategy
- Marshal into JSON
- Combine the knowledge from the previous lessons to create a larger integration
#
Step 1: Update the previous integration- Continuing from the previous lesson, stop running the integration
- Remove the Log from the route
- Add a Splitter component
- For the LANGUAGE choose Simple
- USE AGGREGATION STRATEGY → Checked ☑️
- AGGREGATION STRATEGY → CountriesAggregationStrategy
- Now let us create that resource
#
Step 2: Creating an Aggregation Strategy- In the Explorer, scroll down until you see Source Definitions
- Clicking Source Definitions will be presented with a modal asking for a name, add CountriesAggregationStrategy
- Description → *anything
- Filename→ CountriesAggregationStrategy.java
- You are prompted to add code, place this code inside
- Save the Aggregation Strategy
#
Step 3: Add the Processes- Add 2 Process components under the Splitter. This will case the route to branch
- In the Process under the Route branch add this code to the top section:
- And this code in the bottom section:
- In the Process under the Split branch add this code to the top section:
- And this code in the bottom section:
- Under the route’s Process, add a To JSON COMPONENT
- Under the Split’s Process, add a Log component
- For the MESSAGE put ${body}
- Run the integration
- Open the Execution Logs
- After the integration says
INFO [io.quarkus] (main) Installed features: [
use Postman to shoot the GET request used in the first lesson - View the logs and see the output
🎉 Congratulations you have successfully used your first Aggregation Strategy in Jetic! Notice how much cleaner the output of the logs look🎉