Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Deploying into JBoss EAP
Deploying application packages into the JBoss Enterprise Application Platform (EAP) container
Abstract
Chapter 1. Overview of JBoss Fuse on JBoss EAP Deployment Link kopierenLink in die Zwischenablage kopiert!
You can deploy Fuse applications on Red Hat JBoss Enterprise Application Platform (JBoss EAP), after installing the Fuse on EAP package into the JBoss EAP container.
This part describes the deployment model using the Camel on EAP subsystem. Apache Camel in Fuse enables you to select the container to run an integrated application.
Fuse on JBoss EAP is not supported with Domain mode.
Red Hat JBoss EAP features a range of application deployment and configuration options to cater both administrators and developers. For more information about JBOSS EAP configuration and the deployment process, refer Red Hat JBoss EAP Configuration Guide.
1.1. Supported Product Versions Link kopierenLink in die Zwischenablage kopiert!
To see the latest version of JBoss EAP that supports Fuse 7.3, refer to the Supported Configurations page.
1.2. Camel on EAP Subsystem Link kopierenLink in die Zwischenablage kopiert!
The Camel on EAP subsystem integrates Apache Camel directly into the JBoss EAP container. This subsystem is available after you install the Fuse on EAP package into the JBoss EAP container. It offers many advantages for Camel deployment, including simplified deployment of Camel components and tighter integration with the underlying JBoss EAP container.
Red Hat recommends you to use the Camel on EAP Subsystem deployment model for deployment of Apache Camel applications on JBoss EAP.
Chapter 2. Building Your Application on JBoss EAP Link kopierenLink in die Zwischenablage kopiert!
2.1. Overview Link kopierenLink in die Zwischenablage kopiert!
The following example demonstrates the use of camel-cdi component with Red Hat Fuse on EAP to integrate CDI beans with Camel routes.
In this example, a Camel route takes a message payload from a servlet HTTP GET request and passes it on to a direct endpoint. It then passes the payload onto a Camel CDI bean invocation to produce a message response and displays the output on the web browser page.
2.2. Running the Project Link kopierenLink in die Zwischenablage kopiert!
Before running the project, ensure that your set up includes maven and the application server with Red Hat Fuse. Perform the following steps to run your project:
Start the application server in standalone mode:
-
For Linux:
${JBOSS_HOME}/bin/standalone.sh -c standalone-full.xml -
For Windows:
%JBOSS_HOME%\bin\standalone.bat -c standalone-full.xml
-
For Linux:
-
Build and deploy the project:
mvn install -Pdeploy -
Now, browse to
http://localhost:8080/example-camel-cdi/?name=Worldlocation. The following messageHello World from 127.0.0.1appears as an output on the web page. Also, you can view the Camel Route under theMyRouteBuilder.javaclass as:
from("direct:start").bean("helloBean");
from("direct:start").bean("helloBean");
The bean DSL makes Camel look for a bean named helloBean in the bean registry. Also, the bean is available to Camel due to the SomeBean class. By using the @Named annotation, the camel-cdi adds the bean to the Camel bean registry.
For more information, see $ EAP_HOME/quickstarts/camel/camel-cdi directory.
2.3. BOM file for JBoss EAP Link kopierenLink in die Zwischenablage kopiert!
The purpose of a Maven Bill of Materials (BOM) file is to provide a curated set of Maven dependency versions that work well together, saving you from having to define versions individually for every Maven artifact.
The Fuse BOM for JBoss EAP offers the following advantages:
- Defines versions for Maven dependencies, so that you do not need to specify the version when you add a dependency to your POM.
- Defines a set of curated dependencies that are fully tested and supported for a specific version of Fuse.
- Simplifies upgrades of Fuse.
Only the set of dependencies defined by a Fuse BOM are supported by Red Hat.
To incorporate a BOM file into your Maven project, specify a dependencyManagement element in your project’s pom.xml file (or, possibly, in a parent POM file), as shown in the following example:
After specifying the BOM using the dependency management mechanism, it becomes possible to add Maven dependencies to your POM without specifying the version of the artifact. For example, to add a dependency for the camel-velocity component, you would add the following XML fragment to the dependencies element in your POM:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-velocity</artifactId> <scope>provided</scope> </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-velocity</artifactId>
<scope>provided</scope>
</dependency>
Note how the version element is omitted from this dependency definition.
Chapter 3. Features Link kopierenLink in die Zwischenablage kopiert!
This chapter provides the necessary information about Camel on EAP features.
Camel Context Definitions
To configure camel contexts as a part of the subsystem definition, perform the following in the standalone.xml file:
Camel Context Deployments
You can deploy camel contexts to JBoss EAP with a -camel-context.xml suffix as:
- a standalone XML file
- a part of another supported deployment
A deployment may contain multiple -camel-context.xml files.
A deployed Camel context is CDI injectable like this
@Resource(name = "java:jboss/camel/context/mycontext") CamelContext camelContext; [discrete] ### Management Console
@Resource(name = "java:jboss/camel/context/mycontext")
CamelContext camelContext;
[discrete]
### Management Console
By default, access to management consoles is secured. Therefore, you need to setup a Management User first.
bin/add-user.sh
$ bin/add-user.sh
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
The Hawt.io console should show the camel context from subsystem configuration.
Arquillian Test Support
The Camel on EAP test suite uses the WildFly Arquillian managed container. This can connect to an already running JBoss EAP instance or alternatively start up a standalone server instance when needed.
A number of test enrichers have been implemented that allow you to have these Camel on EAP specific types injected into your Arquillian test cases.
@ArquillianResource CamelContextFactory contextFactory; @ArquillianResource CamelContextRegistry contextRegistry;
@ArquillianResource
CamelContextFactory contextFactory;
@ArquillianResource
CamelContextRegistry contextRegistry;
Chapter 4. Configuration Link kopierenLink in die Zwischenablage kopiert!
This chapter provides the necessary information about the Camel Subsystem and Deployment Configuration.
Camel Subsystem Configuration
The Camel Subsystem Configuration may contain static system routes. However, the system starts the route automatically.
Camel Deployment Configuration
If you want to modify the default configuration of your Camel deployment, you can edit either the WEB-INF/jboss-all.xml or META-INF/jboss-all.xml configuration file in your deployment.
Use a <jboss-camel> XML element within the jboss-all.xml file to control the camel configuration.
Disabling the Camel Subsystem
If you do not want to add the camel subsystem into your deployment, set the enabled="false" attribute on the jboss-camel XML element.
Example jboss-all.xml file:
<jboss umlns="urn:jboss:1.0"> <jboss-camel xmlns="urn:jboss:jboss-camel:1.0" enabled="false"/> </jboss>
<jboss umlns="urn:jboss:1.0">
<jboss-camel xmlns="urn:jboss:jboss-camel:1.0" enabled="false"/>
</jboss>
Selecting Components
If you add nested <component> or <component-module> XML elements, then instead of adding the default list of Camel components to your deployment, only the specified components will be added to your deployment.
Example jboss-all.xml file:
Chapter 5. JavaEE Integration Link kopierenLink in die Zwischenablage kopiert!
This chapter provides the necessary information about the integration points with JavaEE.
5.1. CDI Link kopierenLink in die Zwischenablage kopiert!
The Camel CDI component provides an auto-configuration for Apache Camel, using CDI as dependency injection framework. However, it is based on convention-over-configuration. It implements the standard camel bean integration so that you can use the Camel annotations easily in CDI beans.
For more information about CDI, refer to the cdi documentation.
The following example describes how you can consume and assosciate the Camel Context with a route.
@Inject
@ContextName("cdi-context")
private CamelContext camelctx;
@Inject
@ContextName("cdi-context")
private CamelContext camelctx;
5.1.1. Importing XML DSL configuration Link kopierenLink in die Zwischenablage kopiert!
Camel CDI integration enables you to import existing XML DSL files via the @ImportResource annotation:
@ImportResource("camel-context.xml")
class MyBean {
}
@ImportResource("camel-context.xml")
class MyBean {
}
The location of the imported file must be present on the deployment classpath. Placing the file into locations such as WEB-INF will not work. However, WEB-INF/classes will work fine.
5.2. EJB Link kopierenLink in die Zwischenablage kopiert!
Management support is provided through the ejb component which integrates with the EJB3 subsystem.
5.3. JAXB Link kopierenLink in die Zwischenablage kopiert!
JAXB support is provided through the Camel JAXB data format.
Camel supports unmarshalling XML data to JAXB annotated classes and marshalling from classes to XML. The following demonstrates a simple Camel route for marshalling and unmarshalling with the Camel JAXB data format class.
5.3.1. JAXB Annotated class Link kopierenLink in die Zwischenablage kopiert!
5.3.2. JAXB Class XML representation Link kopierenLink in die Zwischenablage kopiert!
<customer xmlns="http://org/wildfly/test/jaxb/model/Customer">
<firstName>John</firstName>
<lastName>Doe</lastName>
</customer>
<customer xmlns="http://org/wildfly/test/jaxb/model/Customer">
<firstName>John</firstName>
<lastName>Doe</lastName>
</customer>
5.3.3. Camel JAXB Unmarshalling Link kopierenLink in die Zwischenablage kopiert!
5.3.4. Camel JAXB Marshalling Link kopierenLink in die Zwischenablage kopiert!
5.4. JAX-RS Link kopierenLink in die Zwischenablage kopiert!
JAX-RS support is provided by Camel CXF-RS.
5.4.1. CXF-RS Producer Link kopierenLink in die Zwischenablage kopiert!
5.4.2. CXF-RS Consumer Link kopierenLink in die Zwischenablage kopiert!
5.4.3. JAX-RS Consumer with the Camel REST DSL Link kopierenLink in die Zwischenablage kopiert!
The Camel REST DSL gives the capability to write Camel routes that act as JAX-RS consumers. The following RouteBuilder class demonstrates this.
By setting the binding mode, Camel can marshal and unmarshal JSON data either by specifying a 'produces()' or 'type()' configuration step.
-
The REST DSL configuration starts with
restConfiguration().component("undertow"). - The Camel on EAP Subsystem only supports the camel-servlet and camel-undertow components for use with the REST DSL. However, it does not work if you configure the other components.
5.4.4. Security Link kopierenLink in die Zwischenablage kopiert!
Refer to the JAX-RS security section.
5.4.5. Quickstart examples in Fuse on EAP Link kopierenLink in die Zwischenablage kopiert!
A quickstart example is available in your Fuse on EAP installation at quickstarts/camel/camel-cxf-jaxrs directory.
5.5. JAX-WS Link kopierenLink in die Zwischenablage kopiert!
WebService support is provided through the CXF component which integrates with the JBoss EAP WebServices subsystem that also uses Apache CXF.
5.5.1. JAX-WS CXF Producer Link kopierenLink in die Zwischenablage kopiert!
The following code example uses CXF to consume a web service which has been deployed by the WildFly web services subsystem.
5.5.1.1. JAX-WS web service Link kopierenLink in die Zwischenablage kopiert!
The following simple web service has a simple 'greet' method which will concatenate two string arguments together and return them.
When the JBoss EAP web service subsystem detects classes containing JAX-WS annotations, it bootstraps a CXF endpoint. In this example the service endpoint will be located at http://hostname:port/context-root/greeting.
5.5.1.2. Camel route configuration Link kopierenLink in die Zwischenablage kopiert!
This RouteBuilder configures a CXF producer endpoint which will consume the 'greeting' web service defined above. CDI in conjunction with the camel-cdi component is used to bootstrap the RouteBuilder and CamelContext.
The greeting web service 'greet' requires two parameters. These can be supplied to the above route by way of a ProducerTemplate. The web service method argument values are configured by constructing an object array which is passed as the exchange body.
5.5.2. Camel CXF JAX-WS Consumer Link kopierenLink in die Zwischenablage kopiert!
5.5.3. Security Link kopierenLink in die Zwischenablage kopiert!
Refer to the JAX-WS security section.
5.5.4. Quickstart examples in Fuse on EAP Link kopierenLink in die Zwischenablage kopiert!
A quickstart example is available in your Fuse on EAP installation at quickstarts/camel/camel-cxf-jaxws directory.
5.6. JMS Link kopierenLink in die Zwischenablage kopiert!
Messaging support is provided through the JMS component which integrates with the JBoss EAP Messaging (ActiveMQ Artemis) subsystem.
Integration with other JMS implementations is possible through configuration of vendor specific resource adapters, or if not available, by using the JBoss Generic JMS resource adapter.
5.6.1. JBoss EAP JMS configuration Link kopierenLink in die Zwischenablage kopiert!
You can configure the JBoss EAP messaging subsystem through the standard JBoss EAP XML configuration files. For example, standalone.xml file.
For the examples, that follow you use the embedded ActiveMQ Artemis in memory instance. You first configure a new JMS queue on the messaging subsystem by adding the following XML configuration to the jms-destinations section.
<jms-queue name="WildFlyCamelQueue"> <entry name="java:/jms/queue/WildFlyCamelQueue"/> </jms-queue>
<jms-queue name="WildFlyCamelQueue">
<entry name="java:/jms/queue/WildFlyCamelQueue"/>
</jms-queue>
Alternatively you could use a CLI script to add the queue.
jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
$ jms-queue add --queue-address=WildFlyCamelQueue --entries=queue/WildFlyCamelQueue,java:/jms/queue/WildFlyCamelQueue
Also, you can create a messaging-deployment configuration within a custom jms.xml deployment descriptor. See section 'Deployment of -jms.xml files' within the JBoss EAP messaging subsystem documentation for more information.
5.6.2. Camel route configuration Link kopierenLink in die Zwischenablage kopiert!
The following JMS producer and consumer examples make use of JBoss EAP’s embedded ActiveMQ Artemis server to publish and consume messages to and from destinations.
The examples also use CDI in conjunction with the camel-cdi component. JMS ConnectionFactory instances are injected into the Camel RouteBuilder through JNDI lookups.
5.6.2.1. JMS Producer Link kopierenLink in die Zwischenablage kopiert!
The DefaultJMSConnectionFactory connection factory is injected into the RouteBuilder from JNDI. Under the JBoss EAP XML configuration, you can find the connection factory, within the messaging subsystem.
Next a timer endpoint runs every 10 seconds to send an XML payload to the WildFlyCamelQueue destination that has been configured earlier.
A log message will be output to the console each time a JMS message is added to the WildFlyCamelQueue destination. To verify that the messages really are being placed onto the queue, you can use the JBoss EAP administration console.
5.6.2.2. JMS Consumer Link kopierenLink in die Zwischenablage kopiert!
To consume JMS messages the Camel RouteBuilder implementation is similar to the producer example.
As before, the connection factory is discovered from JNDI, injected and set on the JMSComponent instance.
When the JMS endpoint consumes messages from the WildFlyCamelQueue destination, the content is logged to the console.
5.6.2.3. JMS Transactions Link kopierenLink in die Zwischenablage kopiert!
To enable Camel JMS routes to participate in JMS transactions, some additional configuration is required. Since camel-jms is built around spring-jms, you need to configure some Spring classes to enable them to work with JBoss EAP’s transaction manager and connection factory. The following code example demonstrates how to use CDI to configure a transactional JMS Camel route.
The camel-jms component requires a transaction manager of type org.springframework.transaction.PlatformTransactionManager. Therefore, you start by creating a bean extending JtaTransactionManager. Note that the bean is annotated with @Named to allow the bean to be registered within the Camel bean registry. Also note that the JBoss EAP transaction manager and user transaction instances are injected using CDI.
Next, you need to declare the transaction policy that you want to use. Again, use the @Named annotation to make the bean available to Camel. The transaction manager is also injected so that a TransactionTemplate can be created with the desired transaction policy. PROPAGATION_REQUIRED in this instance.
Now you can configure our Camel RouteBuilder class and inject the dependencies needed for the Camel JMS component. The JBoss EAP XA connection factory is injected together with the transaction manager that has been configured earlier.
In this example RouteBuilder, whenever any messages are consumed from queue1, they are routed to another JMS queue named queue2. Messages consumed from queue2 result in JMS transaction being rolled back using the rollback() DSL method. This results in the original message being placed onto the dead letter queue(DLQ).
5.6.2.4. Remote JMS destinations Link kopierenLink in die Zwischenablage kopiert!
It is possible for one JBoss EAP instance to send messages to ActiveMQ Artemis destinations configured on another JBoss EAP instance through remote JNDI.
Some additional JBoss EAP configuration is required to achieve this. First an exported JMS queue is configured.
Only JNDI names bound in the java:jboss/exported namespace are considered as candidates for remote clients, so the queue is named appropriately.
You must configure the queue on the JBoss EAP client application server andJBoss EAP remote server.
<jms-queue name="RemoteQueue"> <entry name="java:jboss/exported/jms/queues/RemoteQueue"/> </jms-queue>
<jms-queue name="RemoteQueue">
<entry name="java:jboss/exported/jms/queues/RemoteQueue"/>
</jms-queue>
Before the client can connect to the remote server, user access credentials need to be configured. On the remote server run the add user utility to create a new application user within the 'guest' group. This example has a user with the name 'admin' and a password of 'secret'.
The RouteBuilder implementation is different to the previous examples. Instead of injecting the connection factory, you need to configure an InitialContext and retrieve it from JNDI ourselves.
The configureInitialContext method creates this InitialContext. Notice that you need to set a provider URL which should reference your remote JBoss EAP instance host name and port number. This example uses the JBoss EAP JMS http-connector, but there are alternatives documented here.
Finally the route is configured to send an XML payload every 10 seconds to the remote destination configured earlier - 'RemoteQueue'.
5.6.3. Security Link kopierenLink in die Zwischenablage kopiert!
Refer to the JMS security section.
5.6.4. Quickstart examples in Fuse on EAP Link kopierenLink in die Zwischenablage kopiert!
A quickstart example is available in your Fuse on EAP installation at quickstarts/camel/camel-jms directory.
5.7. JMX Link kopierenLink in die Zwischenablage kopiert!
You can provide management support through the JMX component which integrates with the JBoss EAP JMX subsystem.
5.8. JNDI Link kopierenLink in die Zwischenablage kopiert!
JNDI integration is provided by a JBoss EAP specific CamelContext as shown below:
InitialContext inictx = new InitialContext();
CamelContextFactory factory = inictx.lookup("java:jboss/camel/CamelContextFactory");
WildFlyCamelContext camelctx = factory.createCamelContext();
InitialContext inictx = new InitialContext();
CamelContextFactory factory = inictx.lookup("java:jboss/camel/CamelContextFactory");
WildFlyCamelContext camelctx = factory.createCamelContext();
From a WildFlyCamelContext you can obtain a preconfigured Naming Context
Context context = camelctx.getNamingContext();
context.bind("helloBean", new HelloBean());
Context context = camelctx.getNamingContext();
context.bind("helloBean", new HelloBean());
which can then be referenced from Camel routes.
5.9. JPA Link kopierenLink in die Zwischenablage kopiert!
JPA integration is provided by the Camel JPA component. You can develop Camel JPA applications by providing a persistence.xml configuration file together with some JPA annotated classes.
5.9.1. Example persistence.xml Link kopierenLink in die Zwischenablage kopiert!
In the following example, you can use the JBoss EAP in-memory ExampleDS datasource which is configured within the JBoss EAP standalone.xml configuration file.
5.9.2. Example JPA entitiy Link kopierenLink in die Zwischenablage kopiert!
5.9.3. Camel JPA endpoint / route configuration Link kopierenLink in die Zwischenablage kopiert!
Having configured JPA, you can make use of CDI to inject an EntityManager and UserTransaction instance into your RouteBuilder class or test case:
@PersistenceContext EntityManager em; @Inject UserTransaction userTransaction;
@PersistenceContext
EntityManager em;
@Inject
UserTransaction userTransaction;
Now to configure the Camel routes and JPA endpoint:
Finally, you can send a 'Customer' entity to the 'direct:start' endpoint and then query the ExampleDS datasource to verify that a record was saved.
Chapter 6. Camel Components Link kopierenLink in die Zwischenablage kopiert!
This chapter details information about supported camel components
6.1. camel-activemq Link kopierenLink in die Zwischenablage kopiert!
Camel ActiveMQ integration is provided by the activemq component.
The component can be configured to work with an embedded or external broker. For Wildfly / EAP container managed connection pools and XA-Transaction support, the ActiveMQ Resource Adapter can be configured into the container configuration file.
6.1.1. JBoss EAP ActiveMQ resource adapter configuration Link kopierenLink in die Zwischenablage kopiert!
Download the ActiveMQ resource adapter rar file. The following steps outline how to configure the ActiveMQ resource adapter.
- Stop your JBoss EAP instance.
Download the resource adapter and copy to the relevant JBoss EAP deployment directory. For standalone mode:
cp activemq-rar-5.11.0.redhat-630396.rar ${JBOSS_HOME}/standalone/deployments/activemq-rar.rarcp activemq-rar-5.11.0.redhat-630396.rar ${JBOSS_HOME}/standalone/deployments/activemq-rar.rarCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Configure the JBoss EAP resource adapters subsystem for the ActiveMQ adapter.
If your resource adapter archive filename differs from activemq-rar.rar, you must change the content of the archive element in the preceding configuration to match the name of your archive file.
The values of the UserName and Password configuration properties must be chosen to match the credentials of a valid user in the external broker.
You might need to change the value of the ServerUrl configuration property to match the actual hostname and port exposed by the external broker.
4) Start JBoss EAP. If everything is configured correctly, you should see a message within the JBoss EAP server.log like.
13:16:08,412 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-5) JBAS010406: Registered connection factory java:/AMQConnectionFactory`
13:16:08,412 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-5) JBAS010406: Registered connection factory java:/AMQConnectionFactory`
6.1.2. Camel route configuration Link kopierenLink in die Zwischenablage kopiert!
The following ActiveMQ producer and consumer examples make use of the ActiveMQ embedded broker and the 'vm' transport (thus avoiding the need for an external ActiveMQ broker).
The examples use CDI in conjunction with the camel-cdi component. JMS ConnectionFactory instances are injected into the Camel RouteBuilder through JNDI lookups.
6.1.2.1. ActiveMQ Producer Link kopierenLink in die Zwischenablage kopiert!
A log message will be output to the console each time a message is added to the WildFlyCamelQueue destination. To verify that the messages really are being placed onto the queue, you can use the ../features/hawtio.md[Hawtio console,window=_blank] provided by the Camel on EAP subsystem.
6.1.2.2. ActiveMQ Consumer Link kopierenLink in die Zwischenablage kopiert!
To consume ActiveMQ messages the Camel RouteBuilder implementation is similar to the producer example.
When the ActiveMQ endpoint consumes messages from the WildFlyCamelQueue destination, the content is logged to the console.
@Override
public void configure() throws Exception {
from("activemq:queue:WildFlyCamelQueue?brokerURL=vm://localhost")
.to("log:jms?showAll=true");
}
@Override
public void configure() throws Exception {
from("activemq:queue:WildFlyCamelQueue?brokerURL=vm://localhost")
.to("log:jms?showAll=true");
}
6.1.2.3. ActiveMQ Transactions Link kopierenLink in die Zwischenablage kopiert!
6.1.2.3.1. ActiveMQ Resource Adapter Configuration Link kopierenLink in die Zwischenablage kopiert!
The ActiveMQ resource adapter is required to leverage XA transaction support, connection pooling etc.
The XML snippet below shows how the resource adapter is configured within the JBoss EAP server XML configuration. Notice that the ServerURL is set to use an embedded broker. The connection factory is bound to the JNDI name java:/ActiveMQConnectionFactory. This will be looked up in the RouteBuilder example that follows.
Finally, two queues are configured named 'queue1' and 'queue2'.
6.1.2.4. Transaction Manager Link kopierenLink in die Zwischenablage kopiert!
The camel-activemq component requires a transaction manager of type org.springframework.transaction.PlatformTransactionManager. Therefore, you can start by creating a bean extending JtaTransactionManager which fulfills this requirement. Note that the bean is annotated with @Named to allow the bean to be registered within the Camel bean registry. Also note that the JBoss EAP transaction manager and user transaction instances are injected using CDI.
6.1.2.5. Transaction Policy Link kopierenLink in die Zwischenablage kopiert!
Next you need to declare the transaction policy that you want to use. Again, use the @Named annotation to make the bean available to Camel. The transaction manager is also injected so that a TransactionTemplate can be created with the desired transaction policy. PROPAGATION_REQUIRED in this instance.
6.1.2.6. Route Builder Link kopierenLink in die Zwischenablage kopiert!
Now you can configure the Camel RouteBuilder class and inject the dependencies needed for the Camel ActiveMQ component. The ActiveMQ connection factory that you configured on the resource adapter configuration is injected together with the transaction manager you configured earlier.
In this example RouteBuilder, whenever any messages are consumed from queue1, they are routed to another JMS queue named queue2. Messages consumed from queue2 result in JMS transaction being rolled back using the rollback() DSL method. This results in the original message being placed onto the dead letter queue(DLQ).
6.1.3. Security Link kopierenLink in die Zwischenablage kopiert!
Refer to the JMS security section.
6.1.4. Code examples on GitHub Link kopierenLink in die Zwischenablage kopiert!
An example camel-activemq application is available on GitHub.
6.2. camel-jms Link kopierenLink in die Zwischenablage kopiert!
There are two supported ways of connecting camel-jms, camel-sjms and camel-sjms2 endpoints to a remote AMQ 7 broker.
- Configuring a remote-connector with a pooled-connection-factory as described in the section called Configuring the Artemis Resource Adapter to Connect to Red Hat JBoss AMQ 7 in the JBoss EAP Configuring Messaging guide.
- Configuring a remote-connector with connection-factory as described in Configure a remote-connector with connection-factory
The first option is the preferred method, because it provides connection pooling and XA transaction support.
For messaging scenarios that use durable subscribers, pooled-connection-factory is not supported by Fuse 7.3 on JBoss EAP due to constraints imposed by the JavaEE 7 specification. In these scenarios configuring a standard unpooled connection-factory is preferred.
Configure a remote-connector with connection-factory
Create an outbound-socket-binding pointing to the remote messaging server:
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=messaging-remote-throughput:add(host=localhost, port=61616)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=messaging-remote-throughput:add(host=localhost, port=61616)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a remote-connector referencing the outbound-socket-binding created in step 1.
/subsystem=messaging-activemq/server=default/remote-connector=netty-remote-throughput:add(socket-binding=messaging-remote-throughput)
/subsystem=messaging-activemq/server=default/remote-connector=netty-remote-throughput:add(socket-binding=messaging-remote-throughput)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a connection-factory referencing the remote-connector created in step 2.
/subsystem=messaging-activemq/server=default/connection-factory=simple-remote-artemis-connection-factory:add(entries=[java:/jms/RemoteJms],connectors=[netty-remote-throughput])
/subsystem=messaging-activemq/server=default/connection-factory=simple-remote-artemis-connection-factory:add(entries=[java:/jms/RemoteJms],connectors=[netty-remote-throughput])Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2.1. Messaging brokers and clients Link kopierenLink in die Zwischenablage kopiert!
Abstract
Fuse 7.3 does not ship with a default internal messaging broker, but it is designed to interface with external JMS brokers.
Fuse 7.3 on JBoss EAP uses the resource adapters detailed in Configuring Messaging on JBoss EAP to access external messaging brokers.
See Supported Configurations for more information about the external brokers, JCA adapters and Camel component combinations that are available for messaging on Fuse 7.3 on JBoss EAP.
For more information about connecting to external brokers using Fuse on JBoss EAP using JMS, see Section 6.2, “camel-jms”.
camel-jms quickstart
A quickstart is provided to demonstrate the use of the camel-jms component with Fuse on JBoss EAP to produce and consume JMS messages.
In this quickstart a Camel route consumes files from EAP_HOME/standalone/data/orders and places their contents onto an in-memory ActiveMQ Artemis queue named OrdersQueue. Another Camel route then consumes the contents of OrdersQueue and sorts the orders into individual country directories within EAP_HOME/standalone/data/orders/processed.
CLI commands create and delete OrdersQueue CLI scripts take care of creating and removing the JMS OrdersQueue for you when the application is deployed and undeployed. These scripts are located within the EAP_HOME/quickstarts/camel-jms/src/main/resources/cli directory.
Prerequisites
To run this quickstart you must have a working version of Fuse 7.3
You must also follow the instructions in Using JBoss AMQ for remote JMS Communication to connect to an external AMQ 7 broker. You can then inject the connection factory as you would with the default connection factory.
@Resource(mappedName = "java:jboss/RemoteJmsXA") ConnectionFactory connectionFactory;
@Resource(mappedName = "java:jboss/RemoteJmsXA")
ConnectionFactory connectionFactory;
Setup the quickstart
- Start JBOSS EAP in standalone mode.
-
Navigate to
EAP_HOME/quickstarts/camel/camel-jms -
Enter
mvn clean install -Pdeploy`to build and deploy the quickstart. - Browse to http://localhost:8080/example-camel-jms
You should see a page titled 'Orders Received'. As we send orders to the example application, a list of orders per country will be listed on this page.
Run the quickstart
There are some example order XML files within the EAP_HOME/quickstarts/camel/camel-jms/src/main/resources directory. Camel will choose a file at random every 5 seconds and will copy it into EAP_HOME/standalone/data/orders for processing.
The console will output messages detailing what happened to each of the orders. The output will look something like this.
JmsConsumer[OrdersQueue]) Sending order to the UK JmsConsumer[OrdersQueue]) Sending order to another country JmsConsumer[OrdersQueue]) Sending order to the US
JmsConsumer[OrdersQueue]) Sending order to the UK
JmsConsumer[OrdersQueue]) Sending order to another country
JmsConsumer[OrdersQueue]) Sending order to the US
When the files have been consumed, you can return to http://localhost:8080/example-camel-jms/orders. The count of received orders for each country should have been increased by 1.
All the processed orders will be split into the following destinations:
EAP_HOME/standalone/data/orders/processed/uk EAP_HOME/standalone/data/orders/processed/us EAP_HOME/standalone/data/orders/processed/other
EAP_HOME/standalone/data/orders/processed/uk
EAP_HOME/standalone/data/orders/processed/us
EAP_HOME/standalone/data/orders/processed/other
Undeploy
To undeploy the example, navigate to EAP_HOME/quickstarts/camel/camel-jms run mvn clean -Pdeploy.
6.3. camel-mail Link kopierenLink in die Zwischenablage kopiert!
Interaction with email is provided by the mail component.
By default, Camel will create its own mail session and use this to interact with your mail server. Since JBoss EAP already provides a mail subsystem with all of the relevant support for secure connections, username and password encryption etc, therefore, it is recommended to configure your mail sessions within the JBoss EAP configuration and use JNDI to wire them into your Camel endpoints.
6.3.1. JBoss EAP configuration Link kopierenLink in die Zwischenablage kopiert!
First you configure the JBoss EAP mail subsystem for the Mail server. The following example adds configuration for Google Mail IMAP and SMTP .
An additional mail-session is configured after the 'default' session.
<subsystem xmlns="urn:jboss:domain:mail:2.0">
<mail-session name="default" jndi-name="java:jboss/mail/Default">
<smtp-server outbound-socket-binding-ref="mail-smtp"/>
</mail-session>
<subsystem xmlns="urn:jboss:domain:mail:2.0">
<mail-session name="default" jndi-name="java:jboss/mail/Default">
<smtp-server outbound-socket-binding-ref="mail-smtp"/>
</mail-session>
<mail-session debug="true" name="gmail" jndi-name="java:jboss/mail/gmail">
<smtp-server outbound-socket-binding-ref="mail-gmail-smtp" ssl="true" username="your-username-here" password="your-password-here"/>
<imap-server outbound-socket-binding-ref="mail-gmail-imap" ssl="true" username="your-username-here" password="your-password-here"/>
</mail-session>
</subsystem>
<mail-session debug="true" name="gmail" jndi-name="java:jboss/mail/gmail">
<smtp-server outbound-socket-binding-ref="mail-gmail-smtp" ssl="true" username="your-username-here" password="your-password-here"/>
<imap-server outbound-socket-binding-ref="mail-gmail-imap" ssl="true" username="your-username-here" password="your-password-here"/>
</mail-session>
</subsystem>
You can configure outbound-socket-binding-ref values of 'mail-gmail-smtp' and 'mail-gmail-imap'.
The next step is to configure these socket bindings. You can add additional bindings to the socket-binding-group configuration as per the following.
This configures the mail session to connect to host smtp.gmail.com on port 465 and imap.gmail.com on port 993. If you’re using a different mail host, then this detail will be different.
6.3.2. POP3 Configuration Link kopierenLink in die Zwischenablage kopiert!
If you need to configure POP3 sessions, the principles are the same as defined in the examples above.
6.3.3. Camel route configuration Link kopierenLink in die Zwischenablage kopiert!
6.3.3.1. Mail producer Link kopierenLink in die Zwischenablage kopiert!
This example uses the SMTPS protocol, together with CDI in conjunction with the camel-cdi component. The Java mail session that you configured within the JBoss EAP configuration is injected into a Camel RouteBuilder through JNDI.
6.3.3.1.1. Route builder SMTPS example Link kopierenLink in die Zwischenablage kopiert!
The GMail mail session is injected into a Producer class using the @Resource annotation with a reference to the jndi-name attribute that you previously configured. This allows you to reference the mail session on the camel-mail endpoint configuration.
To send an email, you can create a ProducerTemplate and send an appropriate body together with the necessary email headers.
6.3.3.2. Mail consumer Link kopierenLink in die Zwischenablage kopiert!
To receive email you can use an IMAP MailEndpoint. The Camel route configuration looks like the following.
public void configure() throws Exception {
from("imaps://imap.gmail.com?session=#mailSession")
.to("log:email");
}
public void configure() throws Exception {
from("imaps://imap.gmail.com?session=#mailSession")
.to("log:email");
}
6.3.4. Security Link kopierenLink in die Zwischenablage kopiert!
6.3.4.1. SSL configuration Link kopierenLink in die Zwischenablage kopiert!
JBoss EAP can be configured to manage Java mail sessions and their associated transports using SSL / TLS. When configuring mail sessions you can configure SSL or TLS on server types:
- smtp-server
- imap-server
- pop-server
By setting attributes ssl="true" or tls="true".
6.3.4.2. Securing passwords Link kopierenLink in die Zwischenablage kopiert!
It is recommended to not use clear text for passwords within configuration files. You can mask sensitive data using the WildFly Vault.
6.3.4.3. Camel security Link kopierenLink in die Zwischenablage kopiert!
Camel endpoint security documentation can be found on the mail component guide. Camel also has a security summary page.
6.3.5. Code examples on GitHub Link kopierenLink in die Zwischenablage kopiert!
An example camel-mail application is available on GitHub for you to try out sending / receiving email.
6.4. camel-rest Link kopierenLink in die Zwischenablage kopiert!
The rest component allows you to define REST endpoints using the Rest DSL and plugin to other Camel components as the REST transport.
The Camel on EAP Subsystem only supports the camel-servlet and camel-undertow components for use with the REST DSL. However, the subsystem does not work, If you attempt to configure other components.
6.5. camel-rest-swagger Link kopierenLink in die Zwischenablage kopiert!
The rest-swagger component can configure REST producers from a Swagger document and delegate to a component implementing the RestProducerFactory interface such as:
6.6. camel-sql Link kopierenLink in die Zwischenablage kopiert!
The SQL component allows you to work with databases using JDBC queries. The difference between this component and JDBC component is that in case of SQL the query is a property of the endpoint and it uses message payload as parameters passed to the query.
The JNDI datasource lookup shown above works only when configuring a DefaultCamelContext. See below for CdiCamelContext and SpringCamelContext examples.
When used in conjunction with the camel-cdi component, Java EE annotations can make a datasource available to Camel. This example uses the @Named annotation so that Camel can discover the desired datasource.
Now the datasource can be referenced through the dataSource parameter on the camel-sql endpoint configuration.
When using camel-spring the route configuration would look like:
6.6.1. Spring JDBC XML namespace support Link kopierenLink in die Zwischenablage kopiert!
Support for the following Spring JDBC XML configurations is supported
jdbc:embedded-database
<jdbc:embedded-database id="datasource" type="H2"> <jdbc:script location="db-schema.sql"/> </jdbc:embedded-database>
<jdbc:embedded-database id="datasource" type="H2">
<jdbc:script location="db-schema.sql"/>
</jdbc:embedded-database>
Only H2 databases are supported by default as JBoss EAP has native support for this. If you want to use other embedded database providers, you will need to install the appropriate database driver.
jdbc:initialize-database
<jdbc:initialize-database data-source="datasource"> <jdbc:script location="classpath:db-init.sql"/> </jdbc:initialize-database>
<jdbc:initialize-database data-source="datasource">
<jdbc:script location="classpath:db-init.sql"/>
</jdbc:initialize-database>
6.7. Adding Components Link kopierenLink in die Zwischenablage kopiert!
Adding support for additional Camel Components is easy
Add your modules.xml definition
A modules.xml descriptor defines the class loading behavior for your component. It should be placed together with the component’s jar in modules/system/layers/fuse/org/apache/camel/component. Module dependencies should be setup for direct compile time dependencies.
Here is an example for the camel-ftp component
Please make sure you don’t duplicate modules that are already available in WildFly and can be reused.
Add a reference to the component
To make this module visible by default to arbitrary JavaEE deployments add a reference to modules/system/layers/fuse/org/apache/camel/component/main/module.xml
Chapter 7. Security Link kopierenLink in die Zwischenablage kopiert!
Security in JBoss EAP is a vast topic. Both JBoss EAP and Camel have well documented, standardised methods of securing configuration, endpoints and payloads.
7.1. JAX-RS Security Link kopierenLink in die Zwischenablage kopiert!
The following topics explain how to secure JAX-RS endpoints.
7.2. JAX-WS Security Link kopierenLink in die Zwischenablage kopiert!
The following topics explain how to secure JAX-WS endpoints.
7.3. JMS Security Link kopierenLink in die Zwischenablage kopiert!
The following topics explain how to secure JMS endpoints.
Additionally, you can use Camel’s notion of Route Policies to integrate with the JBoss EAP security system.
7.4. Route Policy Link kopierenLink in die Zwischenablage kopiert!
Camel supports the notion of RoutePolicies, which can be used to integrate with the JBoss EAP security system. There are currently two supported scenarios for security integration.
7.4.1. Camel calls into JavaEE Link kopierenLink in die Zwischenablage kopiert!
When a camel route calls into a secured JavaEE component, it acts as a client and must provide appropriate credentials associated with the call.
You can decorate the route with a ClientAuthorizationPolicy as follows:
This does not do any authentication and authorization, as a part of the camel message processing. Instead, it associates the credentials that come with the Camel Exchange with the call into the EJB3 layer.
The client that calls the message consumer must provide appropriate credentials in the AUTHENTICATION header like this:
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
Authentication and authorization will happen in the JavaEE layer.
7.4.2. Securing a Camel Route Link kopierenLink in die Zwischenablage kopiert!
In order to secure a Camel Route, you can associate a DomainAuthorizationPolicy with the route. This policy requires a successful authentication against the given security domain and authorization for "Role2".
Again, the client that calls the message consumer must provide appropriate credentials in the AUTHENTICATION header like this:
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);