Skip to content

Latest commit

 

History

History
484 lines (342 loc) · 14.7 KB

File metadata and controls

484 lines (342 loc) · 14.7 KB

Camel JBang - Tennis Rally

Serve winners by familiarising yourself with the prototyping tool that helps you run, iterate and test your Camel applications.

tennis illustration

This chapter is an introductory taste of Camel JBang showing you a basic group of commands. Hopefully you’ll get to see how much you can sharpen your axe when making a good use of Camel JBang.

Note

Familiarity with Apache Camel is helpful but not required to complete this lab. If you have little or no prior experience, consider reviewing an introduction to Enterprise Integration Patterns and Apache Camel first:

This chapter is recommended to understand how Camel JBang helps you work fast with Apache Camel


Camel JBang at play

Camel JBang is a command-line interface (CLI) that accelerates prototyping by letting developers quickly create, validate, and tweak flows without complex setups, making it perfect for rapid experimentation.

camel jbang


Open a terminal

Whether you’re working in your local machine or from Dev Spaces, you’ll need to open a terminal. If you’re working locally we recommend using VS Code as the examples below are based on this editor, but you can use any other terminal you prefer.

Open a terminal following the steps illustrated below (Dev Spaces example):

terminal open

The picture below shows the terminal in VS Code.

terminal

Copy and paste the following into your terminal:

mkdir lab
cd lab
terminal copypaste


When created the first time, your lab directory is empty:

Example
📁 workshop
   📁 lab    (empty)


Playing a game with Camel JBang

They say playing is a great way to learn, so let’s play for a bit. While you’re at it you’ll discover a few tricks Camel JBang has in the bag.

Pretend we’re about to organise a tennis tournament. Let us introduce to you player1:

Copy and paste the following into your terminal to create the player1.yaml file.

Note
You’ll be asked to confirm the paste action, tick "✓ Do not ask me again" and click Paste.
paste multiline
cat <<EOF > player1.yaml
- route:
    id: player1
    from:
      uri: file:court/side1
      parameters:
        delete: true
      steps:
        - log:
            message: (ping)⋅⋅⋅━━━► 🥎
        - delay:
            constant: "{{pace:3000}}"
        - to:
            uri: file:court/side2
EOF
Note
player1 one plays on one side of the court and hits every ball that comes his way. When hitting the ball, it crosses the court (at a given pace) to the other side.

Run this command to get player1 on the court, ready to play:

camel run player1.yaml
Note
Observe the simplicity of it all, no more than one player in the game, no dependency descriptors, no additional files needed to run the show. Camel JBang figures all out, it reads player1 and provides all that is needed to the run the game.

In your terminal you’ll see player1 ready:

Example output
2025-10-26 12:40:32.210 INFO 2243 --- [           main] e.camel.impl.engine.AbstractCamelContext : Apache Camel 4.15.0 (player1) started in 242ms ...

Also, watching closely your folder structure, you’ll see on which side player1 stands waiting for balls:

❯ lab ❯ court/side1


Throw a ball

player1 is ready. Give him a 🥎.

From the terminal’s top right corner, click + to open a second terminal, as shown below:

terminal plus

From the new terminal, use Camel JBang to hand a ball to player1:

Tip
The send command is very helpful to test the game, you can throw balls to players and see what happens.
camel cmd send player1 --header CamelFileName=🥎

Get back to the first terminal where player1 is running:

terminal one

Inspect the terminal’s output, you should see player1 hitting the ball to the other side of the court:

