Red Hat JBoss Fuse 6.1 Tooling Tutorials

Red Hat JBoss Fuse 6.1 Tooling Tutorials

Red Hat JBoss Fuse 6.1

Tooling Tutorials

Building Solutions with Red Hat JBoss Fuse Tooling

JBoss Fuse Tooling Docs Team

Red Hat JBoss Fuse 6.1 Tooling Tutorials

Building Solutions with Red Hat JBoss Fuse Tooling

JBo ss Fuse To o ling Do cs Team

Co ntent Services fuse-do cs-suppo [email protected] m

Legal Notice

Co pyright © 20 14 Red Hat.

The text o f and illustratio ns in this do cument are licensed by Red Hat under a Creative

Co mmo ns Attributio n–Share Alike 3.0 Unpo rted license ("CC-BY-SA"). An explanatio n o f CC-

BY-SA is available at http://creativeco mmo ns.o rg/licenses/by-sa/3.0 /

. In acco rdance with CC-BY-SA, if yo u distribute this do cument o r an adaptatio n o f it, yo u must pro vide the URL fo r the o riginal versio n.

Red Hat, as the licenso r o f this do cument, waives the right to enfo rce, and agrees no t to assert,

Sectio n 4 d o f CC-BY-SA to the fullest extent permitted by applicable law.

Red Hat, Red Hat Enterprise Linux, the Shado wman lo go , JBo ss, MetaMatrix, Fedo ra, the Infinity

Lo go , and RHCE are trademarks o f Red Hat, Inc., registered in the United States and o ther co untries.

Linux ® is the registered trademark o f Linus To rvalds in the United States and o ther co untries.

Java ® is a registered trademark o f Oracle and/o r its affiliates.

XFS ® is a trademark o f Silico n Graphics Internatio nal Co rp. o r its subsidiaries in the United

States and/o r o ther co untries.

MySQL ® is a registered trademark o f MySQL AB in the United States, the Euro pean Unio n and o ther co untries.

No de.js ® is an o fficial trademark o f Jo yent. Red Hat So ftware Co llectio ns is no t fo rmally related to o r endo rsed by the o fficial Jo yent No de.js o pen so urce o r co mmercial pro ject.

The OpenStack ® Wo rd Mark and OpenStack Lo go are either registered trademarks/service marks o r trademarks/service marks o f the OpenStack Fo undatio n, in the United States and o ther co untries and are used with the OpenStack Fo undatio n's permissio n. We are no t affiliated with, endo rsed o r spo nso red by the OpenStack Fo undatio n, o r the OpenStack co mmunity.

All o ther trademarks are the pro perty o f their respective o wners.

Abstract

This guide co ntains a number o f simple tuto rials that demo nstrate ho w to use the to o ling pro vided by Red Hat JBo ss Fuse To o lingRed Hat JBo ss Fuse IDE to develo p and test applicatio ns.

Table of Contents

G o als

Creating the Fuse p ro ject

Creating the ro ute

Next step s

Further read ing

G o als

Prereq uisites

Running the ro ute

Verifying the ro ute

Further read ing

G o als

Prereq uisites

Pro ced ure

Next step s

Further read ing

G o als

Prereq uisites

Pro ced ure

Next step s

Further read ing

O verview

G o als

Prereq uisites

Creating the test case

Running the test

Further read ing

G o als

Prereq uisites

Starting up Red Hat JBo ss Fuse 6 .x Server

Dep lo ying a p ro ject to Red Hat JBo ss Fuse

Uninstalling yo ur p ro ject's b und le

Further read ing

G o als

Prereq uisites

Creating a fab ric in Red Hat JBo ss Fuse

Co nnecting to the JBo ss Fuse server

Co nnecting to the fab ric

Creating a new fab ric p ro file

Dep lo ying yo ur camel p ro ject to the new fab ric p ro file

T able of Cont ent s

23

23

23

27

28

18

18

18

22

22

33

33

33

36

37

37

29

29

29

29

31

32

15

15

15

16

17

7

7

10

14

14

39

39

39

40

42

42

42

1

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Dep lo ying yo ur camel p ro ject to the new fab ric p ro file

Further read ing

42

44

2

T able of Cont ent s

3

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

About Red Hat JBoss Fuse Tooling

Red Hat JBoss Fuse Tooling provides a set of developer tools that enable you to work with

Fuse and Apache versions of ActiveMQ, Camel, CXF, Karaf, and ServiceMix within Red Hat

JBoss Development Studio. You can connect and configure Enterprise Integration Patterns to build routes, browse endpoints and routes, drag and drop messages onto running routes, trace message flows, edit running routes, browse and visualize runtime processes via JMX, and deploy your project's code to Red Hat JBoss Fuse and Fabric8 containers, to Apache

ServiceMix, and to Apache Karaf.

The Red Hat JBoss Fuse Tooling consists of three feature plugins that you can install separately (via the Eclipse software install mechanism), which enables you to select only the features you need:

JBoss Fuse Camel Editor Feature (o rg . fuseso urce. i d e. camel . ed i to r. feature)

The JBoss Fuse Camel Editor Feature is the base building block for the remaining features that make up JBoss Fuse Tooling. It provides the tools for creating a Fuse project, including the route editor, with its palette of supported Enterprise Integration

Patterns, and the logic for running camel contexts inside the editor.

If you want only to create, test, and visualize routes, but not to debug them, you need install only the JBoss Fuse Camel Editor Feature.

No t e

Red Hat JBoss Fuse Service Works tooling uses the JBoss Fuse Camel Editor

Feature only.

Part I, Developing Applications of Using the JBoss Fuse Tooling describes the functionality that this feature provides.

JBoss Fuse Runtimes Feature (o rg . fuseso urce. i d e. runti mes. feature)

