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;

@JMSDestinationDefinitions(
        value = {
            @JMSDestinationDefinition(
                    name = "java:/queue/duke-queue",
                    interfaceName = "javax.jms.Queue",
                    destinationName = "duke"
            ),
            @JMSDestinationDefinition(
                    name = "java:/topic/duke-topic",
                    interfaceName = "javax.jms.Topic",
                    destinationName = "duke-topic"
            )
        }
)
@Startup
@Singleton
public class Initializer {
     
    @Resource(lookup = "java:/queue/duke-queue")
    private Queue queue;      
    
    @Produces
    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

Comments:

why this not working simple out of the box???

I'm using a clean payara 4 (and i have also tested in payara 5) application server, without any kind customization.

I'm allways getting the exception:

Caused by: javax.naming.NamingException: Lookup failed for 'jms/queue/duke-queue' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/io.costax.payments.boundary.Initializer/queue} [Root exception is javax.naming.NameNotFoundException: queue]

Posted by costa on July 01, 2018 at 02:05 PM CEST #

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