<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,這樣會覆蓋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 閱讀(623) 評論(0)  編輯  收藏 所屬分類: JMS

    主站蜘蛛池模板: 中文字幕亚洲综合精品一区| 免费无码又爽又刺激高潮视频| 亚洲精品在线电影| 婷婷亚洲天堂影院| 免费国产作爱视频网站| 国产日韩精品无码区免费专区国产| 91在线亚洲综合在线| 亚洲天堂一区二区| 亚洲无码在线播放| 亚洲狠狠爱综合影院婷婷| 女人被免费视频网站| 免费看美女裸露无档网站| 日本在线免费播放| 男女一进一出抽搐免费视频| 337p日本欧洲亚洲大胆人人| 国产亚洲中文日本不卡二区| 亚洲精品在线不卡| 久久精品国产亚洲AV香蕉| 亚洲va久久久噜噜噜久久| 一本色道久久综合亚洲精品高清| 国产精品久免费的黄网站| 成年人免费网站在线观看| 曰曰鲁夜夜免费播放视频 | 亚洲成人免费在线观看| 日韩精品人妻系列无码专区免费| 在线免费播放一级毛片| 久青草视频在线观看免费| av电影在线免费看| eeuss免费影院| 香蕉免费看一区二区三区| jizz日本免费| 国产99久久久国产精免费| 一区二区三区免费在线观看| 国产激情久久久久影院老熟女免费 | 国产亚洲午夜精品| 国产亚洲Av综合人人澡精品| 视频一区在线免费观看| 国产精品亚洲一区二区三区| 高潮毛片无遮挡高清免费视频| 黄页网址在线免费观看| 国产高潮流白浆喷水免费A片 |