Categories: EAIJava / JEE

Apache Camel and Scala: A Powerful Combination

I really like the integration framework Apache Camel and I also like Scala a lot. This article shows the basics of this combination. It is NO introduction to Apache Camel or Scala. I created a Git project to use it as simple startup for Camel-Scala-Maven projects using just the basic Camel concepts and only a few complex Scala features (i.e. very „Java-friendly“).

Problems when Starting with this Combination

I had several problems finding good resources for starting when I first tried to combine them. I have a lot of Camel experience, but only basic Scala knowledge. I tried to start with some projects which where already available in the web (e.g. from the „Camel in Action“ book or other Git examples).

I could not get them ready to run in IntelliJ IDEA (and Eclipse Scala plugin is still not really stable, at least on my Mac). The examples either used way too many Scala features (and thus contained very complex source code for a Scala beginner), were too basic (here I mean the camel-scala archetype) or did not work because of problems with IDE support or version problems with Maven, Scala, and so on.

Nevertheless, it is also tough to create a Camel project (and even more a Camel Scala project) from scratch without Maven because of so many dependencies. Thus, I created my own „getting started“ project with current versions of Camel (2.7.1) and Scala (2.9). Of course, you can change the version in the maven configuration.

You can download the whole project from Github at https://github.com/megachucky/MavenCamelScala. If you wanna use my project you have to either use Intellij IDEA or uncomment some configuration stuff in the pom.xml file to use it within Eclipse.

Camel and Scala Concepts shown in this Example

This example just shows the most important Camel features for getting started (all in very simple forms) – this includes Routes, Processors, Beans, CamelContext, ErrorHandling and Testing. Besides, only some advanced Scala features are used. This project is easy to understand and extendable to play around with this combination. In the following, only some code snippets will be shown, please download the project at Git if you want to see everything.

CamelContext

You use the CamelContext as you do in Java.

Routes

Scala Routes extend the Java class „RouteBuilder“ as Java Routes do, but they also use several features of Scala. Shorter Scala syntax is implicitly used (no semicolons, dots and parantheses, no constructor). Implicit conversions are another advanced Scala feature. For example, you do not have to use a „from“-method as you have to in Java. Overwriting operators such as „+“ or creating new operators such as „–>“ is another Scala feature shown here.

Processors and Beans

Here you can reduce the lines of code a lot by just using Scala source code instead of Java source code. Nevertheless, you can still call other Java libraries as you did until now.

By the way: You could also use a closure to implement the „process“-method and then assign it to a variable.

Testing

You simply use the CamelTestSupport API from the Java DSL. Besides, you can mix in further traits. In this example, traits are used to include the testing framework ScalaTest. Traits are very powerful for adding more functionality!

In the Git source code, there is one more example, where traits are used to add default error handling to a route (therefore the route extends the „ErrorLog“ trait).

Advantages of using Camel combined with Scala

There are two main advantages. You can reduce the lines of code a lot. This reduces efforts in time to write code, but also in maintenance (code analysis and refactoring of code). You also have several powerful features which are offered by the Scala language, e.g. mixing in more than one trait.

Nevertheless, you can still use all of your Java libraries (as you have seen with the Camel classes which are used within the Scala code).

Conclusion

This article showed the basic Camel concepts realized with Scala. Be aware that not all Enterprise Integration Patterns (EIP) are implemented in Scala DSL yet, but this will happen soon, hopefully. The available documentation and code examples is also still not very comprehensive, maybe this article will help some people for getting started.  Despite of these concerns, you should really try out this combination, because both Apache Camel and Scala have a promising future in the JVM environment! My final conclusion: Apache Camel combined with Scala is a very powerful combination.

Best regards,

Kai Wähner (Twitter: @KaiWaehner)

Kai Waehner

bridging the gap between technical innovation and business value for real-time data streaming, processing and analytics

Recent Posts

Virta’s Electric Vehicle (EV) Charging Platform with Real-Time Data Streaming: Scalability for Large Charging Businesses

The rise of Electric Vehicles (EVs) demands a scalable, efficient charging network—but challenges like fluctuating…

2 days ago

Apache Kafka 4.0: The Business Case for Scaling Data Streaming Enterprise-Wide

Apache Kafka 4.0 represents a major milestone in the evolution of real-time data infrastructure. Used…

5 days ago

How Apache Kafka and Flink Power Event-Driven Agentic AI in Real Time

Agentic AI marks a major evolution in artificial intelligence—shifting from passive analytics to autonomous, goal-driven…

1 week ago

Shift Left Architecture at Siemens: Real-Time Innovation in Manufacturing and Logistics with Data Streaming

Industrial enterprises face increasing pressure to move faster, automate more, and adapt to constant change—without…

2 weeks ago

The Importance of Focus: Why Software Vendors Should Specialize Instead of Doing Everything (Example: Data Streaming)

As real-time technologies reshape IT architectures, software vendors face a critical decision: specialize deeply in…

3 weeks ago

The Top 20 Problems with Batch Processing (and How to Fix Them with Data Streaming)

Batch processing introduces delays, complexity, and data quality issues that modern businesses can no longer…

3 weeks ago