Spring Integration add-on for Roo

Một phần của tài liệu Manning spring roo in action (Trang 375 - 381)

Fortunately, an add-on component exists to create and manage Spring Integration components using Roo commands without having to write the code from scratch. The Spring Integration add-on for Roo provides quick and simple configuration of Spring Integration flows.

In this chapter, we’ll look at the course registration use case that includes a work­

flow with a message queue, a data transformation step, a routing step, and a notifica­

tion step to send an email to the customer of the sample Course Manager application.

The discussion includes the new Spring Integration add-on (http://mng.bz/

VX0h), which is not yet in general release. We’ll look at how to install the add-on and then how to run Roo commands for setting up Spring Integration components like SERVICE_ACTIVATOR, ROUTER, and so on. The design philosophy of the Spring Integra­

tion add-on aligns with the enterprise application integration patterns and their implementation in enterprise applications.

343 Spring Integration add-on for Roo

Another helpful tool when you need to add the various Spring Integration compo­

nents into the application is the SpringSource Tool Suite (http://mng.bz/k0jd), or STS. This Eclipse-based IDE tool makes the job of adding different components easier, without having to configure them manually from scratch. STS also provides a good context-sensitive help feature.

Spring Integration Scala DSL1 is another new project from the Spring Integra­

tion team that makes it easy to configure Spring Integration components using a domain-specific language (DSL) approach. This project is also in the early stages of development.

The Spring Integration add-on’s current status is that of a work in progress, and at the time of this writing, it’s not in GA release. The current version’s support is not comprehensive in that the add-on doesn’t persist the Spring configuration files after issuing the Roo commands. But it does have good support for setting up the various Spring Integration components in the workflow.

We'll start this discussion by running different add-on commands to show you how to set up the Spring Integration workflow and associate the components to one another. Then you’ll create the required Spring configuration files to test the work­

flow setup. You’ll also write the Java classes needed to capture the business logic of the use case. Finally, you’ll write a JUnit test in order to test the different course reg­

istration scenarios.

The add-on also provides a focus command, similar to the Roo focus command, but it works on integration patterns rather than on Java classes.

14.4.1 How to install the Roo add-on for Spring Integration

You’ll perform the following steps to install the Spring Integration add-on:

1 Download the source from its Git repository location.

2 Compile the Java classes and package the JAR files.

3 Deploy the JAR files to the Roo runtime environment (which is based on OSGi technology).

4 After completing the installation process, you’re ready to use the Spring Inte­

gration add-on.

Let’s look at each of these steps in more detail.

GETTING THE SPRING INTEGRATION ADD-ON SOURCE CODE

Let’s first check out the add-on source code from its Git repository location to a local directory on your machine. You can use a Git client tool like SmartGit (http://

mng.bz/n5pg) to work with the Git repository, using a graphical user interface tool.

Figure 14.3 shows the SmartGit client tool window, with the SpringIntegrationRoo- Addon Git project folders (in the left pane) and files (in the right pane).

See http://blog.springsource.org/2012/03/05/introducing-spring-integration-scala-dsl/.

1

Figure 14.3 Spring Integration add-on SmartGit screenshot

Now you need to clone the project using the add-on component’s Git repository URL.2 It includes three subprojects (or Maven modules):

 spring-integration-roo-parent

 spring-integration-roo-core

 spring-integration-roo-adapter

The spring-integration-roo-parent module includes the common dependency JAR files for the other modules in the project. And the spring-integration-roo-core module contains all the Roo commands for setting up a new project, creating various Spring Integration pipeline components, and configuring each component in the workflow.

BUILD THE ADD-ON

To compile and package the add-on JAR files, run Maven clean and install com­

mands, as shown in this example:

REM First, set JAVA_HOME and MAVEN_HOME variables to point to JDK REM and Maven home directories respectively. Add these two variables REM to the PATH system environment variable.

set PROJECT_HOME=C:/dev/projects/SpringRooProjects/ ➥

SpringIntegrationRooAddon cd %PROJECT_HOME%

mvn clean install

2 See git://git.springsource.org/spring-integration/roo-addon.git.

345 Spring Integration add-on for Roo

This will create two JAR files for the core and adapter modules, which you can deploy to the Roo environment, as discussed in the next section.

DEPLOY THE ADD-ON

The Spring Integration add-on depends on the following four libraries:

 Apache Commons Logging

 Spring Core

 Spring Beans

 Spring ASM

If you try to deploy the Roo add-on without having these libraries installed first, the framework will throw the error shown in the following listing.

Listing 14.1 Error when deploying without the dependent Java libraries ERROR: Error starting file:/C:/dev/frameworks/Roo/v1.2.0/ ➥

spring-roo-1.2.0.M1/bundle ➥

spring-integration-roo-core-1.0.0.BUILD-SNAPSHOT.jar

(org.osgi.framework.BundleException: Unresolved constraint in bundle spring-integration-roo-core [71]: Unable to resolve 71.0: ➥

missing requirement [71.0] package;

(&(package=org.springframework.util)(version>=3.0.0)) ➥

[caused by: Unable to resolve 69.0:

missing requirement [69.0] package; (&(package=org.apache. ➥

commons.logging)(version>=1.1.1)

(!(version>=2.0.0)))])org.osgi.framework.BundleException: ➥

Unresolved constraint in bundle

spring-integration-roo-core [71]: Unable to resolve 71.0: ➥

missing requirement [71.0] package;

(&(package=org.springframework.util)(version>=3.0.0)) ➥

[caused by: Unable to resolve 69.0:

missing requirement [69.0] package; (&(package=org.apache. ➥

commons.logging)(version>=1.1.1) (!(version>=2.0.0)))]

You have two options to resolve this error. You can copy the required JAR files to the target folder in the PROJECT_HOME directory, or you can install these libraries using the OSGi commands. To do this, first you create a new directory under target called RooAddOnLibraries and copy the zip file contents into this new folder.

There are five JAR files under the bundles subdirectory:

 spring-asm-3.0.4.RELEASE.jar

 spring-beans-3.0.4.RELEASE.jar

 spring-core-3.0.4.RELEASE.jar

 spring-integration-roo-adapter-1.0.0.BUILD-SNAPSHOT.jar

 spring-integration-roo-core-1.0.0.BUILD-SNAPSHOT.jar

Install these JAR files to the bundle folder under Roo’s installation directory using the osgi start command for each JAR file, as shown in this example:

osgi start --url file:///C:/dev/projects/SpringRooProjects/ ➥

SpringIntegrationRooAddon/spring-integration-roo-core/ ➥

target/spring-integration-roo-core-1.0.0.BUILD-SNAPSHOT.jar osgi start --url file:///C:/dev/projects/SpringRooProjects/ ➥

SpringIntegrationRooAddon/spring-integration-roo-adapter/ ➥

target/spring-integration-roo-adapter-1.0.0.BUILD-SNAPSHOT.jar

If you need to uninstall a library, you can use the following command:

osgi uninstall --bundleSymbolicName spring-integration-roo-core

Let’s install the Apache Commons Logging library now. The OSGi version of the Com­

mons Logging JAR file can be downloaded from the SpringSource Enterprise Bundle Repository (http://mng.bz/PpyY), which hosts OSGi-ready versions of hundreds of open source enterprise libraries commonly used to develop Spring applications.

You can download the Apache Commons Logging (version 1.1.1) library (com .springsource.org.apache.commons.logging-1.1.1.jar) from the bundle reposi­

tory (http://mng.bz/ad5d).

After installing the required libraries, type the following command to view all of the installed libraries and their current status (for example, whether they’re active or not):

osgi ps

The output of this command is shown in the next listing.

Listing 14.2 osgi ps command output showing all active OSGi bundles [ 67] [Active ] [ 1] Spring ASM (3.0.4.RELEASE)

[ 68] [Active ] [ 1] Spring Beans (3.0.4.RELEASE) [ 69] [Active ] [ 1] Spring Core (3.0.4.RELEASE)

[ 70] [Active ] [ 1] Spring Integration ROO add-on ADAPTER module ➥

(1.0.0.BUILD-SNAPSHOT)

[ 71] [Active ] [ 1] Spring Integration ROO add-on CORE module ➥

(1.0.0.BUILD-SNAPSHOT)

[ 74] [Active ] [ 1] Apache Commons Logging (1.1.1)

Another way to verify that the Spring Integration add-on components are installed correctly is to use the osgi log command.

The following listing shows the output of this command.

Listing 14.3 osgi log output showing current status of OSGi bundles 2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

BundleEvent STARTED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.Converter] - ServiceEvent REGISTERED 2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.Converter] - ServiceEvent REGISTERED 2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.Converter] - ServiceEvent REGISTERED 2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.Converter] - ServiceEvent REGISTERED 2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