Example output
2025-10-26 12:50:12.951 INFO 2243 --- [e://court/side1] player1.yaml:8 : (ping)⋅⋅⋅━━━► 🥎

Have a look to the court. You should see the ball resting on the other side:

court side2 ball
Note
The downside of playing tennis with a single player is that balls end up motionless on the other side of the court.

Before we continue, give player1 some rest. Stop the action with Ctrl+C.


The ball boy

We introduce to you the ball boy, he will ensure the court is always tidy.

Copy and paste the following into your terminal to create the the-ballboy.yaml file:

cat <<EOF > the-ballboy.yaml
- route:
    id: ballboy
    from:
      uri: timer:check-court
      steps:
        - filter:
            groovy:
              expression: >-
                def court = ['court/side1/🥎', 'court/side2/🥎'];
                def file = court.find { new File(it).exists() }?.with { new File(it) };

                if (file?.exists() && (System.currentTimeMillis() - file.lastModified()) > {{wait:6000}} )
                  return file.delete();
                else
                  return false;
            steps:
              - log:
                  message: "🥎 cleared, court ready."
EOF
Note
In Camel, certain tasks require agility. Notice the ballboy making use of Groovy to look at both sides of the court, and retrieve any ball sitting on the court for too long (6 seconds).

When you see everyone ready, use the command below to restart:

camel run *
Note

Camel JBang makes things easy:

  • Use the * wildcard when you have multiple individuals on court.

  • The wildcard also picks up property files where you can configure a different game behaviour.
    Here’s a file (optional example) game.properties you could use:

    # Ball pace (millis) when players hit. Lower value is faster.
    pace=3000
    
    # Ballboy waits (millis) before picking up the ball.
    wait=6000

Inspect the terminal logs, you should see the ball boy already at work:

Example output
2025-10-26 18:23:53.558 INFO 20299 --- [r://check-court] the-ballboy.yaml:17 : 🥎 cleared, court ready.

Look also at the court. You’ll notice the ball has been cleared:

court clear

Let player1 practice a bit more. When done, press Ctrl+C to give him some rest.


Set up the tournament

Ok, practice is over, let’s organise a real game.

For a proper game to take place, you need more than just one player. We introduce to you player2:

Copy and paste the following into your terminal to create the player2.yaml file:

cat <<EOF > player2.yaml
- route:
    id: player2
    from:
      uri: file:court/side2
      parameters:
        delete: true
      steps:
        - log:
            message: "      🥎 ◄━━━⋅⋅⋅(pong)"
        - delay:
            constant: "{{pace:3000}}"
        - to:
            uri: file:court/side1
EOF
Note
These players really train for doing just one thing.

Because this is a prestigious tournament, there’s a protocol to follow:

  1. Let spectators sit comfortably while players and staff wait in the locker rooms. Press Ctrl+C (if you didn’t already) to follow on with preparations.

  2. Let the ball boy go on court first to get ready:

    camel run the-ballboy.yaml --background
    Note
    The flag --background indicates Camel JBang to run the process detached.
  3. Present the players to the public and let them jump on court:

    camel run player1.yaml --background --dev
    camel run player2.yaml --background --dev
    Note
    The flag --dev indicates Camel JBang to do live code reloads (new racket for example).
  4. Before the game starts, check everyone is ready:

    camel ps
    Note
    The ps command is handy to check who’s playing and who’s not, who’s ready and who’s not, and who’s busy and who’s not.
  5. Join the crowd and enjoy watching the game:

    camel log
    Note
    The log command aggregates all the action on court so that you’re aware of all that’s happening. You can also focus on one single player, or even the ball boy if curious of what the job entails. For example to focus on player 1, you would run camel log player1.

Ok, the ball boy is ready, the players are ready, and the public is anxious waiting to see the game start.


Let the game begin

player1 starts serving, hand him a 🥎

camel cmd send player1 --header CamelFileName=🥎

Inspect your terminal output, you should see both players hitting the ball hard:

Example output
player1    | 2025-10-26 19:01:36.006 INFO 22363 --- [e://court/side1] player1.yaml:8 : (ping)⋅⋅⋅━━━► 🥎
player2    | 2025-10-26 19:01:39.106 INFO 22578 --- [e://court/side2] player2.yaml:8 :       🥎 ◄━━━⋅⋅⋅(pong)
player1    | 2025-10-26 19:01:42.509 INFO 22363 --- [e://court/side1] player1.yaml:8 : (ping)⋅⋅⋅━━━► 🥎
player2    | 2025-10-26 19:01:45.610 INFO 22578 --- [e://court/side2] player2.yaml:8 :       🥎 ◄━━━⋅⋅⋅(pong)
...

It’s a long rally !

Also, see the ball on the court going back and forth:

court rally

But player1 feels the laces of his shoe are loose and has to stop to tie them up. Run the command:

camel cmd stop-route --id player1

Because player1 stopped hitting the ball, spectators will see player2 hitting one last time, player1 tying up his shoe laces, and the ball boy retrieving the ball:

Example output
player2    | ... :       🥎 ◄━━━⋅⋅⋅(pong)
player1    | ... : Stopped player1 (file://court/side1)
the-ballboy| ... : 🥎 cleared, court ready.


Game statistics

It’s a good moment to look at the game statistics. Get the stats with:

camel get route

Stats will reveal who’s hitting faster (and other measurements as well):

Note
Observe player1 has stopped playing for a moment, but is still very much part of the game.
Example output
  PID   NAME         ID       FROM                            REMOTE  STATUS    AGE   COVER  MSG/S  TOTAL  FAIL  INFLIGHT  MEAN  MIN   MAX   LAST  DELTA  SINCE-LAST
 22140  the-ballboy  ballboy  timer://check-court                     Started   6m3s    2/2   1.00    363     0         0     2     0   841     0      0            0s/0s/-
 22363  player1      player1  file://court/side1?delete=true    x     Stopped           3/3   0.00     25     2         0  2001  2001  2007  2001      0  1m31s/1m29s/1m41s
 22578  player2      player2  file://court/side2?delete=true    x     Started  5m21s    3/3   0.00     23     0         0  2001  2001  2012  2001      0      1m29s/1m27s/-


The game resumes

It seems player1 sorted out the shoe laces problem and is ready to play again. Get the player in position again with:

camel cmd start-route --id player1

It’s player2 's turn to serve, hand him a 🥎

camel cmd send player2 --header CamelFileName=🥎

Here they go again, another insane rally.


Game conditions

It seems the wind is peaking up, some clouds have covered the sky and some spots of rain are dotting the court. Weather conditions can really change the game in tennis.

The rain drops make the ball wetter and heavier, the hitting starts to sound funny and the exchanges feel slower. While the intense rally keeps going (ping/pong), make these changes on the players:

  • In player1.yaml, change the log message to p1ng, and the pace of the ball to {{pace:4000}} (slower)

  • In player2.yaml, change the log message to p0ng, and the pace of the ball to {{pace:4000}} (slower)

Note
Camel JBang reacts to live code changes and ensures the new game behaviour takes immediate effect.

You should see in the terminal Camel reacting with reloads:

Example output
player1    | ... RouteWatcherReloadStrategy : Routes reloaded summary (total:1 started:1)
player1    | ... RouteWatcherReloadStrategy : Started player1 (file://court/side1) (source: player1.yaml:4)

Now you’ll notice more clearly, the funny sound from the rackets, and the game slowing down:

Example output
player2    | ... :       🥎 ◄━━━⋅⋅⋅(p0ng)
player1    | ... : (p1ng)⋅⋅⋅━━━► 🥎
...


Abrupt end

That’s unfortunate…​ player1 slips on the wet court. Were his shoe laces tied well? We hope he is not hurt. After a close look, it is clear: he is injured and must leave the game.

camel stop player1
Tip
Run camel ps and you’ll notice player1 no longer takes part in the game.

At this point, it makes no sense to continue the event, the announcement is made, and the game is halted:

camel stop
Note
When no name is specified, Camel JBang stops all.

We’re sorry it ended this way, but don’t let it spoil your day, there are many other matches to watch!

🥎🥎🥎 Keep exploring tutorials to see more. 🥎🥎🥎

Clean up your lab folder

Make sure your lab folder stays clean in preparation for your next lab exercises.

Run the command below:

rm -r *

Your lab folder should contain no files or directories.

Is your lab folder empty? Get ready to start working!

Closing words

This was only a brief introduction on how to work fast with a few Camel files. Camel JBang has many more commands to assist you in your development.

It’s worth to quickly recap the collection of commands you just used:

  • For running Camel, how to:

    • Run single file

    • Run all

    • Run in the background

    • Run in dev mode (hot reload)

  • For troubleshooting/monitoring, how to:

    • List running instances

    • Follow logs

    • Start/Stop routes in process

    • Get route details

    • Send message to endpoint

  • For stopping Camel, how to:

    • Stop single instance

    • Stop all

Continue exploring other examples to discover, not only what Camel JBang can do for you beyond what you’ve just seen, but also other companion tools empowering the developer to work fast with Apache Camel.