当前位置: 首页>>代码示例>>Java>>正文


Java PooledConnectionFactory.setIdleTimeout方法代码示例

本文整理汇总了Java中org.apache.activemq.pool.PooledConnectionFactory.setIdleTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java PooledConnectionFactory.setIdleTimeout方法的具体用法?Java PooledConnectionFactory.setIdleTimeout怎么用?Java PooledConnectionFactory.setIdleTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.pool.PooledConnectionFactory的用法示例。


在下文中一共展示了PooledConnectionFactory.setIdleTimeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
/**
 * Inits the.
 *
 * @throws JMSException the jMS exception
 */
public void init() throws JMSException {
    Properties properties = new Properties();
    try {
        properties.load(this.getClass().getResourceAsStream("/sink.properties"));
    } catch (IOException e) {
        logger.error("got: " + e.getMessage());
    }

    user = properties.getProperty("amq.user");
    password = System.getenv("KLOOPZ_AMQ_PASS");


    if (password == null) {
        throw new JMSException("missing KLOOPZ_AMQ_PASS env var");
    }

    AMQConnectorURI connectStringGenerator = new AMQConnectorURI();
    connectStringGenerator.setHost("opsmq");
    connectStringGenerator.setProtocol("tcp");
    connectStringGenerator.setPort(61616);
    connectStringGenerator.setTransport("failover");
    connectStringGenerator.setDnsResolve(true);
    connectStringGenerator.setKeepAlive(true);
    HashMap<String, String> transportOptions = new HashMap<>();
    transportOptions.put("initialReconnectDelay", "1000");
    transportOptions.put("startupMaxReconnectAttempts", mqConnectionStartupRetries);
    transportOptions.put("timeout", mqConnectionTimeout);
    transportOptions.put("useExponentialBackOff", "false");
    connectStringGenerator.setTransportOptions(transportOptions);
    url = connectStringGenerator.build();

    showParameters();

    // Create the connection.
    ActiveMQConnectionFactory amqConnectionFactory = new ActiveMQConnectionFactory(user, password, url);
    amqConnectionFactory.setUseAsyncSend(true);
    PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(amqConnectionFactory);
    pooledConnectionFactory.setMaxConnections(amqConnectionPoolSize);
    pooledConnectionFactory.setIdleTimeout(10000);

    for (int i = 0; i < poolsize; i++) {
        JmsTemplate producerTemplate = new JmsTemplate(pooledConnectionFactory);
        producerTemplate.setSessionTransacted(false);
        int shard = i + 1;
        Destination perfin = new org.apache.activemq.command.ActiveMQQueue(queueBase + "-" + shard);
        producerTemplate.setDefaultDestination(perfin);
        producerTemplate.setDeliveryPersistent(false);
        producers[i] = producerTemplate;
    }


}
 
开发者ID:oneops,项目名称:oneops,代码行数:58,代码来源:SensorPublisher.java

示例2: pooledJmsConnectionFactory

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
@Bean(destroyMethod = "stop")
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true", matchIfMissing = false)
@ConfigurationProperties("spring.activemq.pool.configuration")
public PooledConnectionFactory pooledJmsConnectionFactory(
		ActiveMQProperties properties) {
	PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(
			new ActiveMQConnectionFactoryFactory(properties)
					.createConnectionFactory(ActiveMQConnectionFactory.class));

	ActiveMQProperties.Pool pool = properties.getPool();
	pooledConnectionFactory.setMaxConnections(pool.getMaxConnections());
	pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeout());
	pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeout());
	return pooledConnectionFactory;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:ActiveMQConnectionFactoryConfiguration.java

示例3: createConnectionFactory

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
/**
 * Creates the JMS connection factory without registering it.
 * 
 * @param repo  the component repository, only used to register secondary items like lifecycle, not null
 * @return the JMS connection factory, not null
 */
protected ConnectionFactory createConnectionFactory(ComponentRepository repo) {
  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(getClientBrokerUri());
  connectionFactory.setWatchTopicAdvisories(false);
  PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
  pooledConnectionFactory.setIdleTimeout(0);
  return pooledConnectionFactory;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:ActiveMqJmsConnectorComponentFactory.java

示例4: addMQPool

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public void addMQPool(String url, String username, String password) {
	connectionPool = new PooledConnectionFactory(url);
	connectionPool.setMaxConnections(maxTotal);
	connectionPool.setMaximumActiveSessionPerConnection(maxIdle);
	connectionPool.setIdleTimeout(maxWaitMillis);
	this.username = username;
	this.password = password;
}
 
开发者ID:yiyongfei,项目名称:jea,代码行数:9,代码来源:ActiveMQPool.java

示例5: startConsumer

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
private void startConsumer(){
  ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerUrl);
  pooledConnectionFactory = new PooledConnectionFactory(factory);
  pooledConnectionFactory.setReconnectOnException(true);
  pooledConnectionFactory.setMaximumActiveSessionPerConnection(10); // 10
  pooledConnectionFactory.setMaxConnections(10); // 10
  pooledConnectionFactory.setIdleTimeout(300000); // 管理连接池中的连接,5分钟超时   300000
  pooledConnectionFactory.setUseAnonymousProducers(false);
  pooledConnectionFactory.start();
  Thread t = new Thread(){
    @Override
    public void run() {
      // consumer
      Connection conn ;
      Session sess;
      MessageConsumer consumer;
      try {
        while(!shutdown){
          conn = pooledConnectionFactory.createConnection();
          conn.start();
          sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          Destination dest = sess.createQueue("_eds_"+queueName);
          consumer = sess.createConsumer(dest);
          Message msg = consumer.receive();

          if(msg != null){
            System.out.println("received => "+msg);
            msgReceived.incrementAndGet();
          }
          consumer.close();
          sess.close();
          conn.close();
          System.out.println("receiving => "+msg);
        }
      } catch (JMSException e) {
        e.printStackTrace();
      }

    }
  };
  t.start();
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:43,代码来源:EdsTest.java

示例6: getPooledConnection

import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
/**
 * 从连接池中取得连接,如果连接池为null,则初始化连接池
 * <p>
 * 由于连接池中取得的连接会自动回收,因此该连接不能用于Consumer,池连接主要用于Producer
 * 
 * @return Connection
 * @throws JMSException
 */
private Connection getPooledConnection() throws JMSException {
	if (null == producerPooledFactory) {
		// 初始化连接池工厂并设置参数
		synchronized (this) {
			if (serverUrl == null || serverUrl.trim().equals("")) {
				throw new FwRuntimeException("未设置服务器地址serverUrl");
			}

			if (brokerForProduct == null) {
				StringBuilder brokerUrlSb = new StringBuilder();
				brokerUrlSb.append("failover:(");
				String[] hostArr = serverUrl.split(",");
				for (String host : hostArr) {
					brokerUrlSb.append("tcp://" + host + "?connectionTimeout=" + connectTimeout).append(",");
				}
				// 删除最后多出来的,号
				brokerUrlSb.deleteCharAt(brokerUrlSb.length() - 1);
				brokerUrlSb.append(")?timeout=" + operateTimeout);
				brokerForProduct = brokerUrlSb.toString();
			}

			if (producerPooledFactory == null) {
				ActiveMQConnectionFactory connectionFactory = FwMqServiceHelper.createConnectionFactory(
						brokerForProduct, userName, password);

				PooledConnectionFactory pcf = new PooledConnectionFactory(connectionFactory);
				// 设置连接池尺寸
				pcf.setMaxConnections(maximumConnections);
				// 设置每个连接的最多Session数
				pcf.setMaximumActive(maximumActive);
				// 设置连接闲置超时回收时间
				pcf.setIdleTimeout(idleTimeout);

				producerPooledFactory = pcf;
			}

			initMqHealthMBean();// 注册MBean
		}
	}
	return producerPooledFactory.createConnection();
}
 
开发者ID:bignippleboy,项目名称:ipaas,代码行数:50,代码来源:FwMqSendService.java


注:本文中的org.apache.activemq.pool.PooledConnectionFactory.setIdleTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。