This feature extends the functionality of the JBoss Fuse Camel Editor Feature, allowing you to debug and monitor camel routes running in JMX-connected containers or as local processes, and to deploy camel routes to JMX-connected containers and Fabric8 containers. It includes the JMX and Fabric8 tooling.

If you want to debug and deploy the routes that you created with JBoss Fuse Camel

Editor Feature, you also need to install the JBoss Fuse Runtimes Feature.

Part II, Debugging Applications and Part III, Working with Fabrics of Using the JBoss Fuse

Tooling describe how to use the functionality this feature provides.

JBoss Fuse Server Extensions Feature

(o rg . fuseso urce. i d e. server. extensi o ns. feature)

4

About Red Hat JBoss Fuse T ooling

This feature extends the functionality of the JBoss Fuse Camel Editor and the JBoss Fuse

Runtimes Feature features to allow you to configure, run, and interact with any of the supported servers via a Karaf command shell inside JBoss Fuse Tooling. For example, with JBoss Fuse installed on your machine, you can start it up and then create a fabric in which to deploy the camel routes you created with the JBoss Fuse Camel Editor Feature.

If you want to run and interact directly with any of the supported servers from inside the

JBoss Fuse Tooling, you also need to install the JBoss Fuse Server Extensions Feature.

Managing servers in Part II, Debugging Applications of the Using the JBoss Fuse Tooling guide describes how to use the functionality this feature group provides.

Using Red Hat JBoss Fuse Tooling simplifies and streamlines the process of developing integration applications by providing tooling that is specifically designed to work with:

Red Hat JBoss Fuse

Red Hat JBoss A-MQ

Red Hat JBoss Fuse Service Works (works with JBoss Fuse Camel Editor Feature only)

Apache Camel

Apache CXF

Apache Karaf

Using the Red Hat JBoss Fuse Tooling streamlines the process at all stages of application development:

1. Create a Maven project for your application.

The tooling loads all of the relevant Maven archetypes for creating integration projects using the Red Hat supported Apache projects.

2. Add new pieces of logic and functionality to an application.

The tooling has a wizard for creating Apache Camel context files.

3. Edit the integration logic.

The tooling has a visual route editor that makes editing Apache Camel routes as easy as dragging and dropping route components.

4. Test the application.

5

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

The tooling includes testing tools that provide the full gamut of testing capabilities including: creating JUnit test cases for Apache Camel routes

JMX analysis of running components message tracing through Apache Camel routes

5. Deploy the application.

The tooling can deploy applications to a number of containers.

6

Chapt er 1 . T o Creat e a New Rout e

Chapter 1. To Create a New Route

Ab st ract

This tutorial walks you through the process of creating a new Fuse project, adding a route to it, and adding two endpoints to the route. It assumes that you have already set up your workspace and that Red Hat JBoss Fuse Tooling is running inside Red Hat JBoss

Developer Studio.

Goals

In this tutorial you will: create a routing project add endpoints to a route connect two endpoints configure the endpoints

Creat ing t he Fuse project

To create a Fuse project:

1. Open the JBoss perspective.

This is the default perspective when you start up JBoss Developer Studio for the first time.

2. On the Toolbar, select FileNewFu se Pro ject to open the New Fuse

pro ject wizard, as shown in

Figure 1.1, “ New Fuse project location page”

.

Fig u re 1.1. New Fu se p ro ject lo cat io n p ag e

7

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

3. Click Next> to open the New Fuse P ro ject details page, as shown in Figure 1.2,

“ New Fuse project details page” .

Fig u re 1.2. New Fu se p ro ject d et ails p ag e

8

Chapt er 1 . T o Creat e a New Rout e

4. Select camel -archetype-spri ng .

5. Enter tuto ri al in the G ro up Id : field.

6. Enter si mpl e-ro ute in the Arti fact Id : field.

7. The Versi o n: field defaults to 1. 0 . 0 -SNAP SHO T . To change it, enter a different version identifier.

8. The P ackag e: field defaults to tuto ri al . si mpl e. ro ute, the name of the package that contains camel -archetype-spri ng . To include the route in a different package, enter the name of that package.

9. Click Fi ni sh.

9

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

This procedure creates a Fuse project, si mpl e-ro ute, in P ro ject Expl o rer that

contains everything needed to create and run routes. As shown in Figure 1.3

, the files

generated for si mpl e-ro ute include:

si mpl e-ro ute/po m. xml (Maven project file)

si mpl e-ro ute/src/mai n/reso urces/MET A-INF/spri ng /camel -

co ntext. xml (Spring XML file containing the routing rules)

Fig u re 1.3. G en erat ed p ro ject f iles

10

Creat ing t he rout e

To create the new route:

1. In P ro ject Expl o rer, locate si mpl e-ro ute/src/mai n/reso urces/MET A-

INF/spri ng /camel -co ntext. xml .

2. Right-click it to open the context menu, then select D el ete.

You're going to replace the old camel -co ntext. xml file with your own to create a new route.

3. In the D el ete dialog, click O K to confirm the operation.

4. In P ro ject Expl o rer, select si mpl e-ro ute/src/mai n/reso urces/MET A-

INF/spri ng .

5. Right-click it to open the context menu.

6. Select NewCamel XML File to open the C amel XML Fi l e wizard, as shown in

Figure 1.4

.

Fig u re 1.4 . Camel XML File wiz ard

Chapt er 1 . T o Creat e a New Rout e

7. Check that /si mpl e-ro ute/src/mai n/reso urces/MET A-INF/spri ng appears in the C o ntai ner: field. Otherwise enter it manually, or select it using the button.

No t e

The button opens a dialog that displays the folders of all active projects, which you can browse to find and select the files you need.

8. Check that camel C o ntext. xml appears in the Fi l e Name: field. Otherwise enter it manually.

9. Check that Sp rin g appears in the Framewo rk field, or select it from the field's dropdown list.

10. Click Fi ni sh.

No t e

