This example shows how to work with Camel in the Java Container using CDI to configure components, endpoints and beans.
This example is implemented using Java code with CDI injected resources. The source code is provided in the following java file src/main/java/io/fabric8/quickstarts/camelcdi/MyRoute.java
, which can be viewed from github.
This example pickup incoming files, calls a Java bean SomeBean
to transform the message, and writes the output to a file, as shown in the Camel route diagram below:
The example comes with sample data, making it easy to try the example yourself.
The example comes as source code and pre-built binaries with the fabric8 distribution.
To try the example you do not need to build from source first. Although building from source allows you to modify the source code, and re-deploy the changes to fabric. See more details on the fabric8 website about the developer workflow.
To build from the source code:
- Change your working directory to
quickstarts/java/camel-cdi
directory. - Run
mvn clean install
to build the quickstart.
After building from the source code, you can upload the changes to the fabric container:
- It is assumed that you have already created a fabric and are logged into a container called
root
. - Change your working directory to
quickstarts/java/camel-cdi
directory. - Run
mvn fabric8:deploy
to upload the quickstart to the fabric container.
If you run the fabric:deploy
command for the first then, it will ask you for the username and password to login the fabric container.
And then store this information in the local Maven settings file. You can find more details about this on the fabric8 website about the Maven Plugin.
The following information is divded into three sections, whether you are using the command line shell in fabric, or using the web console, or run the example from the source code.
You can deploy and run this example at the console command line, as follows:
-
It is assumed that you have already created a fabric and are logged into a container called
root
. -
Create a new child container and deploy the
quickstarts-java-camel.cdi
profile in a single step, by entering the following command at the console:fabric:container-create-child --profile quickstarts-java-camel.cdi root mychild
-
Wait for the new child container,
mychild
, to start up. Use thefabric:container-list
command to check the status of themychild
container and wait until the[provision status]
is shown assuccess
.
You can deploy and run this example from the web console, as follows
- It is assumed that you have already created a fabric and are logged into a container called
root
. - Login the web console
- Click the Wiki button in the navigation bar
- Select
quickstarts
-->java
-->camel.cdi
- Click the
New
button in the top right corner - In the Create New Container page, enter
mychild
in the Container Name field, and click the Create and start container button
Follow the instructions from the Building this example section, and after you have built the source code run the following command:
- Run
mvn camel:run
to run the example as a standalone Spring based Camel application.
Running outside fabric means that you do not have the fabric web console or fabric server to manage the application. You may want to use mvn camel:run
during development and to quickly try your code changes.
The following information is divded into two sections, whether you are using the command line shell in fabric, or using the web console
To use the application be sure to have deployed the quickstart in fabric8 as described above.
- As soon as the Camel route has been started, you will see a directory
instances/mychild/src/main/fabric8/data
in your Fabric8 installation. - Copy the files you find in this quick start's
src/main/fabric8/data
directory to the newly createdprocesses/mychild/src/data
directory. - Wait a few moments and you will find the files in the
instances/mychild/target/output
directory.
This example comes with sample data which you can use to try this example
-
Login the web console
-
Click the Runtime button in the navigation bar
-
Select the
mychild
container in the containers list, and click the open button right next to the container name. -
A new window opens and connects to the container. Click the Camel button in the navigation bar.
-
In the Camel tree, expand the
Endpoints
tree, and select the first node, which isfile://src/main/fabric8/data
, and click the Send button in the sub navigation bar. -
Click the Choose button and mark [x] for the five
data/message1.txt
...message2.txt
files. -
Click the Send 2 files button in the top right corner
-
Notice instead of Choose you can send your own files by clicking Compose which presents a screen where you can enter message content in the text area, and send by clicking the Send message button, as shown in the figure below:
![Camel Compose message](https://raw.githubusercontent.com/fabric8io/fabric8/master/docs/images/camel-compose-message.jpg)
-
In the Camel tree, expand the
Routes
node, and select the first node, which is the route. And click the Diagram button to see a visual representation of the route. -
Notice the numbers in the diagram, which illustrate that 2 messages has been processed.
-
You can click the Log button the navigation bar to see the business logging.
The following information is divded into two sections, whether you are using the command line shell in fabric, or using the web console
To stop and undeploy the example in fabric8:
-
Stop and delete the child container by entering the following command at the console:
fabric:container-stop mychild fabric:container-delete mychild
To stop and undeploy the example in fabric8:
- In the web console, click the Runtime button in the navigation bar.
- Select the
mychild
container in the Containers list, and click the Stop button in the top right corner