Slide 1

Slide 1 text

Introduction to 
 JCA and MDB HASUNUMA Kenji GlassFish Users Group Japan [email protected] Twitter: @khasunuma

Slide 2

Slide 2 text

What's JCA? • JCA (Java Connector Architecture) brings integration between systems • JCA is also base of Java EE servers • Almost Java EE developer have been used JCA

Slide 3

Slide 3 text

JCA Overview External System 
 (e.g. EIS) Java EE Resource Adapter (.rar) Web app. (.war) Outbound Inbound Java Connector 
 Architecture (JCA)

Slide 4

Slide 4 text

Contracts (1/2) since JCA 1.0 (J2EE 1.3) • Connection management (Connection pooling) • Transaction management (w/JTA) • Security management (w/JAAS)

Slide 5

Slide 5 text

Contracts (2/2) since JCA 1.5 (J2EE 1.4) • Life cycle management • Work management • Transaction inflow management • Message inflow management

Slide 6

Slide 6 text

Application Architecture ConnectionFactory EJB Connection External System getConnection JNDI lookup Outbound Inbound I/F

Slide 7

Slide 7 text

Application c.f. JMS ConnectionFactory EJB Connection JMS broker getConnection JNDI lookup Outbound Inbound JMS

Slide 8

Slide 8 text

Application c.f. JDBC DataSource EJB Connection RDBMS getConnection JNDI lookup SQL JDBC

Slide 9

Slide 9 text

Programming w/JCA • Many cases, JCA resource adapter is provided by each systems • Recently JCA is mainly used to manage message inflow • In JCA 1.7 (Java EE 7/8), properties are set by annotations

Slide 10

Slide 10 text

Outbound @ConnectionFactoryDefinition( name = "java:comp/env/OutboundConnectionFactory", interfacename = com.example.jca.OutboundConnectionFactory, resourceAdapter = "some-rar", ... ) @Stateless public class ExampleMessageSender { @Resource(lookup = "java.comp/env/OutboundConnectionFactory") OutboundConnectionFactory factory; public void send(...) { try (OutboundConnection conn = factory.createConnection()) { ... } catch (Exception e) { ... } } }

Slide 11

Slide 11 text

Attention • Session Bean SHOULD NOT be used to listen messages • SHOULD use Message Driven Bean (MDB) to listen messages

Slide 12

Slide 12 text

What's MDB? • EJB specified for listening messages • Have a callback method and handle inbound messages provided by JCA • MDB adapts both async and sync communication

Slide 13

Slide 13 text

Inbound @MessageDriven( activationConfig = { @ActivationConfigProperty(propertyName = ..., propertyValue = ...), ... } ) public class ExampleMessageListener implements MessageListener { public void onMessage(Message message) { ... } } Callback method invoked by the Resource Adapter

Slide 14

Slide 14 text

Use case: Payara Micro • Payara Micro connects other systems on cloud via JCA adapters; • Apache Kafka • MQTT (Mosquitto, etc.) • Amazon SQS • Microsoft Azure Service Bus

Slide 15

Slide 15 text

Why MQ? • System/service requirements are different each other • Now various systems/services are integrated on cloud platforms • MQ (i.g. Async) often resolves impedance matching between each systems/services

Slide 16

Slide 16 text

JCA is ... • JCA (Java Connector Architecture) brings integration between systems • JCA is also base of Java EE servers, e.g. JMS, JDBC • Almost Java EE developer have been used JCA as JDBC data source

Slide 17

Slide 17 text

Introduction to JCA and MDB HASUNUMA Kenji GlassFish Users Group Japan [email protected] Twitter: @khasunuma