Connect Java EE to the Cloud
With JCA
Steve Millidge
(Founder Payara)
Agenda
• Payara Cloud Connectors
• What is JCA
• Fundamental Principals
• Relationship to MDBs
• Building Inbound Adapter
• Building Outbound Adapter
• Demo
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
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
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
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
A Pluggable Integration Component
Application Server
ResourceAdapter
Enterprise
Information
System
What does this look like
Application Server
Resource Adapter (RAR)
Inbound
Outbound
Connection
Pools
Thread
Pools
Message
Inflow
Deployment
Common API Layer
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
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
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
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
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
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;
/**
*
* @author Steve Millidge (Payara Foundation)
*/
public interface MQTTConnectionFactory {
public MQTTConnection getConnection();
}
Annotating Managed Connection Factory
/**
*
* @author Steve Millidge (Payara Foundation)
*/
@ConnectionDefinition (
connection = MQTTConnection.class,
connectionImpl = MQTTConnectionImpl.class,
connectionFactory = MQTTConnectionFactory.class,
connectionFactoryImpl = MQTTConnectionFactoryImpl.class
)
public class MQTTManagedConnectionFactory implements
ManagedConnectionFactory, Serializable {
@ConfigProperty
• Defines what Configuration is available
• Supports bean Validaion
• Types Valid for
• Resource Adapter
• Managed Connection Factory
• Administered Object
• Activation Spec
Outbound Code Walkthrough
https://github.com/payara/Cloud-
Connectors/tree/master/MQTT/MQTTJCAAPI/src/main/java/fish/payara/cloud/connectors
/mqtt/api/outbound
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
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
@Connector (Defines Resource Adapter)
@Connector(
displayName = "MQTT Resource Adapter",
vendorName = "Payara Services Limited",
version = "1.0" )
public class MQTTResourceAdapter implements
ResourceAdapter {
@ActivationSpec defined MDB Detection
@Activation(messageListeners = MQTTListener.class)
public class MQTTActivationSpec implements
ActivationSpec {
Also defines configuration Properties
Inbound Code Walkthrough
https://github.com/payara/Cloud-
Connectors/tree/master/MQTT/MQTTJCAAPI/src/main/java/fish/payara/cloud/connectors/
mqtt/api/inbound
Putting it all together
DEMO
Key Take Aways
MDBs are NOT just JMS
Payara Cloud Connectors Not just Payara
2 Sides to a JCA Adapter
Building JCA Adapters not Complex
Questions

Connect JavaEE to the cloud with JCA by Steve Millidge

  • 1.
    Connect Java EEto the Cloud With JCA Steve Millidge (Founder Payara)
  • 2.
    Agenda • Payara CloudConnectors • What is JCA • Fundamental Principals • Relationship to MDBs • Building Inbound Adapter • Building Outbound Adapter • Demo
  • 3.
    What I wantedto 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 CloudConnectors 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 theJava 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 IntegrationComponent Application Server ResourceAdapter Enterprise Information System
  • 8.
    What does thislook like Application Server Resource Adapter (RAR) Inbound Outbound Connection Pools Thread Pools Message Inflow Deployment Common API Layer
  • 9.
    Key Contracts inJCA • 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 AllBeans 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 JCAConnector (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 (KeyConcepts) 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 PublicAPI 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 OurCode 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 SteveMillidge (Payara Foundation) */ public interface MQTTConnectionFactory { public MQTTConnection getConnection(); }
  • 16.
    Annotating Managed ConnectionFactory /** * * @author Steve Millidge (Payara Foundation) */ @ConnectionDefinition ( connection = MQTTConnection.class, connectionImpl = MQTTConnectionImpl.class, connectionFactory = MQTTConnectionFactory.class, connectionFactoryImpl = MQTTConnectionFactoryImpl.class ) public class MQTTManagedConnectionFactory implements ManagedConnectionFactory, Serializable {
  • 17.
    @ConfigProperty • Defines whatConfiguration is available • Supports bean Validaion • Types Valid for • Resource Adapter • Managed Connection Factory • Administered Object • Activation Spec
  • 18.
  • 19.
    Inbound Communication KeyConcepts 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 Bootand 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 ResourceAdapter) @Connector( displayName = "MQTT Resource Adapter", vendorName = "Payara Services Limited", version = "1.0" ) public class MQTTResourceAdapter implements ResourceAdapter {
  • 22.
    @ActivationSpec defined MDBDetection @Activation(messageListeners = MQTTListener.class) public class MQTTActivationSpec implements ActivationSpec { Also defines configuration Properties
  • 23.
  • 24.
    Putting it alltogether DEMO
  • 25.
    Key Take Aways MDBsare NOT just JMS Payara Cloud Connectors Not just Payara 2 Sides to a JCA Adapter Building JCA Adapters not Complex
  • 26.