Quarkus IronJacamar
This extension allows you to deploy JCA Resource Adapters in Quarkus. IronJacamar is a Jakarta Connector Architecture (JCA) implementation.
What is Quarkus IronJacamar?
Quarkus IronJacamar is the extension that integrates the IronJacamar project into the Quarkus ecosystem.
To break it down:
-
IronJacamar: An open-source implementation of the Java Connector Architecture (JCA). The JCA specification provides a standardized way to connect a Java application server to external Enterprise Information Systems (EIS), such as databases, ERPs (like SAP), legacy systems, or mainframes. Think of it as "JDBC for everything else," creating a standard contract for connectivity.
-
Quarkus: A modern, Kubernetes-native Java framework designed for high performance, low memory usage, and fast startup times, making it ideal for microservices and cloud environments.
Essentially, Quarkus IronJacamar allows you to use standard JCA Resource Adapters within a lightweight and high-performance Quarkus application. It acts as the bridge connecting the speed and agility of Quarkus with the standardized, robust connectivity of the JCA world.
Key Features
-
Legacy System Connectivity: The primary goal is to enable Quarkus applications to communicate with any EIS that provides a JCA-compliant resource adapter. This is crucial for modernizing applications that still rely on critical backend systems.
-
Connection Pooling: IronJacamar manages a pool of connections to the external system, improving performance and scalability by reusing connections instead of creating new ones for each request.
-
Transaction Management: It integrates with the Quarkus transaction manager, allowing interactions with the external system to participate in distributed (XA) transactions. This ensures data consistency across multiple resources (e.g., updating a database and an ERP system in the same transaction).
-
Security Context: Supports the propagation of security contexts from the application to the EIS, as defined by the JCA specification.
Use Case Example 💡
Imagine you are building a new e-commerce platform using Quarkus microservices. Your company’s product inventory is managed by a legacy mainframe system that doesn’t have a modern REST API but provides a JCA resource adapter.
Instead of developing a complex, custom integration, your "Product" microservice can use the Quarkus IronJacamar extension:
-
Configure the mainframe’s resource adapter in your Quarkus application.
-
Use the standard JCA API to get a connection from the pool managed by IronJacamar.
-
Your microservice can now query the mainframe for real-time stock levels, and this interaction can be part of a larger transaction that also updates your order database, ensuring everything stays consistent.
Installation
If you want to use this extension, you need to add the io.quarkiverse.ironjacamar:quarkus-ironjacamar extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.ironjacamar</groupId>
<artifactId>quarkus-ironjacamar</artifactId>
<version>2.0.0</version>
</dependency>
Integration
We recommend you to create a Quarkus extension dedicated for your Resource Adapter.
This will allow you to build your Resource Adapter to native and perform the optimizations needed to run in Quarkus.
If you don’t want to create a Quarkus extension for your Resource Adapter, just implement the ResourceAdapterFactory in your application code and you’ll be fine.
Implementing a ResourceAdapterFactory
A ResourceAdapterFactory is an SPI that the IronJacamar extension introduces to create ResourceAdapter, ManagedConnectionFactory and ActivationSpec instances.
You must use the @ResourceAdapterKind annotation on it to specify the resource adapter kind that will be used to identify the factory in the application code.
@ResourceAdapterKind(value = "artemis") (1)
@ResourceAdapterTypes(connectionFactoryTypes = { jakarta.jms.ConnectionFactory.class }) (2)
public class ArtemisResourceAdapterFactory implements ResourceAdapterFactory {...} (3)
| 1 | The value is the name of the resource adapter kind. Because a Quarkus application can manage multiple resource adapters, this is used in the configuration to select the proper resource adapter to be configured and started. |
| 2 | The connection factory types that this resource adapter supports.
This must be the types that the object returned in the jakarta.resource.spi.ManagedConnectionFactory.createConnectionFactory(jakarta.resource.spi.ConnectionManager) has.
That will allow you to @Inject this object in your application code (eg. @Inject ConnectionFactory in this example). |
| 3 | The implementation of the ResourceAdapterFactory interface.
This is the class that will be instantiated by the IronJacamar extension to create the resource adapter instance. |
Using a ResourceEndpoint
Resource endpoints are activated in the ResourceAdapter (think EJB’s @MessageDriven annotation) and are declared using the @ResourceEndpoint annotation.
import io.quarkiverse.ironjacamar.ResourceEndpoint;
@ResourceEndpoint(activationSpecConfigKey = "myqueue") (1)
public class MyResourceEndpoint implements jakarta.jms.MessageListener {...} (2)
| 1 | An optional activation spec configuration key.
The activationSpecConfigKey is the key that will be consumed from the configuration (see the application.properties example below) |
| 2 | The resource endpoint implementation.
Because the Artemis ResourceAdapter implementation expects a jakarta.jms.MessageListener instance, you must implement this interface. |
The configuration may vary according to what the chosen ResourceAdapterFactory implementation expects.
- Important
-
The required interface may vary according to the resource adapter used. If you are unsure of what to use, look at your resource adapter documentation.
Configuration
In your application
quarkus.ironjacamar.ra.kind=artemis (1)
quarkus.ironjacamar.ra.config.connection-parameters=host=localhost;port=5445;protocols=HORNETQ (2)
quarkus.ironjacamar.ra.config.protocol-manager-factory=org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory
quarkus.ironjacamar.ra.config.user=guest
quarkus.ironjacamar.ra.config.password=guest
quarkus.ironjacamar.activation-spec.myqueue.config.destination-type=jakarta.jms.Queue (3)
quarkus.ironjacamar.activation-spec.myqueue.config.destination=jms.queue.MyQueue
quarkus.ironjacamar.activation-spec.myqueue.config.max-session=2
quarkus.ironjacamar.activation-spec.myqueue.config.rebalance-connections=true
| 1 | This is the resource adapter kind.
It must match the value of the @ResourceAdapterKind annotation in the ResourceAdapterFactory implementation. |
| 2 | (Optional) You can specify the resource adapter configuration that will be passed to your ResourceAdapterFactory#createResourceAdapter implementation method. |
| 3 | (Optional) You can specify optional activation spec configuration ResourceAdapterFactory#createActivationSpec implementation method. |
Multiple Resource Adapters
You can configure more than one ResourceAdapter instance in your application.
Just name the resource adapter in the configuration:
quarkus.ironjacamar.main.ra.kind=artemis (1)
quarkus.ironjacamar.other.ra.kind=artemis
To reference in the code, you must use the @io.smallrye.common.annotation.Identifier annotation:
import io.quarkiverse.ironjacamar.ResourceEndpoint;
import io.smallrye.common.annotation.Identifier;
import jakarta.inject.Inject;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
@ResourceEndpoint
@Identifier("other") (1)
public class MyResourceEndpoint implements MessageListener {
@Inject
@Identifier("main")
ConnectionFactory connectionFactory; (2)
@Override
public void onMessage(Message message) {
//...
}
}
| 1 | This MessageListener will be activated by the other resource adapter configured above. |
| 2 | This ConnectionFactory will be the one configured in the main resource adapter. |
Transactions
Quarkus IronJacamar supports the @Transactional annotation on ResourceEndpoint implementations to automatically enlist the connection in the current transaction:
import io.quarkiverse.ironjacamar.ResourceEndpoint;
import jakarta.inject.Inject;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import javax.transaction.Transactional;
@ResourceEndpoint
public class MyResourceEndpoint implements MessageListener {
@Inject
ConnectionFactory connectionFactory;
@Override
@Transactional
public void onMessage(Message message) {
//...
}
}
It also supports the @Transactional annotation on methods consuming the managed connection factories produced by the ResourceAdapterFactory implementation:
@Path("/jca")
@ApplicationScoped
public class JcaResource {
@Inject
ConnectionFactory connectionFactory;
@GET
@Path("/send")
@Transactional
public void send() {
try (Connection connection = connectionFactory.createConnection()) {
//...
}
}
}
Some adapter implementations may require additional configuration to enable transaction support. Check the adapter documentation for more details.
- NOTE
-
if running in a XA transaction, it is recommended to enable recovery by using
quarkus.transaction-manager.enable-recovery=true. Check the guide on Using Transactions in Quarkus for more details.
Metrics
If you are using the quarkus-micrometer or quarkus-smallrye-metrics extension, quarkus-ironjacamar can contribute some connection pool-related metrics to the metric registry.
This can be activated by setting the quarkus.ironjacamar.metrics.enabled property to true.
Alternatively, you can disable the pool metrics for a specific resource adapter by setting the quarkus.ironjacamar."resource-adapter-name".ra.cm.pool.enable-metrics property to false.
Listening to lifecycle events
You can listen to lifecycle events of the ResourceAdapter instances by having an @ApplicationScoped bean implementing the ResourceAdapterLifecycleListener interface.
Here is an example:
@ApplicationScoped
public class WaitUntilServiceIsReady implements ResourceAdapterLifecycleListener {
@Override
public void preStartup(String id, ResourceAdapter resourceAdapter) {
// Using the org.awaitility.Awaitility library
await().atMost(10, SECONDS).until(() -> {
// Check if a dependent service is ready
return true;
});
}
}
Startup
The startup of the application waits for the resource adapters: it is only complete once every resource adapter is started and every endpoint is activated.
The startup sequence
For each configured resource adapter, in order:
-
The
ResourceAdapterFactoryof its kind creates theResourceAdapter, theManagedConnectionFactoryand the connection manager of its pool. -
The resource adapter gets its own bootstrap context, cloned from the default one, and its own work manager, which runs its work on the Quarkus thread pool. Both are shut down when the resource adapter stops, which is why they are not shared.
-
A Vert.x worker verticle, named
jca-worker-pool-<name>and with a single thread, is deployed for the resource adapter. It invokespreStartupon the lifecycle listeners, thenResourceAdapter.start(BootstrapContext)(QIJ000001), thenpostStartup. -
Once that verticle is deployed, each endpoint of this resource adapter is activated (
QIJ000017), unless its activation spec is disabled withquarkus.ironjacamar.activation-spec."key".enabled=false.
The pool services are started along the way, independently of the resource adapters (QIJ000013, QIJ000015).
The shutdown is the mirror image: the endpoints are deactivated (QIJ000018), the resource adapter is stopped (QIJ000002) with preShutdown and postShutdown invoked around it, and its work manager and bootstrap context are released.
Because the startup waits for step 3, a resource adapter that is slow to start delays the startup of the whole application.
Vert.x logs a blocked thread warning when it takes longer than quarkus.ironjacamar.max-worker-execute-time, but it does not abort the start.
Failing fast, or starting degraded
By default, a resource adapter that fails to start, or an endpoint that cannot be activated, fails the startup of the application (QIJ000023, QIJ000011), rather than leaving it running without a working resource adapter.
Set quarkus.ironjacamar.fail-on-start-error to false for an application that must start anyway:
quarkus.ironjacamar.fail-on-start-error=false
The failure is then logged (QIJ000024), the endpoints of that resource adapter are not activated, and the application starts without it.
An endpoint that fails to be activated is logged too (QIJ000025), and does not fail the startup either.
The setting can be overridden per resource adapter, so that a critical resource adapter still fails the startup while an optional one does not:
quarkus.ironjacamar.fail-on-start-error=false (1)
quarkus.ironjacamar.critical.ra.fail-on-start-error=true (2)
| 1 | The application starts even when a resource adapter fails to start. |
| 2 | Except for the critical resource adapter, which must start. |
Which one to choose depends on what the application can still do without that resource adapter:
Keep the default when the application is useless without it. The failure then surfaces at deployment time, and an orchestrator restarts the pod rather than routing traffic to an application that cannot work.
Disable it when the resource adapter is optional, for instance one of several, or when serving the rest of the application matters more than consuming messages.
| A resource adapter that failed to start is not retried. The application runs without it until it is restarted, its endpoints stay inactive, and its connection factory, while still injectable, cannot be used. |
When the external system is merely slow to come up, waiting is usually better than either option: a ResourceAdapterLifecycleListener waiting for it in its preStartup, as in Listening to lifecycle events, delays the startup until the system is ready.
Startup and shutdown log messages
| Id | Level | Meaning |
|---|---|---|
|
INFO |
The resource adapter is starting. |
|
INFO |
An endpoint is being activated. |
|
INFO |
The Connection Validator, or the Idle Remover, is starting. |
|
exception |
The resource adapter failed to start, and failed the startup of the application. |
|
exception |
An endpoint could not be activated, and failed the startup of the application. |
|
ERROR |
The resource adapter failed to start, and the application started without it, as |
|
ERROR |
An endpoint could not be activated, and the application started anyway, as |
|
WARN |
No resource adapter kind is configured, the extension is disabled. |
|
INFO |
An endpoint is being deactivated. |
|
INFO |
The resource adapter is stopping. |
|
INFO |
The Connection Validator, or the Idle Remover, is stopping. |
Connection Pool Services
The extension automatically manages two background services that help maintain healthy connection pools: the Idle Remover and the Connection Validator.
Idle Remover
The Idle Remover periodically scans the connection pool and removes connections that have been idle for longer than the configured timeout. This helps free up resources on both the application and the external system.
The Idle Remover is enabled by default with a 30-minute timeout.
It will start automatically if any resource adapter has an idle-timeout-minutes value greater than 0.
To disable it, set the idle timeout to 0:
quarkus.ironjacamar.ra.cm.pool.config.idle-timeout-minutes=0
To configure a custom timeout (e.g., 15 minutes):
quarkus.ironjacamar.ra.cm.pool.config.idle-timeout-minutes=15
Connection Validator
The Connection Validator periodically checks the validity of connections in the pool in the background. Invalid connections are removed and replaced, ensuring that the application always gets working connections from the pool.
The Connection Validator is disabled by default.
It will start automatically when background-validation is set to true and background-validation-millis is set to a positive value.
To enable it:
quarkus.ironjacamar.ra.cm.pool.config.background-validation=true
quarkus.ironjacamar.ra.cm.pool.config.background-validation-millis=30000
To disable it (the default):
quarkus.ironjacamar.ra.cm.pool.config.background-validation=false
As an alternative to background validation, you can use validate-on-match to validate connections when they are borrowed from the pool.
This adds latency to each connection request but guarantees a valid connection without requiring a background thread.
|
Named Resource Adapters
When using Multiple Resource Adapters, each resource adapter can be configured independently:
quarkus.ironjacamar.main.ra.cm.pool.config.idle-timeout-minutes=15
quarkus.ironjacamar.other.ra.cm.pool.config.idle-timeout-minutes=0
Contributing endpoints from another extension
Extensions can take part in the endpoint activation at build time, typically to activate endpoints they generate themselves (for example from their own listener annotation).
This requires a dependency on io.quarkiverse.ironjacamar:quarkus-ironjacamar-deployment in the deployment module of your extension.
Three build items are involved:
ContainerCreatedBuildItem-
Produced for each configured resource adapter. Consume it to discover the deployed resource adapters, their
identifier()and theirkind(). ResourceEndpointBuildItem-
Registers an endpoint to activate. Use it for endpoint classes that are not annotated with
@ResourceEndpoint, which is the case of classes generated at build time, as those are not in the Jandex index when the endpoints are activated. ResourceEndpointIgnoredBuildItem-
Excludes endpoints from the automatic activation, for the endpoints your extension activates itself.
Activating a generated endpoint
@BuildStep
void contributeEndpoints(List<ContainerCreatedBuildItem> containers, (1)
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<RunTimeConfigurationDefaultBuildItem> configDefaults,
BuildProducer<ResourceEndpointBuildItem> resourceEndpoints) {
for (ContainerCreatedBuildItem container : containers) {
if (!"artemis".equals(container.kind())) { (2)
continue;
}
String endpointClassName = generateEndpoint(generatedBeans, container); (3)
configDefaults.produce(new RunTimeConfigurationDefaultBuildItem(
"quarkus.ironjacamar.activation-spec.my-activation-spec.config.destination", "MyQueue")); (4)
resourceEndpoints.produce(new ResourceEndpointBuildItem(endpointClassName,
"my-activation-spec", container.identifier())); (5)
}
}
| 1 | The configured resource adapters, which is how you discover the container identifiers to activate the endpoint in. |
| 2 | The kind declared by the @ResourceAdapterKind annotation of the ResourceAdapterFactory, useful to only handle the resource adapters your extension supports. |
| 3 | Your extension owns the endpoint class and must make it an unremovable bean. Reflective access to its methods is registered by this extension. |
| 4 | (Optional) The activation spec configuration can be given defaults, so that the application only overrides what it needs. |
| 5 | The activation spec configuration key is the same one the @ResourceEndpoint annotation uses, and the container id tells which resource adapter activates the endpoint. |
The container id is optional when a single resource adapter is configured, but it is required as soon as there is more than one, and it must always match a configured resource adapter. Otherwise the build fails, instead of silently never consuming any message.
Taking over an annotated endpoint
An extension that activates @ResourceEndpoint annotated classes itself tells this extension to leave them alone with a Predicate<ClassInfo>:
private static final DotName MY_LISTENER = DotName.createSimple(MyListener.class);
@BuildStep
void ignoreEndpointsHandledByThisExtension(BuildProducer<ResourceEndpointIgnoredBuildItem> ignoredEndpoints) {
ignoredEndpoints.produce(new ResourceEndpointIgnoredBuildItem(
classInfo -> classInfo.hasAnnotation(MY_LISTENER))); (1)
}
| 1 | The predicate is evaluated against every class annotated with @ResourceEndpoint, here matching the ones having a @MyListener method.
It is also evaluated against the endpoints contributed through a ResourceEndpointBuildItem, as long as their class is in the index. |
The ignored classes are still registered as beans, only their activation is skipped.
They also don’t need the @Identifier annotation required by Multiple Resource Adapters, since your extension is the one deciding where they are activated.
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
|---|---|---|
Whether IronJacamar (pool) metrics are published in case a metrics extension is present. This is a global setting and is not specific to a resource adapter. Environment variable: |
boolean |
|
The maximum amount of time the worker thread can be blocked. If not specified it assumes the same value as defined by the Environment variable: |
|
|
Whether a resource adapter that fails to start, or an endpoint that cannot be activated, fails the startup of the application. When set to It can be overridden for a given resource adapter with Environment variable: |
boolean |
|
The kind of resource adapter. Environment variable: |
string |
|
Enable pool metrics collection. If unspecified, collecting metrics will be enabled by default if a metrics extension is active. Environment variable: |
boolean |
|
The configuration for this resource adapter Environment variable: |
Map<String,String> |
|
The transaction support level for the Connection Manager See the TransactionSupportLevel Javadoc for more information Environment variable: |
|
|
The number of times to retry the allocation of a connection Environment variable: |
int |
|
The time to wait between retries of the allocation of a connection Environment variable: |
|
|
The transaction timeout for the XAResource Environment variable: |
|
|
The flush strategy for the Connection Manager Environment variable: |
|
|
Whether the connection manager is sharable Environment variable: |
boolean |
|
Whether the connection manager should enlist connections Environment variable: |
boolean |
|
Whether the connection manager should be connectable Environment variable: |
boolean |
|
Whether the connection manager should track connections Environment variable: |
boolean |
|
Whether the connection manager should use CCM Environment variable: |
boolean |
|
Whether the connection manager should use interleaving Environment variable: |
boolean |
|
Whether the connection manager should use same RM override Environment variable: |
boolean |
|
Whether the connection manager should wrap the XAResource Environment variable: |
boolean |
|
Whether the connection manager should pad the XID Environment variable: |
boolean |
|
The recovery username for the Connection Manager Environment variable: |
string |
|
The recovery password for the Connection Manager Environment variable: |
string |
|
The recovery security domain for the Connection Manager Environment variable: |
string |
|
The pool strategy Environment variable: |
|
|
Minimum size of the pool Environment variable: |
int |
|
Initial size of the pool Environment variable: |
int |
|
Maximum size of the pool Environment variable: |
int |
|
Blocking timeout Environment variable: |
|
|
Idle timeout period. Default 30 mins Environment variable: |
int |
|
Validate on match validation Environment variable: |
boolean |
|
Background validation Environment variable: |
boolean |
|
Background validation - millis Environment variable: |
long |
|
Prefill pool Environment variable: |
boolean |
|
Strict minimum, default false Environment variable: |
boolean |
|
Do we want to immediately break when a connection cannot be matched and not evaluate the rest of the pool? Environment variable: |
boolean |
|
Fairness of semaphore permits, default true Environment variable: |
boolean |
|
Whether the pool is sharable Environment variable: |
boolean |
|
Should the pool be created without a separate pool for non-transactional connections? Environment variable: |
boolean |
|
Whether this resource adapter failing to start, or one of its endpoints failing to be activated, fails the startup of the application. Defaults to Environment variable: |
boolean |
|
Enable this activation spec. If the activation spec is disabled, endpoints configured to use this activation spec will be not activated. Environment variable: |
boolean |
|
The configuration for this resource adapter Environment variable: |
Map<String,String> |
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|