Auto-Creating JMS Destinations With JMS 2.0 and Java EE 7

Java EE 7 and JMS 2.0 introduced the @JMSDestinationDefinitions annotation which allows automatic creation of JMS resources at deployment time:

import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.jms.JMSDestinationDefinition;
import javax.jms.JMSDestinationDefinitions;

        value = {
                    name = "java:/queue/duke-queue",
                    interfaceName = "javax.jms.Queue",
                    destinationName = "duke"
                    name = "java:/topic/duke-topic",
                    interfaceName = "javax.jms.Topic",
                    destinationName = "duke-topic"
public class Initializer {
    @Resource(lookup = "java:/queue/duke-queue")
    private Queue queue;      
    public Queue expose() {
        return this.queue;

The conveniently created JMS destination (Queue or Topic) can be immediately exposed to dependency injection with the CDI @Produces annotation.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting

NEW online workshop: Web Components training (online)

Airport MUC workshops: Java EE 8, Java 9: Bootstrap, Effective, Architectures, Single Page Apps, Progressive Web Apps, HTML 5, ES 6, CSS 3 and Microservices

Podcast: and newsletter:

A book about rethinking Java EE Patterns


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments