include::../shared-doc/attributes.adoc[]

= ejb-asynchronous: EJB with asynchronous methods
:author: Wolf-Dieter Fink
:level: Advanced
:technologies: Asynchronous EJB

[abstract]
The `ejb-asynchronous` quickstart demonstrates the behavior of asynchronous EJB invocations by a deployed EJB and a remote client and how to handle errors.

:standalone-server-type: default
:archiveType: jar

== What is it?

The `ejb-asynchronous` quickstart demonstrates the behavior of asynchronous EJB invocations in {productNameFull}. The methods are invoked by both an EJB in the deployment and by a remote client. The quickstart also shows error handling if the asynchronous method invocation fails.

This example consists of the following Maven projects, each with a shared parent.

[cols="30%,70%",options="headers"]
|===
|Project |Description

| `ejb`
| This project contains the EJBs that are deployed to the server.
| `client`
| This project contains a remote EJB client.
|===

The root `pom.xml` builds each of the subprojects in the above order and deploys the archive to the server.

//  System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
// Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]
// Start the {productName} Standalone Server
include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]
// Install the Quickstart Parent Artifact in Maven
include::../shared-doc/install-quickstart-parent-artifact.adoc[leveloffset=+1]
// Build and Deploy the Quickstart
include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

== Access the Application

. Open a terminal and navigate to the root directory of this quickstart.
. Type the following command to start the client.
+
[source,options="nowrap"]
----
$ cd client
$ mvn exec:exec
----

. Check the client output
+
[source,options="nowrap"]
----
INFO: The server log should contain a message at (about) <date>, indicating that the call to the asynchronous bean completed.
INFO: Got the async result as expected => returning at <date>, duration was 200ms
INFO: Got the async result as expected after wait => returning at <date>, duration was 1500ms
INFO: Catch the expected Exception of the asynchronous execution!
INFO: Results of the parallel (server) processing : [returning at <date> duration was 5000ms, returning at <date>, duration was 3000ms]
----

. Check the server log. There should be two `INFO` log messages for the `fireAndForget` invocation.
+
First, you should see the following message.
+
[source,options="nowrap"]
----
'fireAndForget' Will wait for 15000ms
----
+
The second message appears after the client is finished, approximately 15 seconds later.
+
[source,options="nowrap"]
----
action 'fireAndForget' finished
----

// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]
// Run the Quickstart in Red Hat Developer Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]

// Additional Red Hat Developer Studio instructions
This quickstart consists of multiple projects, so it deploys and runs differently in {JBDSProductName} than the other quickstarts.

. Install the required Maven artifacts and deploy the asynchronous EJB quickstart project.
** Right-click on the *{artifactId}-ejb* project and choose *Run As* -> *Maven Install*.
** Right-click on the *{artifactId}-ejb* project and choose *Run As* -> *Run on Server*.
. Build and run the client side of the quickstart project.
** Right-click on the *{artifactId}-client* project and choose *Run As* -> *Java Application*.
** In the *Select Java Application* window, choose *AsynchronousClient - org.jboss.as.quickstarts.ejb.asynchronous.client* and click *OK*.
** The client output displays in the *Console* window.
. To undeploy the project, right-click on the *{artifactId}-ejb* project and choose *Run As* -> *Maven build*. Enter `wildfly:undeploy` for the *Goals* and click *Run*.

// Debug the Application
include::../shared-doc/debug-the-application.adoc[leveloffset=+1]
