DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Spring Beans With Auto-Generated Implementations: How-To
  • Keep Your Application Secrets Secret
  • Spring, IoC Containers, and Static Code: Design Principles
  • Protect Your Invariants!

Trending

  • How TIBCO Is Evolving Integration for the Multi-Cloud Era
  • LLMs for Bad Content Detection: Pros and Cons
  • Database Monitoring: Key Metrics and Considerations
  • Securing Your Applications With Spring Security
  1. DZone
  2. Coding
  3. Java
  4. MDB != JMS and vice-versa

MDB != JMS and vice-versa

Abhishek Gupta user avatar by
Abhishek Gupta
CORE ·
Jan. 26, 15 · Interview
Like (0)
Save
Tweet
Share
3.96K Views

Join the DZone community and get the full member experience.

Join For Free

Basics

  • A Message Driven Bean (further referred to as MDB) is just another EJB like Stateless, Stateful or a Singleton. It’s specified using the @MessageDriven annotation.
  • MDBs are used for asynchronous message processing
  • They are similar to Stateless EJBs since both of them are pooled by the EJB container
  • However they differ from Stateless EJBs since MDBs cannot be directly accessed by a client. Only the container calls them in response to a message sent by the client to an endpoint which the MDB is listening to.

Commonly used pattern for MDB

  • MDBs are generally used along with JMS (Java Message Service API)
  • A MDB is configured to listen to a JMS destination using @ActivationConfigProperty, implements the javax.jms.MessageListener interface and provides the business logic (message processing) in the onMessage method
  • A component sends a Message to the JMS destination (end point). This is not a synchronous process (as already mentioned above). The message firing method returns immediately and the container takes care of calling the MDB configured to listen that particular JMS destination
jms-based-mdb

JMS based MDB

MDB myth

  • MDBs are not part of the JMS spec or coupled with JMS by any means – this is a misconception.
  • MDB are pooled beans which can process messages in an async fashion and can listen to any end point including a JMS queue or destination (most generally seen).
  • In fact, this has been the case since EJB 2.1 and is made possible by the JCA (Java Connector Architecture) spec

What’s JCA ?

  • On a high level, JCA enables Java EE servers to interact with external systems e.g. legacy enterprise information sources etc via a standard SPI (not dealing with intricate JCA details here)
  • One can use the JCA standard interfaces to build a Resource Adapter (RAR file) for a specific system
  • JCA provides contracts for two-way communication (inbound and outbound) b/w the Java EE container and the external system – the implementation for which needs to be present withing the Resource Adapter itself
jca-architecture

Courtesy: JCA Specification document

How does JCA enable the concept of Generic MDBs ?

  • JCA defines MDB specific features
  • Just like in the case of a JMS based MDB, a JCA based MDB also needs to implement an interface and define activation properties (both are specific to the JCA Resource Adapter implementation)
  • The external system sends a message which the Resource Adapter accepts via its implementation of the inbound JCA contract and this message is relayed to an internal endpoint (this is again specific to the JCA adapter implementation)
  • The MDB registered to this endpoint kicks in an executes the business logic on the received message
jca-based-mdb

JCA based MDB

End result

An external system sending messages to a Java EE container using a standard interface (JCA) while the JCA implementation takes care of delivering it to the appropriate endpoint which further delivers it to the registered MDB

Thing to notice is that this is completely portable across Java EE servers since, EJB spec vendors have to support JCA based MDBs.

Further reading

  • JCA specification
  • JMS specification
  • EJB specification
Java EE Business logic Implementation Container Two-way communication Interface (computing) Java (programming language) Bean (software) Processing Spring Framework

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Spring Beans With Auto-Generated Implementations: How-To
  • Keep Your Application Secrets Secret
  • Spring, IoC Containers, and Static Code: Design Principles
  • Protect Your Invariants!

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: