Exemplo n.º 1
0
  private static synchronized void initMQConnectionFactory() {

    pool_conn_factory = new PooledConnectionFactory();

    MQConfig config = new MQConfig();

    String url = config.getProperty(MQConfig.ACTIVEMQ_CONN_URL, DEFAULT_URL);

    String user = config.getProperty(MQConfig.ACTIVEMQ_CONN_USER, DEFAULT_USER);

    String passwd = config.getProperty(MQConfig.ACTIVEMQ_CONN_PASSWD, DEFAULT_PASSWORD);

    ActiveMQConnectionFactory activeMQConnFactory =
        new ActiveMQConnectionFactory(user, passwd, url);

    if (Boolean.TRUE
        .toString()
        .equalsIgnoreCase(config.getProperty(MQConfig.ACTIVEMQ_POOL_USE_ASYNCSEND, "false"))) {
      activeMQConnFactory.setUseAsyncSend(true);
    }

    pool_conn_factory.setConnectionFactory(activeMQConnFactory);

    pool_conn_factory.setMaxConnections(
        config.getIntProperty(MQConfig.ACTIVEMQ_POOL_CONN_MAX, "10"));

    // Sets the maximum number of active sessions per connection
    pool_conn_factory.setMaximumActive(
        config.getIntProperty(MQConfig.ACTIVEMQ_POOL_ACTIVE_SESSION_MAX, "200"));

    pool_conn_factory.setIdleTimeout(
        config.getIntProperty(MQConfig.ACTIVEMQ_POOL_IDLETIMEOUT, "30000"));
  }
 @Test
 public void testActiveMQOverriddenPoolAndStandalone() {
   load(TestConfiguration.class, "spring.activemq.pooled:true", "spring.activemq.inMemory:false");
   JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
   PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
   assertThat(jmsTemplate).isNotNull();
   assertThat(pool).isNotNull();
   assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
   ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
   assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_NETWORK_URL);
 }
 public static ConnectionFactory createConnectionFactory(String options) {
   String url = "vm://test-broker?broker.persistent=false&broker.useJmx=false";
   if (options != null) {
     url = url + "&" + options;
   }
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
   // use a pooled connection factory
   PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
   pooled.setMaxConnections(8);
   return pooled;
 }
 @Test
 public void testActiveMQOverriddenPoolAndRemoteServer() {
   load(
       TestConfiguration.class,
       "spring.activemq.pooled:true",
       "spring.activemq.brokerUrl:tcp://remote-host:10000");
   JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
   PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class);
   assertThat(jmsTemplate).isNotNull();
   assertThat(pool).isNotNull();
   assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory());
   ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory();
   assertThat(factory.getBrokerURL()).isEqualTo("tcp://remote-host:10000");
 }
Exemplo n.º 5
0
 /** Configures the jms broker url. */
 public void setBrokerUrl() {
   String jmsBrokerHost = getJmsBrokerHost();
   Integer jmsBrokerPort = getJmsBrokerPort();
   connectionFactory.setBrokerURL("tcp://" + jmsBrokerHost + ":" + jmsBrokerPort);
   pooledConnectionFactory.setConnectionFactory(connectionFactory);
   configureTransportConnector(jmsBrokerHost, jmsBrokerPort);
 }
 @Bean(destroyMethod = "stop")
 public PooledConnectionFactory pooledConnectionFactory() {
   final PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
   pooledConnectionFactory.setConnectionFactory(this.connectionFactory());
   return pooledConnectionFactory;
 }
Exemplo n.º 7
0
 public static Connection createConnection() throws JMSException {
   return pool_conn_factory.createConnection();
 }