Fabric3 supports defining components using annotations, XML, or a DSL. Before discussing other aspects of programming with Fabric3, we will provide an overview of working with annotations and the DSL.
Fabric3 is a modular runtime that is designed to be configured and deployed based on the specific functional requirements of the services it is hosting. For example, if a runtime is to host a service that requires JAX-RS functionality, an image can be assembled from the Fabric3 kernel and JAX-RS extensions; extensions for other technologies such as JMS or WS-* may be excluded.
Fabric3 provides Maven and Gradle plugins for assembling runtime images as part of a build. For details, see Service Delivery.
This modularity is reflected in the structure of the Fabric3 API. The main API module,
org.fabric3:fabric3-api contains base annotations for working with Java POJO. Component implementation types (such as the timer component) and bindings also have API modules that extend from the core
fabric3-api module. For example, the
org.fabric3:fabric3-timer-api contains the
Timer annotation used to declare a Java class as timer component. It may therefore be necessary to configure multiple API modules as dependencies in a project build. At runtime, Fabric3 will ensure installed API module classes are visible to applications.
Throughout this manual, we refer to Fabric3 modules (JARs) using their coordinate names, e.g.
org.fabric3:fabric3-api. These coordinates correspond to
[group id:artifact id] and can be used to derive dependency configuration for various build systems such as Maven and Gradle.
The following table lists the set of Fabric3 API modules:
|The base package containing general annotations and API classes|
|The base package for DSL classes|
|Package for JMS annotations and DSL classes|
|Package for file binding annotations and DSL classes|
|Package for JAX-RS annotations and DSL classes|
|Package for JAX-WS annotations and DSL classes|
|Package for ZeroMQ annotations and DSL classes|
|Package for JUnit annotations|
|Package for Timer annotations and DSL classes|
Using the DSL
Components and channels can also be defined using the Fabric3 DSL. To use the DSL, one or more provider classes must be packaged in an application archive under the Java package "f3". Provider classes are invoked by the runtime to programmatically create composites. The following is an example of a provider class:
A provider class contains one or more static methods annotated with
org.fabric3.api.annotation.model.Provides that returns a Composite. Programmatic configuration is extremely flexible as it can be used to create conditional configuration such as changing binding settings based on the environment. To facilitate this, Fabric3 supports the
Environment annotation signals to Fabric3 to inject the name of the environment the runtime is started with. For example of how to configure the runtime with different environment settings, see Packaging For Different Environments.
For specific examples of using annotations or the DSL, refer to the sample applications.