347 Spring Integration add-on for Roo

[org.springframework.integration.roo.addon.IntegrationOperations] ➥

- ServiceEvent REGISTERED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.CommandMarker] - Service Event REGISTERED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.roo.shell.CommandMarker] - Service Event REGISTERED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-core - ➥

[org.springframework.integration.roo.addon.IntegrationContext] - ➥

ServiceEvent REGISTERED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-adapter - ➥

BundleEvent STARTED

2011.04.19 20:24:34 INFO - Bundle: spring-integration-roo-adapter - ➥

BundleEvent RESOLVED

2011.04.19 20:24:34 INFO - Bundle: org.springframework.core - ➥

BundleEvent STARTED

2011.04.19 20:24:34 INFO - Bundle: org.springframework.beans - ➥

BundleEvent STARTED

2011.04.19 20:24:34 INFO - Bundle: org.springframework.beans - ➥

BundleEvent RESOLVED

2011.04.19 20:24:34 INFO - Bundle: org.springframework.asm - ➥

BundleEvent STARTED

So far, you’ve downloaded, compiled, packaged, and deployed the Spring Integration add-on component source code along with the libraries on which the add-on depends. Now you can start using the add-on to implement the course registration use case. Before you do that, you need to quickly verify that you successfully installed the add-on and that there were no errors during deployment.

14.4.2 Verifying the add-on installation

To verify success of the add-on installation, run the help command in the Roo com­

mand shell window. This will display all of the Spring Integration commands. The fol­

lowing listing is the partial output of this command that shows Roo’s Spring Integration commands.

Listing 14.4 Spring Integration Roo commands to verify the add-on installation

* integration flow delete - Allows you to delete an existing ➥

Integration flow

* integration flow edit - Allows you to edit an existing ➥

Integration flow

* integration flow fold - Allows you to fold an existing ➥

Integration flow to be exposed via convenient namespace support

* integration flow list - Lists available flows

* integration flow read - Allows you to read an existing ➥

Integration flow

* integration flow start - Starts the new Integration flow

* integration project - Focuses the Command Line context on the ➥

component specified

If you want context-sensitive help, you can type integration and press TAB:

roo> integration flow

integration flow read integration flow start

Note that the exact syntax of these commands may change in more recent releases of the Spring Integration add-on, because the version of the add-on component is not in GA release at the time of this writing.

Now you’re ready to use the new add-on for your use case implementation. In the next section, we’ll discuss the implementation of the course registration confirmation use case step by step using Roo commands to define and configure the Spring Integra­

tion components you need in the use case.

Một phần của tài liệu Manning spring roo in action (Trang 375 - 381)

Tải bản đầy đủ (PDF)

(406 trang)