package org.cucina.email;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.support.destination.DestinationResolver;
import org.springframework.jms.support.destination.JndiDestinationResolver;


/**
 * JAVADOC for Class Level
 *
 * @author $Author: $
 * @version $Revision: $
  */
@SpringBootApplication
@EnableJms
public class EmailApplication {
    /**
     * JAVADOC Method Level Comments
     *
     * @param args JAVADOC.
     *
     * @throws Exception JAVADOC.
     */
    public static void main(String[] args)
        throws Exception {
        SpringApplication.run(EmailApplication.class, args);
    }

    /**
     * JAVADOC Method Level Comments
     *
     * @return JAVADOC.
     */
    @Bean
    public DestinationResolver destinationResolver() {
        //TODO provide optional mapping in properties 
        JndiDestinationResolver destinationResolver = new JndiDestinationResolver();

        destinationResolver.setFallbackToDynamicDestination(true);

        return destinationResolver;
    }

    /**
     * JAVADOC Method Level Comments
     *
     * @return JAVADOC.
     */
    @Bean
    public DefaultJmsListenerContainerFactory myJmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

        factory.setDestinationResolver(destinationResolver());
        factory.setConcurrency("5");

        return factory;
    }
}

@@ -20,16 +20,167 @@
 email;%0A%0A
+import javax.jms.Destination;%0Aimport javax.jms.JMSException;%0Aimport javax.jms.Session;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -343,16 +343,65 @@
 n.Bean;%0A
+import org.springframework.core.env.Environment;%0A
 import o
@@ -642,20 +642,23 @@
 ination.
-Jndi
+Dynamic
 Destinat
@@ -820,24 +820,77 @@
 plication %7B%0A
+    @Autowired%0A    private Environment environment;%0A%0A
     /**%0A    
@@ -1255,138 +1255,191 @@
 c De
-stinationResolver destinationResolver() %7B%0A        //TODO provide optional mapping in properties %0A        JndiDestinationResolver d
+faultJmsListenerContainerFactory myJmsListenerContainerFactory() %7B%0A        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();%0A%0A        factory.setD
 esti
@@ -1456,20 +1456,10 @@
 lver
- = new JndiD
+(d
 esti
@@ -1474,18 +1474,18 @@
 solver()
+)
 ;
-%0A
 %0A       
@@ -1489,102 +1489,60 @@
     
-destinationResolver.setFallbackToDynamicDestination(true);%0A%0A        return destinationResolver
+factory.setConcurrency(%225%22);%0A%0A        return factory
 ;%0A  
@@ -1638,299 +1638,579 @@
     
-@Bean%0A    public DefaultJmsListenerContainerFactory myJmsListenerContainerFactory() %7B%0A        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();%0A%0A        factory.setDestinationResolver(destinationResolver());%0A        factory.setConcurrency(%225%22);%0A%0A
+private DestinationResolver destinationResolver() %7B%0A        return new DestinationResolver() %7B%0A                private DestinationResolver dynamicDestinationResolver = new DynamicDestinationResolver();%0A%0A                @Override%0A                public Destination resolveDestinationName(Session session, String destinationName,%0A                    boolean pubSubDomain)%0A                    throws JMSException %7B%0A                    String dname = environment.getProperty(%22jms.destination.%22 + destinationName,%0A                            destinationName);%0A%0A       
         
 retu
@@ -2201,36 +2201,170 @@
             
+     
 return 
-factory
+dynamicDestinationResolver.resolveDestinationName(session, dname,%0A                        pubSubDomain);%0A                %7D%0A            %7D
 ;%0A    %7D%0A%7D%0A

resolve destination via properties