By default, O utl i ne view is located in the upper, right corner of the JBoss perspective. To provide more room for D esi g n view to display the graphical representation of your route, drag O utl i ne view to the lower, left corner of the workspace, below P ro ject Expl o rer.

11. Click the So urce tab at the bottom, left of the canvas to open the new

camel C o ntext. xml file in the route editor's Source view, as shown in

Figure 1.5,

“ New camelContext file in the route editor's source view” .

11

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

“ New camelContext file in the route editor's source view” .

Fig u re 1.5. New camelCo n t ext f ile in t h e ro u t e ed it o r' s so u rce view

12. Click the D esi g n tab at the bottom, left of the canvas to return to the route editor's

Design view.

13. Drag an End po i nt element (

) from the P al ette to the canvas.

14. Drag a second End po i nt element from the P al ette to the canvas.

15. Select the first endpoint you dragged onto the canvas.

The P ro perti es editor, located below the canvas, displays the endpoint's property

fields for editing, as shown in Figure 1.6, “ Endpoint property editor” .

Fig u re 1.6 . En d p o in t p ro p ert y ed it o r

12

16. Enter fi l e: src/d ata?no o p= true in the Uri field. Leave the other fields blank.

17. Select the second endpoint you dragged onto the canvas.

18. Enter fi l e: targ et/messag es/o thers in the Uri field. Leave the other fields blank.

19. On the canvas, select the first endpoint (fi l e: src/d ata?no o p= true), and drag it's connector arrow (

Chapt er 1 . T o Creat e a New Rout e

) to the second endpoint (fi l e: targ et/messag es/o thers), then release it.

A segmented line connects the two endpoints, as shown in Figure 1.7

.

Fig u re 1.7. Co mp let ed ro u t e, d iag ram view

No t e

You can drag the line's bendpoint (orange dot) to change the angle of the line's segments. Doing so creates two new bendpoints, one on either side of the original. This behavior enables you to easily adjust your diagram to accommodate increasingly complex routes.

20. To quickly align the connected endpoints, right-click the canvas to open the context menu, and then select Layo u t Diag ram.

21. Select FileSave to save the route.

22. Click the So urce tab at bottom, left of the canvas.

So urce view displays the XML for the route. The camel C o ntext element will look

like Example 1.1

.

Examp le 1.1. XML f o r simp le ro u t e

<?xml

version="1.0" encoding="UTF-8"

?>

<beans

xmlns= "http://www.springframework.org/schema/beans"

xmlns:camel= "http://camel.apache.org/schema/spring"

xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.springframework.org/schema/bean s

http://www.springframework.org/schema/beans/springbeans-3.0.xsd

http://camel.apache.org/schema/spring

http://camel.apache.org/schema/spring/camelspring.xsd"

>

<camel C o ntext

trace= "false" xmlns= "http://camel.apache.org/schema/spring"

>

<ro ute>

13

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

<fro m

uri= "file:src/data?noop=true"

/>

<to

uri= "file:target/messages/others"

/>

</ro ute>

</camel C o ntext>

</beans>

Next st eps

After you have created and designed your route, you can run it by deploying it into your

Apache Camel runtime, as described in Chapter 2, To Run a Route

.

Furt her reading

To learn more about: using the editor, see Red Hat JBoss Fuse Tooling: JBoss Fuse Tooling User Guide at https://access.redhat.com/site/documentation/JBoss_Fuse/

Apache Camel endpoints, see Red Hat JBoss Fuse: Component Reference that comes with

Red Hat JBoss Fuse.

14

Chapt er 2 . T o Run a Rout e

Chapter 2. To Run a Route

Ab st ract

This tutorial walks you through the process of running a route.

Goals

In this tutorial you will: run a route as a local Apache Camel context send messages through a route examine the messages received by the endpoints

Prerequisit es

To complete this tutorial you will need the Apache Camel project created in Chapter 1, To

Create a New Route

.

Running t he rout e

To run the route:

1. Open the simp le- ro u t e project you created in the section called “ Creating the Fuse project” .

2. In P ro ject Expl o rer, select si mpl e-ro ute/src/mai n/reso urces/MET A-

INF/spri ng /camel C o ntext. xml .

3. Right-click it to open the context menu, then select Ru n AsLo cal Camel

Co n t ext ( wit h o u t t est s) .

The C o nso l e panel opens to display messages that reflect the progress of the project's execution. A message similar to the following

[INFO] Using org.apache.camel.spring.Main to initiate a

CamelContext [pache.camel.spring.Main.main()] MainSupport INFO

Apache Camel 2.12.0.redhat-610062 starting

[pache.camel.spring.Main.main()] SpringCamelContext INFO

Apache Camel 2.12.0.redhat-610062 (CamelContext: camel-1) is starting [pache.camel.spring.Main.main()]

ManagedManagementStrategy INFO JMX is enabled

[pache.camel.spring.Main.main()] DefaultTypeConverter INFO

15

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Loaded 176 type converters [pache.camel.spring.Main.main()]

SpringCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html

[pache.camel.spring.Main.main()] FileEndpoint INFO Endpoint is configured with noop=true so forcing endpoint to be idempotent as well [pache.camel.spring.Main.main()] FileEndpoint INFO

Using default memory based idempotent repository with cache max size: 1000 [pache.camel.spring.Main.main()]

SpringCamelContext INFO Route: route1 started and consuming from: Endpoint[file://src/data?noop=true]

[pache.camel.spring.Main.main()] SpringCamelContext INFO Total

1 routes, of which 1 is started.

[pache.camel.spring.Main.main()] SpringCamelContext INFO

Apache Camel 2.12.0.redhat-610062 (CamelContext: camel-1) started in 0.354 seconds indicates the route executed successfully.

4. To shutdown the route, click the red square (

) located at the top, right of the C o nso l e panel.

Verifying t he rout e

To verify that the route executed properly:

1. In P ro ject Expl o rer, select si mpl e-ro ute.

2. Right-click it to open the context menu, then select Ref resh .

3. In P ro ject Expl o rer, locate the folder targ et/messag es/ and expand it, as shown in

Figure 2.1

.

Fig u re 2.1. T arg et messag e d est in at io n s in Pro ject Exp lo rer t ree

16

4. Verify that the targ et/messag es/ subfolders contain these files:

Chapt er 2 . T o Run a Rout e uk/messag e1. xml o thers/messag e2. xml

5. Double-click messag e1. xml to open it in the editor's Design view, then select the

So urce tab at the bottom, left of the canvas to see the xml code.

It's contents should match that shown in

Example 2.1

.

Examp le 2.1. Co n t en t s o f messag e1.xml

<?xml

version="1.0" encoding="UTF-8"

?>

<perso n

user= "james"

>

<fi rstName>

James

</fi rstName>

<l astName>

Strachan

</l astName>

<ci ty>

London

</ci ty>

</perso n>

Furt her reading

To learn more about: configuring runtime profiles, see Red Hat JBoss Fuse Tooling: JBoss Fuse Tooling User

Guide at https://access.redhat.com/site/documentation/JBoss_Fuse/ .

deploying Apache Camel applications see Red Hat JBoss Fuse: Deploying into the Container that comes with Red Hat JBoss Fuse.

17

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Chapter 3. To Add a Content-Based Router

Ab st ract

This tutorial walks you through adding a content-based router with logging to a route.

Goals

In this tutorial you will: add a content based-router to a route configure the content-based router add a log endpoint to each output branch of the content-based router rewire the route to use the content-based router and log its output

Prerequisit es

To complete this tutorial you will need the simp le- ro u t e project you created in Chapter 1,

To Create a New Route

.

Procedure

To add a content-based router with logging to your route:

1. In P ro ject Expl o rer, double-click si mpl e-

ro ute/src/mai n/reso urces/MET A-INF/spri ng /camel C o ntext. xml to open your si mpl e-ro ute project.

2. Select the connector joining the two endpoint nodes fi l e: src/d ata?no o p= true and fi l e: targ et/messag es/o thers.

3. Right-click it to open the context menu, and select Ed it Remo ve to delete the connector.

No t e

Alternatively, you can delete the connector by selecting it, then selecting Delet e from the toolbar's Ed it menu.

4. On the canvas, select the terminal endpoint node,

fi l e: targ et/messag es/o thers, and drag it out of the way.

18

Chapt er 3. T o Add a Cont ent - Based Rout er

5. On the canvas, select the starting endpoint node, fi l e: src/d ata?no o p= true, and right-click it to open the context menu.

6. Select Ad d Ro u t in g Ch o ice.

A cho i ce node (

) appears on the canvas connected to the starting endpoint node.

7. On the canvas, select the cho i ce node, then right-click it to open the context menu.

8. Select Ad d Ro u t in g Wh en .

A when node (

) appears on the canvas connected to the cho i ce node. The P ro perti es editor opens, displaying the when node's property fields for you to edit, as shown in

Figure 3.1

.

Fig u re 3.1. Wh en p ro p ert y ed it o r

9. In the Expressi o n field, enter /perso n/ci ty= ' Lo nd o n' .

This XPath expression determines which messages will transit this path in the route.

10. From the Lang uag e drop-down menu, select xpath.

11. In the Id field, enter when1.

12. On the canvas, reselect the Ch o ice node, then right-click it to open the context menu.

13. Select Ad d Ro u t in g O t h erwise.

An o t h erwise node (

) appears on the canvas, connected to the ch o ice node.

19

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

The o t h erwise node will eventually route to the terminal endpoint

(fi l e: targ et/messag es/o thers) any message that does not match the XPath expression set for the wh en 1 node.

14. On the canvas, select the when1 node, and then right-click it to open the context menu.

15. Select Ad d En d p o in t sLo g

A lo g node (

) appears on the canvas, connected to the wh en 1 node. The P ro perti es editor opens, displaying the l o g node's property fields for you to edit.

16. In the Messag e field, enter uk messag es, and in the Lo g Name field, enter 1.

No t e

In Fuse Integ rati o n perspective's Messag es Vi ew, the tooling inserts the contents of the log node's Id field in the T race No d e Id column for message

instances, when tracing is enabled on the route (see Figure 4.4

). In the

C o nso l e, it adds the contents of the log node's Messag e field to the log data whenever the route runs.

17. On the canvas, select the o therwi se node, and then right-click it to open the context menu.

18. Select Ad d En d p o in t sLo g

A lo g node (

) appears on the canvas, connected to the o t h erwise node. The P ro perti es editor opens, displaying the l o g node's property fields for you to edit.

19. In the Messag e field, enter o ther messag es, and in the Lo g Name field, enter 2.

20. On the canvas, select the l o g 1 node, and then right-click it to open the context menu.

21. Select Ad d En d p o in t sEn d p o in t

An En d p o in t node (

) appears on the canvas, connected to the lo g 1 node. The P ro perti es editor opens, displaying the End po i nt node's property fields for you to edit.

22. In the Uri field, enter fi l e: targ et/messag es/uk, and leave the other property fields blank.

20

Chapt er 3. T o Add a Cont ent - Based Rout er

23. On the canvas, select the lo g 2 node, and then drag its connector arrow (

) to the terminal endpoint node, fi l e: targ et/messag es/o thers, and release it.

24. To quickly realign all of the nodes on the canvas, right-click the canvas to open the context menu, and then select Layo u t Diag ram.

The route on the canvas should resemble Figure 3.2

.

Fig u re 3.2. Co mp let ed co n t en t - b ased ro u t er wit h lo g s

25. On the toolbar, select FileSave to save the completed route.

26. Click the So urce tab at the bottom, left of the canvas to display the XML for the route.

The camel C o ntext element will look like that shown in

Example 3.1

.

Examp le 3.1. XML f o r co n t en t - b ased ro u t er

<?xml

version="1.0" encoding="UTF-8"

?>

<beans

xmlns= "http://www.springframework.org/schema/beans"

xmlns:camel= "http://camel.apache.org/schema/spring"

xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.springframework.org/schema/bean s

http://www.springframework.org/schema/beans/springbeans-3.0.xsd

http://camel.apache.org/schema/spring

http://camel.apache.org/schema/spring/camelspring.xsd"

>

<camel C o ntext

trace= "false" xmlns= "http://camel.apache.org/schema/spring"

>

<ro ute>

<fro m

uri= "file:src/data?noop=true"

/>

21

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

<cho i ce>

<when

id= "when1"

>

<xpath>

/person/city='London'

</xpath>

<l o g

logName= "1" message= "uk messages"

/>

<to

uri= "file:target/messages/uk"

/>

</when>

<o therwi se>

<l o g

logName= "2" message= "other messages"

/>

<to

uri= "file:target/messages/others"

/>

</o therwi se>

</cho i ce>

</ro ute>

</camel C o ntext>

</beans>

Next st eps

You can run the new route as described in the section called “ Running the route”

.

Furt her reading

To learn more about message enrichment see: the when EIP in Red Hat JBoss Fuse: Enterprise Implementing Integration Patterns the Red Hat JBoss Fuse 6.x documentation

22

Chapt er 4 . T o T race a Message T hrough a Rout e

Chapter 4. To Trace a Message Through a Route

Ab st ract

This tutorial walks you through the process of tracing a message through a route.

Goals

In this tutorial you will: run a route in the Fuse Integ rati o n perspective enable tracing on your route drop messages onto your route and track them through the route's nodes

Prerequisit es

To complete this tutorial you will need the si mpl e-ro ute project you updated in Chapter 3,

To Add a Content-Based Router

.

Procedure

To trace a message through your route:

1. Select Win d o wO p en Persp ect iveO t h er...Fu se In t eg rat io n to open

the Fuse Integ rati o n perspective as shown in Figure 4.1, “ Fuse Integration perspective” ).

