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

  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way
  • Beans Custom Validation Constraints
  • How to Embed a jBPM Process in a Java EE Application

Trending

  • Unraveling Lombok's Code Design Pitfalls: Exploring Encapsulation Issues
  • Best Practices for Writing Clean Java Code
  • Log Analysis Using grep
  • Demystifying Enterprise Integration Patterns: Bridging the Gap Between Systems
  1. DZone
  2. Coding
  3. Java
  4. Automated Provisioning of JMS Resources in Java EE 7

Automated Provisioning of JMS Resources in Java EE 7

See exactly what has changed in Java EE 7 that allows JMS resources to be automatically deployed.

Abhishek Gupta user avatar by
Abhishek Gupta
CORE ·
Dec. 05, 15 · Tutorial
Like (4)
Save
Tweet
Share
5.94K Views

Join the DZone community and get the full member experience.

Join For Free

JMS 2.0 (part of the Java EE 7 Platform) introduced lots of nice features. One of these was the ability to declare JMS resources for automatic deployment.

Pre Java EE 7

  • Inject Connection Factory using @Resource
  • Lookup Destination (Queue/Topic) using @Resource
  • Pull out the Session object and use it to create the Message, Message Producer and send the message

Most importantly, you had to make sure that the resources i.e. the Connection Factory and the physical destinations were configured in your application server in advance.

In the Java EE 7 Era…

You can leverage JMS 2.0 goodies:

  • Use injected JMS Context (in most of the cases) to ease the sending process with less boilerplate code
  • Most importantly, you can declaratively configure auto provisioning of JMS Resources using annotations or deployment descriptors

Let’s look at the new JMS 2.0 annotations in action. You can also pick up this Maven project on Github and deploy it in your favourite IDE.

@JMSConnectionFactoryDefinition, @JMSConnectionFactoryDefinitions

Used to declare one or more connection factories.

@JMSDestinationDefinition, @JMSDestinationDefinitions

Used to declare one or more physical destinations (queues or topics).

@Stateless
@JMSConnectionFactoryDefinition(name = "java:comp/env/AutoDeloyedJMSConf")
@JMSDestinationDefinition(interfaceName = "javax.jms.Queue", name  = "java:comp/env/AutoDeloyedJMSQueue")
public class Service {
    //usage omitted...
}

@JMSConnectionFactoryDefinitions({
    @JMSConnectionFactoryDefinition(
       name="java:comp/env/AutoDeloyedJMSConf1"
    ),
    @JMSConnectionFactoryDefinition(
       name="java:comp/env/AutoDeloyedJMSConf2"
    ) 
})
@JMSDestinationDefinitions({
    @JMSDestinationDefinition(
       name="java:comp/env/AutoDeloyedJMSQueue1",
       interfaceName = "javax.jms.Queue",
    ),
    @JMSDestinationDefinition(
       name="java:comp/env/AutoDeloyedJMSQueue2",
       interfaceName = "javax.jms.Queue",
    ) 
})
@Stateless
public class AnotherService {
    //usage omitted...
}

Oh and you can also use XML:

//snippet only..

<jms-connection-factory>
   <name>java:comp/env/AutoDeloyedJMSConf3</name>
</jms-connection-factory>

<jms-destination>
   <name>java:comp/env/AutoDeloyedJMSQueue3</name>
   <interfaceName>javax.jms.Queue</interfaceName>
</jms-destination>

These can be a part of the web deployment descriptor (web.xml) or the EJB deployment descriptor (ejb-jar.xml).

Possible Variations

There are several ways to use this feature:

  • Declare your JMS resources using a @Startup powered @Singleton EJB
  • You can also declare it on a Servlet or any CDI managed bean for that matter
@Singleton
@Startup
@JMSDestinationDefinition(interfaceName = "javax.jms.Queue", name  = "java:comp/env/EmailQueue")
public class EmailQueueAutoProvisionService {

    @PostConstruct
    public void confirm(){
        System.out.println("Email Queue configured");
    }
}

What’s the Point of All This?

The container/Java EE application server makes sure that the JMS artefacts are available to your application logic on-demand.

  • It’s valuable in PaaS, microservices, dockerized and any other environment which heavily leverage automated deployments
  • Good for automated testing
  • It’s one less item to think about and configure!

Additional Resources

  • JMS 2.0 specification document
  • They have a twitter account too !
  • The Aquarium Blog for all things Java EE


Java EE Java (programming language)

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

Opinions expressed by DZone contributors are their own.

Related

  • Java EE 6 Pet Catalog with GlassFish and MySQL
  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way
  • Beans Custom Validation Constraints
  • How to Embed a jBPM Process in a Java EE Application

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: