<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    在SPRING BOOT中使用多JMS CONNECTION

    使用自定義CONNECTION FACTORY,這樣會(huì)覆蓋SPRING 的AUTO CONFIGURATION。

    ActiveMQConnectionFactoryFactory.java
    import java.lang.reflect.InvocationTargetException;
    import java.util.Collections;
    import java.util.List;

    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryCustomizer;
    import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties;
    import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties.Packages;
    import org.springframework.util.Assert;
    import org.springframework.util.StringUtils;


    /**
     * Factory to create a {
    @link ActiveMQConnectionFactory} instance from properties defined
     * in {
    @link SecondaryActiveMQProperties}.
     *
     * 
    @author Phillip Webb
     * 
    @author Venil Noronha
     
    */
    class ActiveMQConnectionFactoryFactory {

        private static final String DEFAULT_EMBEDDED_BROKER_URL = "vm://localhost?broker.persistent=false";

        private static final String DEFAULT_NETWORK_BROKER_URL = "tcp://localhost:61616";

        private final ActiveMQProperties properties;

        private final List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers;

        ActiveMQConnectionFactoryFactory(ActiveMQProperties properties,
                List<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
            Assert.notNull(properties, "Properties must not be null");
            this.properties = properties;
            this.factoryCustomizers = (factoryCustomizers != null) ? factoryCustomizers : Collections.emptyList();
        }

        public <T extends ActiveMQConnectionFactory> T createConnectionFactory(Class<T> factoryClass) {
            try {
                return doCreateConnectionFactory(factoryClass);
            }
            catch (Exception ex) {
                throw new IllegalStateException("Unable to create " + "ActiveMQConnectionFactory", ex);
            }
        }

        private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(Class<T> factoryClass) throws Exception {
            T factory = createConnectionFactoryInstance(factoryClass);
            if (this.properties.getCloseTimeout() != null) {
                factory.setCloseTimeout((intthis.properties.getCloseTimeout().toMillis());
            }
            factory.setNonBlockingRedelivery(this.properties.isNonBlockingRedelivery());
            if (this.properties.getSendTimeout() != null) {
                factory.setSendTimeout((intthis.properties.getSendTimeout().toMillis());
            }
            Packages packages = this.properties.getPackages();
            if (packages.getTrustAll() != null) {
                factory.setTrustAllPackages(packages.getTrustAll());
            }
            if (!packages.getTrusted().isEmpty()) {
                factory.setTrustedPackages(packages.getTrusted());
            }
            customize(factory);
            return factory;
        }

        private <T extends ActiveMQConnectionFactory> T createConnectionFactoryInstance(Class<T> factoryClass)
                throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
            String brokerUrl = determineBrokerUrl();
            String user = this.properties.getUser();
            String password = this.properties.getPassword();
            if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
                return factoryClass.getConstructor(String.class, String.class, String.class).newInstance(user, password,
                        brokerUrl);
            }
            return factoryClass.getConstructor(String.class).newInstance(brokerUrl);
        }

        private void customize(ActiveMQConnectionFactory connectionFactory) {
            for (ActiveMQConnectionFactoryCustomizer factoryCustomizer : this.factoryCustomizers) {
                factoryCustomizer.customize(connectionFactory);
            }
        }

        String determineBrokerUrl() {
            if (this.properties.getBrokerUrl() != null) {
                return this.properties.getBrokerUrl();
            }
            if (this.properties.isInMemory()) {
                return DEFAULT_EMBEDDED_BROKER_URL;
            }
            return DEFAULT_NETWORK_BROKER_URL;
        }
    }

    TwinJmsConnectionFactoryConfiguration.java
    import java.util.stream.Collectors;

    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
    import org.springframework.beans.factory.ObjectProvider;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
    import org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryFactory;
    import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryCustomizer;
    import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.context.annotation.Profile;


    @Configuration
    @Profile({"local"})
    public class TwinJmsConnectionFactoryConfiguration {

        @Bean
        @ConfigurationProperties(prefix = "spring.activemq.primary")
        public ActiveMQProperties primaryActiveMQProperties() {
            return new ActiveMQProperties();
        }
        
        @Bean(destroyMethod = "stop")
        @Primary
        @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
        public JmsPoolConnectionFactory connectionFactory(ActiveMQProperties primaryActiveMQProperties,
                ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(primaryActiveMQProperties,
                    factoryCustomizers.orderedStream().collect(Collectors.toList()))
                    .createConnectionFactory(ActiveMQConnectionFactory.class);
            return new JmsPoolConnectionFactoryFactory(primaryActiveMQProperties.getPool())
                    .createPooledConnectionFactory(connectionFactory);
        }
        
        ////////////////////////////////////////////////////////////////////////////////
        @Bean
        @ConfigurationProperties(prefix = "spring.activemq.sescond")
        public ActiveMQProperties sescondActiveMQProperties() {
            return new ActiveMQProperties();
        }
        
        @Bean(destroyMethod = "stop")
        @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
        public JmsPoolConnectionFactory sescondPooledJmsConnectionFactory(ActiveMQProperties sescondActiveMQProperties,
                ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(sescondActiveMQProperties,
                    factoryCustomizers.orderedStream().collect(Collectors.toList()))
                    .createConnectionFactory(ActiveMQConnectionFactory.class);
            return new JmsPoolConnectionFactoryFactory(sescondActiveMQProperties.getPool())
                    .createPooledConnectionFactory(connectionFactory);
        }
        
    }


    posted on 2020-03-19 09:45 paulwong 閱讀(622) 評(píng)論(0)  編輯  收藏 所屬分類: JMS

    主站蜘蛛池模板: www免费插插视频| 日韩在线播放全免费| 国产成人精品日本亚洲专区| 亚洲av无码专区在线电影天堂| 黄页网站免费观看| 精品亚洲国产成人| 久久天天躁狠狠躁夜夜免费观看| 亚洲第一页在线观看| 无码一区二区三区免费| 久久精品国产精品亚洲精品| 99久久免费国产特黄| 亚洲乱码一区二区三区在线观看 | 亚洲黄色激情视频| 真人做A免费观看| 亚洲六月丁香六月婷婷色伊人| 无码国产精品一区二区免费式直播| 亚洲第一页在线视频| 欧美日韩国产免费一区二区三区| 亚洲入口无毒网址你懂的| 成年午夜视频免费观看视频 | 又大又硬又爽又粗又快的视频免费 | 7777久久亚洲中文字幕| 成年人免费视频观看| 久久水蜜桃亚洲AV无码精品 | 国产精品青草视频免费播放| 亚洲亚洲人成综合网络| 日本免费中文字幕| 亚洲天天做日日做天天看| 亚洲一区在线免费观看| 亚洲乱码在线卡一卡二卡新区| 韩国欧洲一级毛片免费| 免费观看四虎精品成人| 国产亚洲日韩一区二区三区| 暖暖免费在线中文日本| 亚洲精品**中文毛片| 日韩a级毛片免费观看| 免费大片av手机看片| 久久亚洲国产午夜精品理论片| 日本xxxx色视频在线观看免费| 亚洲中文久久精品无码1| 日韩免费一级毛片|