Fig u re 4 .1. Fu se In t eg rat io n p ersp ect ive

23

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

24

No t e

You can use the O pen P erspecti ve icon (

) in the perspectives tab to access the list of available perspectives.

2. In P ro ject Expl o rer, expand the si mpl e-ro ute project to expose the

src/mai n/reso urces/MET A-INF/spri ng /camel -co ntext. xml file.

3. Select Ru n AsLo cal Camel Co n t ext ( wit h o u t t est s) from the camel -

co ntext. xml file's context menu.

4. In Fuse JMX Navi g ato r, expand Lo cal P ro cesses.

5. Double click Lo cal Camel Co n t ext [ id] to connect to the context and expand the

elements of your route as shown in Figure 4.2, “ Route elements in Fuse JMX

Navigator” ).

Fig u re 4 .2. Ro u t e elemen t s in Fu se JMX Navig at o r

Chapt er 4 . T o T race a Message T hrough a Rout e

6. In Fuse JMX Navi g ato r, select St art T racin g from the camel- 1 node's context menu.

The tooling displays a graphical representation of your route in D i ag ram Vi ew.

7. In D i ag ram Vi ew, drag the nodes to rearrange them, so you can clearly see the route's flow paths.

No t e

You will have to rearrange the nodes in D i ag ram Vi ew each time you select a different node in Fuse JMX Navi g ato r.

8. In P ro ject Expl o rer, expand si mpl e-ro ute/src/d ata, so you can access the

messag e1. xml and messag e2. xml files as shown in

Figure 4.3, “ Message files in simple-route project” .

Fig u re 4 .3. Messag e f iles in simp le- ro u t e p ro ject

25

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

26

9. Drag messag e1. xml and drop it on . . . /camel -

1/End po i nts/fi l e/src/d ata?no o p= true.

As the message traverses the route, the tooling traces and records its passage at each step and displays the results in Messag es Vi ew.

10. Repeat

Step 9 , but this time drag messag e2. xml and drop it on . . . /camel -

1/End po i nts/fi l e/src/d ata?no o p= true.

11. In the bottom, right panel, switch from C o nso l e to Messag es Vi ew.

12. In Fuse JMX Navi g ato r, click camel- 1 to populate Messag es Vi ew with the traces of each message.

As shown in Figure 4.4, “ Fuse Integration perspective's message tracing components” , the tooling draws the route in D i ag ram Vi ew, tagging paths exiting a

processing step with timing and performance metrics. Only the metric T o tal

exchang es is displayed in the diagram. Hovering over the displayed metrics reveals additional metrics about message flow: mean time the step took to process a message maximum time the step took to process a message minimum time the step took to process a message

Fig u re 4 .4 . Fu se In t eg rat io n p ersp ect ive' s messag e t racin g co mp o n en t s

Chapt er 4 . T o T race a Message T hrough a Rout e

13. In Messag es Vi ew, click a message instance.

The associated step in the route is highlighted in D i ag ram Vi ew. You can step through the message instances to see how a particular message traversed the route and whether it was processed as expected at each step in the route.

The tooling displays the details about a message instance in the top half of the

P ro perti es panel and the contents of the message instance, including any headers, in the bottom half of the P ro perti es panel. So, if your application sets headers at any step within a route, you can check whether they are set as expected.

No t e

You can control columnar layout in all of the tooling's tables. Use the drag method to temporarily rearrange tabular format. For example, drag a column's border rule to expand or contract its width. To hide a column, totally contract its borders. Drag the column header to relocate a column within the table. If you want your arrangement to persist, use the View Men u Co n f ig u re

Co lu mn s... method instead. To access it, click the icon on the panel's menu bar.

14. When done, switch back to the C o nso l e and click the sto p button (

) in the upper, right side of its pane.

