本文整理汇总了Java中org.apache.activemq.pool.PooledConnectionFactory.setMaxConnections方法的典型用法代码示例。如果您正苦于以下问题:Java PooledConnectionFactory.setMaxConnections方法的具体用法?Java PooledConnectionFactory.setMaxConnections怎么用?Java PooledConnectionFactory.setMaxConnections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.activemq.pool.PooledConnectionFactory
的用法示例。
在下文中一共展示了PooledConnectionFactory.setMaxConnections方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
@Bean(name="connectionFactory")
public ConnectionFactory connectionFactory(){
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
// activeMQConnectionFactory.setUseAsyncSend(true);
activeMQConnectionFactory.setUserName(jmsUserName);
activeMQConnectionFactory.setPassword(jmsPassword);
activeMQConnectionFactory.setBrokerURL(jmsBrokerUrl);
// 默认重复投递6次将转发到死信队列,改为无限次数
// RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
// redeliveryPolicy.setMaximumRedeliveries(-1);
//
// activeMQConnectionFactory.setRedeliveryPolicy(redeliveryPolicy);
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(activeMQConnectionFactory);
pooledConnectionFactory.setMaxConnections(jmsMaxPooledConnections);
// CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(pooledConnectionFactory);
// cachingConnectionFactory.setSessionCacheSize(10);
return pooledConnectionFactory;
}
示例2: createConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static ConnectionFactory createConnectionFactory(String options) {
// using a unique broker name improves testing when running the entire test suite in the same JVM
int id = counter.incrementAndGet();
String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false";
if (options != null) {
url = url + "&" + options;
}
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
// optimize AMQ to be as fast as possible so unit testing is quicker
connectionFactory.setCopyMessageOnSend(false);
connectionFactory.setOptimizeAcknowledge(true);
connectionFactory.setOptimizedMessageDispatch(true);
connectionFactory.setTrustAllPackages(true);
// When using asyncSend, producers will not be guaranteed to send in the order we
// have in the tests (which may be confusing for queues) so we need this set to false.
// Another way of guaranteeing order is to use persistent messages or transactions.
connectionFactory.setUseAsyncSend(false);
connectionFactory.setAlwaysSessionAsync(false);
// use a pooled connection factory
PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(8);
return pooled;
}
示例3: createConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static ConnectionFactory createConnectionFactory(String options) {
// using a unique broker name improves testing when running the entire test suite in the same JVM
int id = counter.incrementAndGet();
String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false";
if (options != null) {
url = url + "&" + options;
}
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
// optimize AMQ to be as fast as possible so unit testing is quicker
connectionFactory.setCopyMessageOnSend(false);
connectionFactory.setOptimizeAcknowledge(true);
connectionFactory.setOptimizedMessageDispatch(true);
// When using asyncSend, producers will not be guaranteed to send in the order we
// have in the tests (which may be confusing for queues) so we need this set to false.
// Another way of guaranteeing order is to use persistent messages or transactions.
connectionFactory.setUseAsyncSend(false);
connectionFactory.setAlwaysSessionAsync(false);
// use a pooled connection factory
PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(8);
return pooled;
}
示例4: newAMQInstance
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static ActiveMQComponent newAMQInstance(){
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL("vm:localhost");
// use a pooled connection factory between the module and the queue
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(connectionFactory);
// how many connections should there be in the session pool?
pooledConnectionFactory.setMaxConnections(100);
pooledConnectionFactory.setMaximumActiveSessionPerConnection(100);
pooledConnectionFactory.setCreateConnectionOnStartup(true);
pooledConnectionFactory.setBlockIfSessionPoolIsFull(false);
JmsConfiguration jmsConfiguration = new JmsConfiguration(pooledConnectionFactory);
jmsConfiguration.setDeliveryPersistent(false);
jmsConfiguration.setTimeToLive(1000*10);
ActiveMQComponent activeMQComponent = ActiveMQComponent.activeMQComponent("vm:localhost");
return activeMQComponent;
}
示例5: 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;
}
}
示例6: 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
示例7: createPersistentConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static ConnectionFactory createPersistentConnectionFactory(String options) {
// using a unique broker name improves testing when running the entire test suite in the same JVM
int id = counter.incrementAndGet();
// use an unique data directory in target
String dir = "target/activemq-data-" + id;
// remove dir so its empty on startup
FileUtil.removeDir(new File(dir));
String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
if (options != null) {
url = url + "&" + options;
}
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
// optimize AMQ to be as fast as possible so unit testing is quicker
connectionFactory.setCopyMessageOnSend(false);
connectionFactory.setOptimizeAcknowledge(true);
connectionFactory.setOptimizedMessageDispatch(true);
connectionFactory.setUseAsyncSend(true);
connectionFactory.setAlwaysSessionAsync(false);
connectionFactory.setTrustAllPackages(true);
// use a pooled connection factory
PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(8);
return pooled;
}
示例8: createPooledConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static PooledConnectionFactory createPooledConnectionFactory() {
ConnectionFactory cf = createConnectionFactory(null, null);
PooledConnectionFactory pooled = new PooledConnectionFactory();
pooled.setConnectionFactory(cf);
pooled.setMaxConnections(8);
return pooled;
}
示例9: createPersistentConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public static ConnectionFactory createPersistentConnectionFactory(String options) {
// using a unique broker name improves testing when running the entire test suite in the same JVM
int id = counter.incrementAndGet();
// use an unique data directory in target
String dir = "target/activemq-data-" + id;
// remove dir so its empty on startup
FileUtil.removeDir(new File(dir));
String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
if (options != null) {
url = url + "&" + options;
}
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
// optimize AMQ to be as fast as possible so unit testing is quicker
connectionFactory.setCopyMessageOnSend(false);
connectionFactory.setOptimizeAcknowledge(true);
connectionFactory.setOptimizedMessageDispatch(true);
connectionFactory.setUseAsyncSend(true);
connectionFactory.setAlwaysSessionAsync(false);
// use a pooled connection factory
PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(8);
return pooled;
}
示例10: getConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public ConnectionFactory getConnectionFactory(){
if(connectionFactory == null ){
connectionFactory = new ActiveMQConnectionFactory(this.userName, this.password, this.broker);
PooledConnectionFactory pooledConnectionFactory = new org.apache.activemq.pool.PooledConnectionFactory(connectionFactory);
pooledConnectionFactory.setMaxConnections(10);
return pooledConnectionFactory;
}
return connectionFactory;
}
示例11: getPooledConnectionFactory
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
private PooledConnectionFactory getPooledConnectionFactory(String brokerUrl) {
if (null != pooledConnectionFactory) {
return pooledConnectionFactory;
} else {
PooledConnectionFactory connectionFactory = new PooledConnectionFactory(brokerUrl);
connectionFactory.setMaxConnections(8);
connectionFactory.start();
this.pooledConnectionFactory = connectionFactory;
return pooledConnectionFactory;
}
}
示例12: 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;
}
示例13: 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();
}
示例14: AMQConnectionResource
import org.apache.activemq.pool.PooledConnectionFactory; //导入方法依赖的package包/类
public AMQConnectionResource(String connectString, int maxConnections) {
pcf = new PooledConnectionFactory(connectString);
pcf.setMaxConnections(maxConnections);
pcf.start();
}
示例15: 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();
}