Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Connect JavaEE to the cloud with JCA by Steve Millidge
1. Connect Java EE to the Cloud
With JCA
Steve Millidge
(Founder Payara)
2. Agenda
• Payara Cloud Connectors
• What is JCA
• Fundamental Principals
• Relationship to MDBs
• Building Inbound Adapter
• Building Outbound Adapter
• Demo
3. What I wanted to do (Demo at the booth)
Clustered
CDI
Events
HumidityQ
Payara Micro Cluster
on Azure
JCA
Cloud
Connector
WebSocket
Web App
EJB Timer
Humidity
MDB
Grid Loader
Humidity
REST
Services
4. Cloud Connectors Project
Cloud Connectors
Deliver standard JCA connectors for Cloud Messaging
Kafka, Amazon SQS, Azure SB, MQTT
Payara Micro – Supports JCA Inbound/OutBound
JMS and JCA MDB
https://github.com/payara/Cloud-Connectors
5. What is the Java EE Connector
Architecture
The Java EE Connector
architecture defines a standard
architecture for connecting the
Java EE platform to heterogenous
Enterprise Information Systems
(EIS).
Source: JSR 322 Specification
6. Java Connector Architecture (JCA)
• Originally envisaged for Enterprise Application
Integration (EAI)
• 16 years Old JSR-16 September 2001
• Part of Java EE 8
• Last updated for Java EE 7 – May 2013
• Huge Specification – 592 pages!
• Pretty Generic – First look massively complex.
• MDBs and JDBC connection pools often JCA
7. A Pluggable Integration Component
Application Server
ResourceAdapter
Enterprise
Information
System
8. What does this look like
Application Server
Resource Adapter (RAR)
Inbound
Outbound
Connection
Pools
Thread
Pools
Message
Inflow
Deployment
Common API Layer
9. Key Contracts in JCA
• Lifecycle Management
• Configuration, Deployment, Boot, Shutdown
• Connection Management
• Connection creation, pooling destruction
• Work Management
• Threading
• Message Inflow
• Inbound Asynch Messaging
• Others not covered in the talk
• Security, Transactions, CCI
10. Key Java Beans
All Beans can use Bean Validation for setting their Properties.
Further configured via @ConfigProperty
Resource
Adapter
Activation
Spec
Managed Connection
Factory
Administered
Object
Java Beans inherit configuration from the Resource Adapter
11. Building a JCA Connector (Our Scenario)
Payara Micro Payara Micro
Resource Adapter (RAR)
Inbound
Outbound
Common API Layer
Resource Adapter (RAR)
Inbound
Outbound
Common API Layer
MQTT Topic
Outbound Inbound
12. Outbound Communication (Key Concepts)
Public API
Connection
Connection
Factory
RAR Internal Classes
ConnectionImpl
Connection
FactoryImpl
Managed
Connection
Managed
Connection
Factory
1*
11
Application Server
Connection
Manager
13. Key Class Responsibilities
Public API
Connection Factory
Application Developer
uses this to create
connections
Creates Connections using
the Application Server
Provided Connection
Manager
Connection
Application Developer
uses this api to interact
with the EIS
Connection Manager
Generic class provided by
the application server
runtime.
Interacts with your
Managed Connection
Factory to actually create
Physical Connections to
the EIS
Pools Managed
Connections using
Application Server Pooling
Application Server
Managed Connection
Factory
Creates Physical
connections to the EIS.
Interacts with your
Managed Connection
Factory to actually create
Physical Connections to
the EIS
Managed Connection
Is the connection to the
EIS
Resource Adapter
14. What Does Our Code Look Like?
public interface MQTTConnection extends AutoCloseable {
/**
* Publish a message on the MQTT topic
* @param topic Name of the topic to publish the message
* @param payload Byte array to use as message payload
* @param qos Quality of Service valid values are 0,1,2
* @param retained Whether or not this message should be retained by the server.
* @throws javax.resource.ResourceException
*/
public void publish(String topic, byte payload[], int qos, boolean retained) throws
ResourceException;
/**
* Publish a message on the MQTT topic
* @param topic
* @param message
* @throws ResourceException
*/
public void publish (String topic, MqttMessage message) throws
ResourceException;
15. /**
*
* @author Steve Millidge (Payara Foundation)
*/
public interface MQTTConnectionFactory {
public MQTTConnection getConnection();
}
19. Inbound Communication Key Concepts
Public API
Listener
Interface
Message
Annotations
RAR Internal Classes
Activation
Spec
Resource
Adapter
Work
Application Server
Bootstrap
Context
Message Endpoint
Factory
Your
EIS integration
Class
Work Manager
20. Process of Boot and receipt of Messages
1. Resource Adapter start called with BootstrapContext
2. Application Server detects MDBs
3. Calls Resource Adapter for Each MDB passing in the
Endpoint Factory and Activation Spec
4. Resource Adapter creates an instance of your integration
class passing in the Activation Spec and Endpoint Factory
5. Your integration class connects to the EIS
Receipt of messages
1. When message received from the EIS
2. Schedule a unit of Work with the WorkManager
3. Unit of Work uses Endpoint Factory to create an endpoint
4. Calls Method on the endpoint
5. Releases the Endpoint
21. @Connector (Defines Resource Adapter)
@Connector(
displayName = "MQTT Resource Adapter",
vendorName = "Payara Services Limited",
version = "1.0" )
public class MQTTResourceAdapter implements
ResourceAdapter {
22. @ActivationSpec defined MDB Detection
@Activation(messageListeners = MQTTListener.class)
public class MQTTActivationSpec implements
ActivationSpec {
Also defines configuration Properties