Next st eps

You can run the route with a JUnit test case, as described in Chapter 5, To Test a Route with

JUnit

.

27

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Furt her reading

To learn more about message enrichment see: the cho i ce, when, and l o g EIP Enterprise Integration Patterns in Red Hat JBoss Fuse:

Implementing Enterprise Integration Patterns that comes with Red Hat JBoss Fuse.

the Red Hat JBoss Fuse 6.x documentation library

28

Chapt er 5. T o T est a Rout e wit h JUnit

Chapter 5. To Test a Route with JUnit

Ab st ract

This tutorial walks you through the process of using the New Camel Test Case wizard to create a test case for your route and using it test the route.

Overview

The New Camel JUnit Test Case wizard generates a boilerplate JUnit test case. This means that when you create or modify a route (for example, adding more processors to it), you'll need to modify the generated test case to add expectations and assertions specific to the new route you've created, so the test is valid for the route.

Goals

In this tutorial you will: create a Apache Camel test case run the route with the test case observe the output

Prerequisit es

To complete this tutorial you will need:

the simp le- ro u t e project you created in Chapter 3, To Add a Content-Based Router

Creat ing t he t est case

To create a new test case:

1. In P ro ject Expl o rer, select src/test/java.

2. Right-click it to open the context menu, and then select NewCamel T est Case to

open the New C amel JUni t T est C ase wizard, as shown in Figure 5.1, “ New

Camel JUnit Test Case wizard” .

Fig u re 5.1. New Camel JUn it T est Case wiz ard

29

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

30

3. Make sure the So urce fo l d er field contains si mpl e-ro ute/src/test/java.

No t e

If needed, you can click to find the proper folder.

4. The P ackag e field defaults to tuto ri al . si mpl e-ro ute. To include the test case in a different package, enter the name of the package.

5. In the C amel XML fi l e und er test field, enter src/mai n/reso urces/MET A-

INF/spri ng /camel C o ntext. xml , or use to open a file explorer, configured to screen for XML files, to locate the file.

No t e

The Name field defaults to CamelContextXmlTest for the name of the test file.

6. Click Next> to open the T est End po i nts page, shown in Figure 5.2, “ Test

Endpoints page” .

Fig u re 5.2. T est En d p o in t s p ag e

Chapt er 5. T o T est a Rout e wit h JUnit

7. By default, all endpoints are selected and will be included in the test case. You can select or deselect all endpoints by clicking the Sel ect Al l or D esel ect Al l button, or you can select and deselect individual endpoints by clicking the check box next to each.

8. Click Fi ni sh.

No t e

If prompted, add JUnit to the build path.

The artifacts for the test are added to your project, and the class implementing the test case opens in the Java editor.

Running t he t est

To run the test:

1. Select the project root, si mpl e-ro ute, in the P ro ject Expl o rer.

2. Open the context menu.

3. Select Ru n AsJUn it T est .

The JUni t view, shown in Figure 5.3, “ JUnit view”

, opens in the Eclipse sidebar.

Fig u re 5.3. JUn it view

31

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

4. Examine the output and take action to resolve any test failures.

No t e

You may have to run this boilerplate test twice before it runs without a failure.

Furt her reading

To learn more about: see JUnit

32

Chapt er 6 . T o Deploy a Camel Project t o Red Hat JBoss Fuse

Chapter 6. To Deploy a Camel Project to Red Hat JBoss

Fuse

Ab st ract

This tutorial walks you through the process of deploying a camel project into Red Hat JBoss

Fuse. It assumes that you have an instance of Red Hat JBoss Fuse installed on the same machine on which you are running the Red Hat JBoss Fuse Tooling.

Goals

In this tutorial you will: start up Red Hat JBoss Fuse 6.x Server deploy your project into Red Hat JBoss Fuse 6.x Server check whether your project was successfully built and deployed uninstall your deployed bundle

Prerequisit es

To complete this tutorial you will need access to a Red Hat JBoss Fuse instance the simp le- ro u t e project you updated in

Chapter 3, To Add a Content-Based Router

St art ing up Red Hat JBoss Fuse 6.x Server

To start up the server:

1. In Fuse Integ rati o n perspective, click the Servers tab in the lower, right pane to open the Servers view.

2. Click the link No servers are avai l abl e. C l i ck thi s l i nk to create a

new server. . . to open the D efi ne a New Server page.

3. Expand the JBo ss Fuse node to expose the available server options as shown in

Figure 6.1

.

Fig u re 6 .1. Def in e a New Server p ag e

33

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

34

4. Click JBo ss Fuse 6 . 1 Server.

5. Accept the defaults for Server' s ho st name (localhost) and Server name (JBoss

Fuse 6.1 Server at localhost), and then click Next to open the JBo ss Fuse R unti me page.

6. In Instal l ati o n d i recto ry, enter the path where the JBoss Fuse 6.1 installation is located, or click the Bro wse to search for it, and then click Next to open the New

Server> JBo ss Fuse server co nfi g urati o n d etai l s page.

Fig u re 6 .2. New server co n f ig u rat io n

Chapt er 6 . T o Deploy a Camel Project t o Red Hat JBoss Fuse

7. Accept the defaults for Ho st Name (0.0.0.0) and P o rt Number (8101).

8. In User name, enter the name used to log into the server.

This is a user name stored in Red Hat JBoss Fuse's

installDir/etc/users. pro perti es file.

If one has not been set, you can either add one to that file using the format

user= passwo rd ,ro l e (for example, ad mi n= ad mi n,ad mi n), or you can set one using the karaf jaas command set:

jaas: real ms—to list the realms

jaas: manag e --i nd ex 1—to edit the first (server) realm

jaas: userad d <username> <passwo rd >—to add a user and associated password

jaas: ro l ead d <username> ad mi n—to specify the new user's role

jaas: upd ate—to update the realm with the new user information

If a jaas realm has already been selected for the server, you can discover the user name by issuing the command JBo ssFuse: [email protected] ro o t>jaas: users.

9. In P asswo rd , enter the password required for User name to log into the server.

This is the password set either in Red Hat JBoss Fuse's

installDir/etc/users. pro perti es file or by the karaf jaas commands.

10. Click Next, and then click Fi ni sh.

35

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

10. Click Next, and then click Fi ni sh.

jbo ss-fuse-6 . 1. 0 . red hat-xxx [sto pped ] appears in Servers view.

11. In Servers view, right-click jbo ss-fuse-6 . 1. 0 . red hat-xxx to open the context menu, and then click St art .

Imp o rt an t

If the warning that the remote host identification has changed appears, click yes to delete the old key and insert the new key, only if the JBoss Fuse 6.1 server runtime is installed on the same machine where the Red Hat JBoss Fuse Tooling is running! Otherwise click no and contact your system administrator.

Wait a few seconds for JBoss Fuse 6.1 Server to start up. When it does, JBo ss Fuse

[xxx] is added to the Fuse JMX Navi g ato r tree under the Local Processes node, but you need to expand the Local Processes node to see it.

The JBoss Fuse console also starts up in Shel l view, as shown in Figure 6.3

:

Fig u re 6 .3. JBo ss Fu se co n so le

36

12. In Fuse JMX Navi g ato r, right-click JBo ss Fuse [xxx] to open the context menu, and then click Co n n ect .

13. In Fuse JMX Navi g ato r, expand the JBo ss Fuse [xxx] node to see its tree structure.

Now you're ready to deploy your project.

Deploying a project t o Red Hat JBoss Fuse

Chapt er 6 . T o Deploy a Camel Project t o Red Hat JBoss Fuse

To deploy a camel project to JBoss Fuse:

1. From P ro ject Expl o rer, drag the si mpl e-ro ute root project over to Fuse JMX

Navi g ato r and drop it on JBo ss Fuse [xxx].

No t e

The Dep lo y t o ... tool provides an alternative to the drag and drop method of deployment. For details, see Deploying Projects to a Container in the Red Hat JBoss

Fuse Tooling: JBoss Fuse Tooling User Guide.

C o nso l e view chronicles the process as the tooling builds the si mpl e-ro ute project, runs the tests, and then installs the project as a bundle inside JBo ss Fuse

[xxx].

2. In Fuse JMX Navi g ato r, right-click JBo ss Fuse [xxx] to open the context menu, and then click Ref resh .

No t e

You may have to repeat the Ref resh operation before your project appears in

Fuse JMX Navi g ato r under JBo ss Fu se [ xxx}Camel as

<bundleIdentifier>-camel -#. (Camel generates and appends an ID number to the end of the node name to ensure that every camel context is uniquely identified.)

In the mean time, you can verify whether your project's bundle was installed by clicking the Bu n d les node under JBo ss Fuse [xxx] to display, in

Pro p ert ies view, all installed bundles. Start typing tutorial in Pro p ert ies view's

Search tool to quickly determine whether your project's tuto ri al . si mpl e-

ro ute bundle is included in the list.

Once your project appears in Fuse JMX Navigator, you can start tracing on it, as

described in Chapter 4, To Trace a Message Through a Route

.

Uninst alling your project 's bundle

To uninstall your project from JBoss Fuse 6.1 server:

1. Switch to the JBoss Fuse console in Shel l view.

2. At the JBoss Fuse console command line, type uni nstal l <bundleIdentifier>

Furt her reading

To learn more about deploying applications to external containers, see:

37

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Deploying Projects to a Container in the Red Hat JBoss Fuse Tooling: JBoss Fuse Tooling User

Guide

38

Chapt er 7 . T o Deploy a Camel Project t o a fabric profile

Chapter 7. To Deploy a Camel Project to a fabric profile

Ab st ract

This tutorial walks you through the process of deploying a camel project into a fabric profile in Fuse Integ rati o n perspective. It assumes that you have an instance of Red Hat JBoss

Fuse installed on the same machine on which you are running the Red Hat JBoss Fuse

Tooling.

Goals

In this tutorial you will: create a fabric in JBoss Fuse 6.x Server connect to the JBoss Fuse 6.x Server connect to the fabric create a new fabric profile deploy your project to the new fabric profile

Prerequisit es

To complete this tutorial you will need: access to Red Hat JBoss Fuse a user with admin privileges configured in JBoss Fuse's

installDir/etc/users. pro perti es file, as described in Starting up Red Hat JBoss Fuse

6.x Server starting at Step 8 .

the simp le- ro u t e project you updated in

Chapter 3, To Add a Content-Based Router

Creat ing a fabric in Red Hat JBoss Fuse

To create a fabric in Red Hat JBoss Fuse:

1. Open a terminal and cd to the JBoss Fuse server's installDir.

2. Enter . /bi n/fuse to start up a standalone instance of jbo ss-fuse-

6 . x. x. red hat-xxx.

39

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Wait a few seconds for the JBoss Fuse 6.x server to start up.

3. At the JBoss Fuse console command line, enter fabri c: create and press Enter to create a fabric.

JBossFuse:[email protected] root> fabric:create

Waiting for container: root

Using specified zookeeper password:admin

It may take a couple of seconds for the container to provision...

You can use the --wait-for-provisioning option, if you want this command to block until the container is provisioned.

JBossFuse:[email protected] root>

You can use the fabri c: status command to check whether the fabric has been created and provisioned.

JBossFuse:[email protected] root> fabric:status

[profile] [instances] [health] fabric 1 100% fabric-ensemble-0000-1 1 100% jboss-fuse-full 1 100%

JBossFuse:[email protected] root>

4. Once the fabric is running, enter fabri c: co ntai ner-l i st and press Enter to list the new fabric's default container (ro o t*) and its status.

JBossFuse:[email protected] root> fabric:container-list

[id] [version] [alive] [profiles]

[provision status] root* 1.0 true fabric,fabric-ensemble-0000-1,jbossfuse-full success

JBossFuse:[email protected] root>

Connect ing t o t he JBoss Fuse server

To connect the Fuse Tooling to the JBoss Fuse server:

1. If necessary, reopen Fuse Integ rati o n perspective.

2. In Fabri c Expl o rer, right-click Fabri cs to open the context menu, and then click

Ad d Fabri c d etai l s to open the Fabri c D etai l s wizard.

Fig u re 7.1. Fab ric Det ails wiz ard

4 0

Chapt er 7 . T o Deploy a Camel Project t o a fabric profile

3. In Name, enter the name of the fabric to which you want to connect. The name you enter identifies the fabric whose location you specify in Jo l o ki a UR L, and this name will appear in Fabri c Expl o rer.

The default Name is Local Fabric.

4. In Jo l o ki a UR L, enter the url, in the form http: //ho stname: po rt/jo l o ki a/, of the fabric to which you want to connect. This URL specifies the location of a fabric

registry agent, whose default port is 8181.

The default URL is http://localhost:8181/jolokia.

5. In User name, enter the name used to log into the specified fabric.

This is the user name specified when the fabric was created, has ad mi n privileges, and is stored in Red Hat JBoss Fuse's installDir/etc/users. pro perti es file. In that file, user information is specified using this format: user= passwo rd ,ro l e (for example, ad mi n= ad mi n,ad mi n).

You can also discover the user name by issuing the command

JBo ssFuse: [email protected] ro o t>jaas: users, if the Jaas realm has been selected for the fabric.

6. In P asswo rd , enter the password required for User name to log into the specified fabric.

This is the password specified for User name when the fabric was created and is stored in Red Hat JBoss Fuse's installDir/etc/users. pro perti es file.

7. In Zo o keeper P asswo rd , enter the password required for logging into the specified fabric's zookeeper registry.

This is the password that was specified when the fabric was created, or it is the password of the first user defined in Red Hat JBoss Fuse's

installDir/etc/users. pro perti es file.

4 1

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

You can also discover the Z ookeeper password by issuing the command

JBo ssFuse: [email protected] ro o t>fabri c: ensembl e-passwo rd .

8. Click O K.

The fabric's name appears in Fabri c Expl o rer as a node beneath Fabri cs.

Connect ing t o t he fabric

In Fabri c Expl o rer, right-click Lo cal Fabri c to open the context menu, and then click

C o nnect to connect to the new fabric.

Now you're ready to create a new fabric profile into which you'll deploy your camel project.

Creat ing a new fabric profile

To create a new fabric profile:

1. In Fabri c Expl o rer, expand Lo cal Fab ricVersio n s1.0 to reveal the fabric's top-level profiles.

2. Further expand the profiles tree to find the exampl e-q ui ckstarts-jms profile nested under d efaul t/karaf/feature-camel /feature-camel -jms/.

3. Right-click exampl e-q ui ckstarts-jms to open the context menu, and then click

Creat e a n ew Pro f ile.

4. In P ro fi l e name, enter myC amel R o ute, and then click O K.

The new profile myC amel R o ute appears under its parent profile, exampl e-

q ui ckstarts-jms, in Fabri c Expl o rer.

5. Click the myC amel R o ute profile to populate the D etai l s tab's P ro fi l es page with its information.

6. In the P arents pane, you can see that exampl e-q ui ckstarts-jms is the new profile's immediate parent. Leave exampl e-q ui ckstarts-jms selected.

Now you're ready to deploy your camel project to the profile myC amel R o ute.

Deploying your camel project t o t he new fabric profile

To deploy your camel project to the new myC amel R o ute fabric profile:

4 2

Chapt er 7 . T o Deploy a Camel Project t o a fabric profile

1. From P ro ject Expl o rer, drag the si mpl e-ro ute root project over to Fabri c

Expl o rer and drop it on Lo cal Fab ricVersio n s1.0d ef au lt karaf

f eat u re- camelf eat u re- camel- jmsexamp le- q u ickst art s- jms

myCamelRo u t e.

No t e

The Dep lo y t o ... tool provides an alternative to the drag and drop method of deployment. For details, see Deploying a Project to a Fabric Container in Red Hat

JBoss Fuse Tooling: JBoss Fuse Tooling User Guide.

C o nso l e view chronicles the process as the tooling builds the si mpl e-ro ute project, runs the tests, installs the project as a bundle in the myC amel R o ute profile, and then uploads the profile to the fabric's internal Maven repository.

2. In Fabri c Expl o rer, click the myC amel R o ute profile to populate P ro perti es view with its properties and profile information.

No t e

It can take some time for the tooling to build the project, run the tests, and install the project bundle. The simple-route bundle will appear in the FABs field on the

P ro fi l es page only when the process has finished. You can use Fabri c

Expl o rer's Ref resh button to trigger an update of the P ro fi l es page.

3. On the P ro fi l es page, check that the simple-route bundle appears in the FABs field, as shown in

Figure 7.2, “ simple-route bundle deployed”

.

Fig u re 7.2. simp le- ro u t e b u n d le d ep lo yed

4 3

Red Hat JBoss Fuse 6 .1 T ooling T ut orials

Now you can deploy your camel project to the fabric by creating one or more containers on the fabric and assigning the myC amel R o ute profile to them. Once the containers are started, you can start tracing on the deployed projects, as described in

Chapter 4, To Trace a Message Through a Route

.

Furt her reading

To learn more about deploying applications to a fabric, see in Deploying a Project to a Fabric

Container in Red Hat JBoss Fuse: Tooling User Guide on the Red Hat Customer Portal :

Deploying Projects to a Container

Working with Fabric Containers

Working with Fabric Profiles

Working with Versions

4 4

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement