第5章 Running Red Hat JBoss Data Grid with Apache Camel
5.1. Running Red Hat JBoss Data Grid with Apache Camel
Apache Camel is an open source integration and routing system that allows transference of messages from various sources to different destinations, providing an integration framework that allows interaction with various systems using the same API, regardless of the protocol or data type. Using Camel with Red Hat JBoss Data Grid and Red Hat JBoss Fuse simplifies integration in large enterprise applications by providing a wide variety of transports and APIs that add connectivity.
JBoss Data Grid provides support for caching on Camel routes in JBoss Fuse, partially replacing Ehcache. JBoss Data Grid is supported as an embedded cache (local or clustered) or as a remote cache in a Camel route.
5.2. The camel-jbossdatagrid Component
Red Hat JBoss Data Grid’s camel-jbossdatagrid
component includes the following features:
Local Camel Consumer
Receives cache change notifications and sends them to be processed. This can be done synchronously or asynchronously, and is also supported with a replicated or distributed cache.
Local Camel Producer
A producer creates and sends messages to an endpoint. The
camel-jbossdatagrid
producer usesGET
,PUT
,REMOVE
, andCLEAR
operations. The local producer is also supported with a replicated or distributed cache.Remote Camel Producer
In Remote Client-Server mode, the Camel producer can send messages using Hot Rod.
Remote Camel Consumer
In Client-Server mode, receives cache change notifications and sends them to be processed. The events are processed asynchronously.
The following camel-jbossdatagrid
dependency must be added to the pom.xml file to run JBoss Data Grid with Camel:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jbossdatagrid</artifactId> <version>7.0.0.ER4-redhat-1</version> <!-- use the same version as your JBoss Data Grid version --> </dependency>
The camel-jbossdatagrid
component ships with JBoss Data Grid, and is not included in the JBoss Fuse 6.1 or JBoss Fuse Service Works 6.0 distributions.
Camel components are the main extension point in Camel, and are associated with the name used in a URI, and act as a factory of endpoints. For example, a FileComponent
is referred to in a URI as file
, which creates FileEndpoints
.
URI Format
The following URI format is used for camel-jbossdatagrid
:
infinispan://hostname?[options]
URI Options
The producer can create and send messages to a local or remote JBoss Data Grid cache configured in the registry. If a cacheContainer
is present, the cache will be either local or remote, depending on whether the cacheContainer
instance is a DefaultCacheManager
or RemoteCacheManager
. If it is not present, the cache will try to connect to remote cache using the supplied hostname/port.
A consumer listens for events from the local JBoss Data Grid cache accessible from the registry.
Name | Description |
---|---|
cacheContainer |
Default Value: null Type: CacheContainer Context: Shared
Description: Reference to a |
cacheName |
Default Value: null Type: String Context: Shared Description: The cache name to use. If not specified, the default cache is used. |
command |
Default Value: PUT Type: String Context: Producer Description: The operation to perform. Only the PUT, GET, REMOVE, and CLEAR values are currently supported. |
eventTypes |
Default Value: null Type: Set<String> Context: Consumer
Description: A comma separated list of the event types to register. By default, this listens for all event types. Possible values are defined in ...?eventTypes=CACHE_ENTRY_EXPIRED,CACHE_ENTRY_EVICTED,... |
sync |
Default Value: true Type: Boolean Context: Consumer Description: By default the consumer will receive notifications synchronously by the same thread that process the cache operation. Remote HotRod listeners support only asynchronous notification. |
clustered |
Default Value: false Type: Boolean Context: Consumer
Description: By default the consumer will only receive local events. By using this option, the consumer also listens to events originated on other nodes in the cluster. The only events available for clustered listeners are |
Camel Operations
A list of all available operations, along with their header information, is found below:
Operation Name | Description |
---|---|
CamelInfinispanOperationPut |
Context: Embedded / Remote Description: Puts a key/value pair in the cache, optionally with expiration Required Headers: CamelInfinispanKey, CamelInfinispanValue Optional Headers: CamelInfinispanLifespanTime, CamelInfinispanLifespanTimeUnit, CamelInfinispanMaxIdleTime, CamelInfinispanMaxIdleTimeUnit, CamelInfinispanIgnoreReturnValues Result Header: CamelInfinispanOperationResult |
CamelInfinispanOperationPutAsync |
Description: A variation of the |
CamelInfinispanOperationPutIfAbsent |
Description: A variation of the |
CamelInfinispanOperationPutIfAbsentAsync |
Description: A variation of the |
Operation Name | Description |
---|---|
CamelInfinispanOperationPutAll |
Context: Embedded / Remote Description: Adds multiple entries to a cache, optionally with expiration Required Headers: CamelInfinispanMap Optional Headers: CamelInfinispanLifespanTime, CamelInfinispanLifespanTimeUnit, CamelInfinispanMaxIdleTime, CamelInfinispanMaxIdleTimeUnit Result Header: None |
CamelInfinispanOperationPutAllAsync |
Description: A variation of the |
Operation Name | Description |
---|---|
CamelInfinispanOperationGet |
Context: Embedded / Remote Description: Retrieves the value associated with a specific key from the cache Required Headers: CamelInfinispanKey Optional Headers: None Result Header: None |
Operation Name | Description |
---|---|
CamelInfinispanOperationContainsKey |
Context: Embedded / Remote Description: Determines whether a cache contains a specific key Required Headers: CamelInfinispanKey Optional Headers: None Result Header: CamelInfinispanOperationResult |
Operation Name | Description |
---|---|
CamelInfinispanOperationContainsValue |
Context: Embedded / Remote Description: Determines whether a cache contains a specific value Required Headers: CamelInfinispanKey Optional Headers: None Result Headers: None |
Operation Name | Description |
---|---|
CamelInfinispanOperationRemove |
Context: Embedded / Remote Description: Removes an entry from a cache, optionally only if the value matches a given one Required Headers: CamelInfinispanKey Optional Headers: CamelInfinispanValue Result Header: CamelInfinispanOperationResult |
CamelInfinispanOperationRemoveAsync |
Description: A variation of the |
Operation Name | Description |
---|---|
CamelInfinispanOperationReplace |
Context: Embedded / Remote Description: Conditionally replaces an entry in the cache, optionally with expiration Required Headers: CamelInfinispanKey, CamelInfinispanValue, CamelInfinispanOldValue Optional Headers: CamelInfinispanLifespanTime, CamelInfinispanLifespanTimeUnit, CamelInfinispanMaxIdleTime, CamelInfinispanMaxIdleTimeUnit, CamelInfinispanIgnoreReturnValues Result Header: CamelInfinispanOperationResult |
CamelInfinispanOperationReplaceAsync |
Description: A variation of the |
Operation Name | Description |
---|---|
CamelInfinispanOperationClear |
Context: Embedded / Remote Description: Clears the cache Required Headers: None Optional Headers: None Result Header: None |
Operation Name | Description |
---|---|
CamelInfinispanOperationSize |
Context: Embedded / Remote Description: Returns the number of entries in the cache Required Headers: None Optional Headers: None Result Header: CamelInfinispanOperationResult |
Operation Name | Description |
---|---|
CamelInfinispanOperationQuery |
Context: Remote Description: Executes a query on the cache Required Headers: CamelInfinispanQueryBuilder Optional Headers: None Result Header: CamelInfinispanOperationResult |
Any operations that take CamelInfinispanIgnoreReturnValues
will receive a null result.
Name | Description |
---|---|
CamelInfinispanCacheName |
Default Value: null Type: String Context: Shared Description: The cache participating in the operation or event. |
CamelInfinispanMap |
Default Value: null Type: Map Context: Producer
Description: A Map to use in case of the |
CamelInfinispanKey |
Default Value: null Type: Object Context: Shared Description: The key to perform the operation to or the key generating the event. |
CamelInfinispanValue |
Default Value: null Type: Object Context: Producer Description: The value to use for the operation. |
CamelInfinispanOperationResult |
Default Value: null Type: Object Context: Producer Description: The result of the operation. |
CamelInfinispanEventType |
Default Value: null Type: String Context: Consumer
Description: For local cache listeners (non-clustered), one of the following values:
For remote HotRod listeners, one of the following values: |
CamelInfinispanIsPre |
Default Value: null Type: Boolean Context: Consumer Description: Infinispan fires two events for each operation when local non-clustered listener is used: one before and one after the operation. For clustered listeners and remote HotRod listeners, Infinispan fires only one event after the operation. |
CamelInfinispanQueryBuilder |
Default Value: null Type: InfinispanQueryBuilder Context: Producer
Description: An instance of |
CamelInfinispanLifespanTime |
Default Value: null Type: long Context: Producer Description: The Lifespan time of a value inside the cache. Negative values are interpreted as infinity. |
CamelInfinispanTimeUnit |
Default Value: null Type: String Context: Producer Description: The Time Unit of an entry Lifespan Time. |
CamelInfinispanMaxIdleTime |
Default Value: null Type: long Context: Producer Description: The maximum amount of time an entry is allowed to be idle for before it is considered as expired. |
CamelInfinispanMaxIdleTimeUnit |
Default Value: null Type: String Context: Producer Description: The Time Unit of an entry Max Idle Time. |
5.3. Routing with Camel in JBoss Data Grid
Camel routing is a chain of processors that move messages in the background. The following is an example of a route that retrieves a value from the cache for a specific key.
from("direct:start") .setHeader(InfinispanConstants.OPERATION, constant(InfinispanConstants.GET)) .setHeader(InfinispanConstants.KEY, constant("123")) .to("infinispan://localhost?cacheContainer=#cacheContainer");
Routing can also be performed using XML configuration. The following example demonstrates camel-jbossdatagrid’s local-camel-producer
, a camel route that uses the camel-jbossdatagrid
component to send data to an embedded cache created by the local-cache
module.
<camelContext id="local-producer" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="timer://local?fixedRate=true&period=5000"/> <setHeader headerName="CamelInfinispanKey"> <constant>CamelTimerCounter</constant> </setHeader> <setHeader headerName="CamelInfinispanValue"> <constant>CamelTimerCounter</constant> </setHeader> <to uri="infinispan://foo?cacheContainer=#cacheManager"/> <to uri="log:local-put?showAll=true"/> </route> </camelContext>
The provided example requires the cacheManager
to be instantiated.
The cacheManager
bean for Spring XML can be instantiated as follows:
<bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager" init-method="start" destroy-method="stop"> <constructor-arg type="java.lang.String" value="infinispan.xml"/> </bean>
The following demonstrates how to instantiate the cacheManager
bean using Blueprint XML.
<bean id="cacheManager" class="org.infinispan.manager.DefaultCacheManager" init-method="start" destroy-method="stop"> <argument value="infinispan.xml" /> </bean>
Both the Spring XML and Blueprint XML examples use the configuration file infinispan.xml for configuration of the cache. This file must be present on the classpath.
5.4. Remote Query
When executing remote queries the cacheManager must be an instance of RemoteCacheManager
, and an example configuration utilizing a RemoteCacheManager
is found below for both Java and blueprint.xml:
例5.1 Using only Java
from("direct:start") .setHeader(InfinispanConstants.OPERATION, InfinispanConstants.QUERY) .setHeader(InfinispanConstants.QUERY_BUILDER, new InfinispanQueryBuilder() { public Query build(QueryFactory<Query> queryFactory) { return queryFactory.from(User.class).having("name").like("%abc%") .build(); } }) .to("infinispan://localhost?cacheContainer=#cacheManager&cacheName=remote_query_cache") ;
例5.2 Using Blueprint and Java
Java RemoteCacheManagerFactory
class:
public class RemoteCacheManagerFactory { ConfigurationBuilder clientBuilder; public RemoteCacheManagerFactory(String hostname, int port) { clientBuilder = new ConfigurationBuilder(); clientBuilder.addServer() .host(hostname).port(port); } public RemoteCacheManager newRemoteCacheManager() { return new RemoteCacheManager(clientBuilder.build()); } }
Java InfinispanQueryExample
class:
public class InfinispanQueryExample { public InfinispanQueryBuilder getBuilder() { return new InfinispanQueryBuilder() { public Query build(QueryFactory<Query> queryFactory) { return queryFactory.from(User.class) .having("name") .like("%abc%") .build(); } } } }
blueprint.xml:
<bean id=”remoteCacheManagerFactory” class=“com.jboss.datagrid.RemoteCacheManagerFactory”> <argument value=”localhost”/> <argument value="11222”/> </bean> <bean id=”cacheManager” factory-ref=”remoteCacheManagerFactory” factory-method=“newRemoteCacheManager”> </bean> <bean id="queryBuilder" class="org.example.com.InfinispanQueryExample"/> <camelContext id="route" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:start"/> <setHeader headerName="CamelInfinispanOperation"> <constant>CamelInfinispanOperationQuery</constant> </setHeader> <setHeader headerName="CamelInfinispanQueryBuilder"> <method ref="queryBuilder" method="getBuilder"/> </setHeader> <to uri="infinispan://localhost?cacheContainer=#cacheManager&cacheName=remote_query_cache"/> </route> </camelContext>
The remote_query_cache
is an arbitrary name for a cache that holds the data, and the results of the query will be a list of domain objects stored as a CamelInfinispanOperationResult
header.
In addition, there are the following requirements:
-
The
RemoteCacheManager
must be configured to useProtoStreamMarshaller
. -
The
ProtoStreamMarshaller
must be registered with theRemoteCacheManager
's serialization context. - The .proto descriptors for domain objects must be registered with the remote JBoss Data Grid server.
For more details on how to setup a RemoteCacheManager
, see the Remote Querying
section of the Red Hat JBoss Data Grid Infinispan Query Guide .
5.5. Custom Listeners for Embedded Cache
Custom Listeners for an embedded cache can be registered through the customListener
parameter as shown below:
Using Java
from("infinispan://?cacheContainer=#myCustomContainer&cacheName=customCacheName&customListener=#myCustomListener") .to("mock:result");
Using Blueprint
<bean id="myCustomContainer" org.infinispan.manager.DefaultCacheManager" init-method="start" destroy-method="stop"> <argument value="infinispan.xml" /> </bean> <bean id="myCustomListener" class="org.example.com.CustomListener"/> <camelContext id="route" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="infinispan://?cacheContainer=#myCustomContainer&cacheName=customCacheName&customListener=#myCustomListener"/> <to uri="mock:result"/> </route> </camelContext>
The instance of myCustomListener
must exist. Users are encouraged to extend the org.apache.camel.component.infinispan.embedded.InfinispanEmbeddedCustomListener
and annotate the resulting class with the @Listener
annotation from org.infinispan.notifications .
Custom filters and converters for embedded caches are currently not supported.
5.6. Custom Listeners for Remote Cache
Custom listeners for a remote cache can be registered in the same way as an embedded cache, with the exception that sync=false
must be present. For instance:
例5.3 Using only Java
from(infinispan://?cacheContainer=#cacheManager&sync=false&customListener=#myCustomListener") .to(mock:result);
例5.4 Using Blueprint and Java
Java class:
public class RemoteCacheManagerFactory { ConfigurationBuilder clientBuilder; public RemoteCacheManagerFactory(String hostname, int port) { clientBuilder = new ConfigurationBuilder(); clientBuilder.addServer() .host(hostname).port(port); } public RemoteCacheManager newRemoteCacheManager() { return new RemoteCacheManager(clientBuilder.build()); } }
blueprint.xml:
<bean id=”remoteCacheManagerFactory” class=“com.jboss.datagrid.RemoteCacheManagerFactory”> <argument value=”localhost”/> <argument value="11222”/> </bean> <bean id=”cacheManager” factory-ref=”remoteCacheManagerFactory” factory-method=“newRemoteCacheManager”> </bean> <bean id="myCustomListener" class="org.example.com.CustomListener"/> <camelContext id="route" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="infinispan://?cacheContainer=#cacheManager&sync=false&customListener=#myCustomListener"/> <to uri="mock:result"/> </route> </camelContext>
The instance of myCustomListener
must exist. Users are encouraged to extend the org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener
class and annotate the resulting class with @ClientListener
; this annotation is found in org.infinispan.client.hotrod.annotation .
Remote listeners may also be associated with custom filters and converters as shown below:
@ClientListener(includeCurrentState=true, filterFactoryName = "static-filter-factory", converterFactoryName = "static-converter-factory") private static class MyCustomListener extends InfinispanRemoteCustomListener { }
In order to use custom filters or converters classes annotated with @NamedFactory
must be implemented. A skeleton that implements the necessary methods is shown below:
import org.infinispan.notifications.cachelistener.filter; @NamedFactory(name = "static-converter-factory") public static class StaticConverterFactory implements CacheEventConverterFactory { @Override public CacheEventConverter<Integer, String, CustomEvent> getConverter(Object[] params) { ... } static class StaticConverter implements CacheEventConverter<Integer, String, CustomEvent>, Serializable { @Override public CustomEvent convert(Integer key, String previousValue, Metadata previousMetadata, String value, Metadata metadata, EventType eventType) { ... } } } @NamedFactory(name = "static-filter-factory") public static class StaticCacheEventFilterFactory implements CacheEventFilterFactory { @Override public CacheEventFilter<Integer, String> getFilter(final Object[] params) { ... } static class StaticCacheEventFilter implements CacheEventFilter<Integer, String>, Serializable { @Override public boolean accept(Integer key, String previousValue, Metadata previousMetadata, String value, Metadata metadata, EventType eventType) { ... } } }
Custom filters and converters must be registered with the server. Registering these classes is documented in the Remote Event Listeners
section of the Red Hat JBoss Data Grid Developer Guide .
In order to listen for remote HotRod events the cacheManager must be of type RemoteCacheManager
and instantiated.
5.7. Red Hat JBoss Data Grid and Red Hat JBoss Fuse
5.7.1. Installing camel-jbossdatagrid for Red Hat JBoss Fuse
Red Hat JBoss Fuse is an OSGi container based on the Karaf container. To run Red Hat JBoss Data Grid and JBoss Fuse using camel-jbossdatagrid
, ensure that both JBoss Data Grid 7.1 Beta and JBoss Fuse 6.1 (Full Installation) are installed.
Installing JBoss Data Grid
For information about installing JBoss Data Grid, see Download and Install Red Hat JBoss Data Grid . Only the following JBoss Data Grid components are required to run the camel component in JBoss Fuse: * JBoss Data Grid Maven repository. * The JBoss Data Grid Server package (to use the Hot Rod client).
The camel-jbossdatagrid
library is also available in a separate distribution called jboss-datagrid-7.1.0-camel-library
Installing JBoss Fuse
Before attempting to install and use Red Hat JBoss Fuse, ensure your system meets the minimum requirements. For supported Platforms and recommended Java Runtime platforms, see the Red Hat JBoss Fuse Installation Guide
The following hardware is required for the JBoss Fuse 6.1 Full Installation:
- 700 MB of free disk space
- 2 GB of RAM
In addition to the disk space required for the base installation, a running system will require space for caching, persistent message stores, and other functions.
Download the JBoss Fuse Full Installation
You can download the Red Hat JBoss Fuse archive from the Red Hat Customer Portal>Downloads>Red Hat JBoss Middleware>Downloads page, after you register and login to your customer account.
When logged in:
- Select Fuse , listed under Integrated Platforms in the sidebar menu.
- Select 6.1.0 from the Version drop-down list on the Software Downloads page.
- Click the Download button next to the Red Hat JBoss Fuse 6.1.0 distribution file to download.
JBoss Fuse allows you to choose between installations that contain different feature sets. To run JBoss Data Grid with JBoss Fuse, the Full installation is required. The Full installation includes the following:
- Apache Karaf
- Apache Camel
- Apache ActiveAMQ
- Apache CXF
- Fuse Management
- Console (hawtio)
- JBI components
Unpacking the Archive
Red Hat JBoss Fuse is installed by unpacking an archive on a system. JBoss Fuse is packaged as a zip file. Using a suitable archive tool, unpack Red Hat JBoss Fuse into a directory to which you have full access.
警告Do not unpack the archive file into a folder that has spaces in its path name. For example, do not unpack into C:\Documents and Settings\Greco Roman\Desktop\fusesrc.
Additionally, do not unpack the archive file into a folder that has any of the following special characters in its path name: #, %, ^, ".
Adding a Remote Console User
The server’s remote command console is not configured with a default user. Before remotely connecting to the server’s console, add a user to the configuration.
重要The information in this file is unencrypted so it is not suitable for environments that require strict security.
To add a user:
- Open InstallDir/etc/users.properties in your favorite text editor.
-
Locate the line
#admin=admin,admin
. This line specifies a useradmin
with the passwordadmin
and the roleadmin
. - Remove the leading # to uncomment the line.
-
Replace the first
admin
with a name for the user. -
Replace the second
admin
with the password for the user. -
Leave the last
admin
as it is, and save the changes.
注記To access the Fuse Management Console to monitor and manage your Camel routes, ActiveMQ brokers, Web applications, and so on, open a browser to , after starting Red Hat JBoss Fuse.
Red Hat JBoss Fuse Maven Repositories
To use Maven to build projects, specify the location of the artifacts in a Maven settings.xml file.
The following JBoss Fuse Maven repository contains the required dependencies for Camel and must be added to the settings.xml file.
https://repo.fusesource.com/nexus/content/groups/public/
The JBoss Fuse repository runs alongside the JBoss Data Grid repository.
JBoss Data Grid includes a features.xml file for Karaf that deploys all artifacts required for the
camel-jbossdatagrid
component. This file is not included in the JBoss Fuse container distribution. The features.xml file is in jboss-datagrid-7.1.0-maven-repository/org/apache/camel/camel-jbossdatagrid/${version}/ . No further configuration of the JBoss Data Grid repository is required.For more information about installing and getting started with JBoss Fuse, see the Red Hat JBoss Fuse documentation on the Red Hat Customer Portal.
5.8. Red Hat JBoss Data Grid and Red Hat JBoss EAP
5.8.1. Installing camel-jbossdatagrid for Red Hat JBoss Enterprise Application Platform
Red Hat JBoss Enterprise Application Platform 7 (JBoss EAP 7) is a middleware platform built on open standards and compliant with the Java Enterprise Edition 8 specification.
As Camel is only supported through Red Hat JBoss Fuse valid entitlements for all of the following products will be necessary:
- Red Hat JBoss EAP
- Red Hat JBoss Fuse
- Red Hat JBoss Data Grid
Entitlement to Red Hat JBoss Fuse Service Works includes entitlements to Red Hat JBoss EAP and Red Hat JBoss Fuse.
The following variables are used instead of specific version numbers in the installation procedures below:
-
jdg.version
- the latest version of Red Hat JBoss Data Grid -
fuse.version
- the latest version of Red Hat JBoss Fuse -
infinispan.version
- the version of Infinispan that is included in the latest version of Red Hat JBoss Data Grid camel.version
- the version of Apache Camel that is included in the latest version of Red Hat JBoss FuseFor more information on tested integrations for ``camel-jbossdatagrid``, please refer to https://access.redhat.com/articles/115883.
Procedure: Installing JBoss Data Grid
For information about installing JBoss Data Grid, see Download and Install Red Hat JBoss Data Grid . Only the following JBoss Data Grid components are required to run the camel component in JBoss EAP: * JBoss Data Grid Maven repository. * The JBoss Data Grid Server package (to use the Hot Rod client).
The camel-jbossdatagrid
library is also available in a separate distribution called jboss-datagrid-${jdg.version}-camel-library .
Installing JBoss EAP
Before attempting to install and use Red Hat JBoss EAP ensure your system meets the minimum requirements as documented in Red Hat JBoss EAP Installation Guide.
Unpacking the Archive
Red Hat JBoss EAP is installed by unpacking an archive on a system, as JBoss EAP is packaged as a zip file; using a suitable archive tool, unpack Red Hat JBoss EAP into a directory to which you have full access.
警告Do not unpack the archive file into a folder that has spaces in its path name. For example, do not unpack into C:\Documents and Settings\Greco Roman\Desktop\JBoss.
Additionally, do not unpack the archive file into a folder that has any of the following special characters in its path name: #, %, ^, ".
- Once the archive has been extracted JBoss EAP will have been successfully installed. For more information on installation options refer to the appropriate section, based on how JBoss EAP was installed, under Red Hat JBoss EAP Installation Guide.
- If JBoss Data Grid is being used in Library mode then refer to Deploy JBoss Data Grid in JBoss EAP (Library Mode) to ensure the necessary dependencies have been installed.
- If JBoss Data Grid is being used in Remote Client-Server mode then refer to Deploy JBoss Data Grid in JBoss EAP (Remote Client-Server Mode) to ensure the necessary dependencies have been installed.
5.8.2. Deploy Camel with EAP
5.8.2.1. Add development and runtime dependencies
In order to compile your application the dependent libraries for Camel and JBoss Data Grid will have to be added to the pom.xml
(if using Maven).
Add Camel from Fuse
Ensure that the Fuse repository has been added to the
pom.xml
:<repository> <id>fusesource</id> <name>FuseSource Release Repository</name> <url>https://repo.fusesource.com/nexus/content/groups/public/</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository>
Add the Camel components as a dependency in the
pom.xml
:<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>${camel.version}</version> </dependency>
Add camel-jbossdatagrid to the deployment.
- Follow the instructions in Install and Use the Maven Repositories to add the maven repository.
Add camel-jbossdatagrid as a dependency in the
pom.xml
:<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jbossdatagrid</artifactId> <version>${jdg.version}</version> </dependency>
Add in the remaining JBoss Data Grid dependencies depending on which functionality is in use:
<!-- If Remote Camel Producer is used add the following dependency --> <dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-remote</artifactId> <version>${infinispan.version}</version> </dependency> <!-- If the Local Camel Producer or Local Camel Consumer are in use add --> <!-- the following dependency --> <dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-embedded</artifactId> <version>${infinispan.version}</version> </dependency>
5.8.2.2. Optionally: Add runtime dependencies as a JBoss EAP Module
Sometimes it is preferable to maintain other product libraries in JBoss EAP as modules. This requires some additional procedures to create these modules.
When using modules for dependencies the pom.xml
will need to have the scope
set to "provided" for any dependencies provided as modules. For example:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jbossdatagrid</artifactId> <scope>provided</scope> <version>${jdg.version}</version> </dependency>
Download jboss-datagrid-${jdg.version}-camel-library.zip
from the customer portal.
Extract the apache-camel-${camel.version}.zip
found in Red Hat JBoss Fuse’s extras/
directory:
user@example modules] unzip /path/to/jboss-fuse-${fuse.version}/extras/apache-camel-${camel.version}
Add in the Camel components from JBoss Fuse
Create a directory under $EAP_HOME/modules:
user@example jboss-eap-7.0] cd modules user@example modules] mkdir -p org/apache/camel/core
Create a
main
subdirectory to store the jars:user@example modules] mkdir org/apache/camel/core/main
Copy over the camel-core jar from
apache-camel-${camel.version}.zip
to the newly createdmain
directory:user@example modules] cp /path/to/jboss/fuse/extras/apache-camel-${camel.version}/lib/camel-core-${camel.version}.jar ./org/apache/camel/core/main/
Create the
module.xml
descriptor by adding in the following text toorg/apache/camel/core/main/module.xml
:<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.apache.camel.core"> <resources> <resource-root path="camel-core-${camel.version}.jar"/> </resources> </module>
- Repeat the above steps to create a module for each dependency in use; note that modules may have dependencies on other modules as described in the Red Hat JBoss Administration and Configuration Guide .
Add in Camel components from JBoss Data Grid.
Create a
main
subdirectory for the JDG Camel components:user@example jboss-eap-7.0] mkdir -p modules/org/apache/camel/main
-
Unzip
jboss-datagrid-${jdg.version}-camel-library.zip
. Copy
camel-jbossdatagrid-${jdg.version}.jar
into the newly created directory:user@example jboss-eap-7.0] cp jboss-datagrid-${jdg.version}-camel-library/camel-jbossdatagrid-${jdg.version}.jar modules/org/apache/camel/main/
Create a
module.xml
descriptor by adding in the following text toorg/apache/camel/main/module.xml
:<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.apache.camel"> <resources> <resource-root path="camel-jbossdatagrid-${jdg.version}.jar"/> </resources> <dependencies> <module name="org.apache.camel.core" /> </dependencies> </module>
Create a jboss-deployment-structure.xml
in the WEB-INF
of the war, and add dependencies on the newly created module:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <dependencies> <module name="org.apache.camel" meta-inf="import"/> <!-- Add the following lines if Library mode is used --> <module name="org.infinispan" slot="jdg-7.1" /> <module name="org.jgroups" slot="jdg-7.1" /> <!-- Add the following lines if Remote Client-Server mode is used --> <module name="org.infinispan.client.hotrod" slot="jdg-7.1" /> </dependencies> </deployment> </jboss-deployment-structure>