org.apache.activemq.pool.PooledConnectionFactory Java Examples
The following examples show how to use
org.apache.activemq.pool.PooledConnectionFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PooledConnectionTempQueueTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testTempQueueIssue() throws JMSException, InterruptedException { final ConnectionFactory cf = new PooledConnectionFactory("vm://localhost?broker.persistent=false"); Connection con1 = cf.createConnection(); con1.start(); // This order seems to matter to reproduce the issue con1.close(); new Thread(() -> { try { receiveAndRespondWithMessageIdAsCorrelationId(cf, SERVICE_QUEUE); } catch (Exception e) { e.printStackTrace(); } }).start(); sendWithReplyToTemp(cf, SERVICE_QUEUE); }
Example #2
Source File: ActivemqConfiguration.java From jim-framework with Apache License 2.0 | 6 votes |
@Bean public PooledConnectionFactory pooledConnectionFactory(){ // ActiveMQConnectionFactory activeMQConnectionFactory=new ActiveMQConnectionFactory(Constans.PRODUCER_BROKER_URL); // //activeMQConnectionFactory. // activeMQConnectionFactory.setPrefetchPolicy(new ActiveMQPrefetchPolicy()); // PooledConnectionFactory pooledConnectionFactory=new PooledConnectionFactory(activeMQConnectionFactory); // pooledConnectionFactory.setMaxConnections(10); // // pooledConnectionFactory.setMaximumActiveSessionPerConnection(50); //// pooledConnectionFactory.setTimeBetweenExpirationCheckMillis(3000); //// pooledConnectionFactory.setIdleTimeout(10000); // //pooledConnectionFactory.setCreateConnectionOnStartup(true); // return pooledConnectionFactory; String brokerClusterString=ConnectionFactoryContainer.buildProducerBrokerClusterUri(Constans.PRODUCER_BROKER_URL); return ConnectionFactoryContainer.getPooledConnectionFactory(brokerClusterString); }
Example #3
Source File: ClientMtomXopWithJMSTest.java From cxf with Apache License 2.0 | 6 votes |
@BeforeClass public static void startServers() throws Exception { Object implementor = new TestMtomJMSImpl(); bus = BusFactory.getDefaultBus(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); PooledConnectionFactory cfp = new PooledConnectionFactory(cf); cff = new ConnectionFactoryFeature(cfp); EndpointImpl ep = (EndpointImpl)Endpoint.create(implementor); ep.getFeatures().add(cff); ep.getInInterceptors().add(new TestMultipartMessageInterceptor()); ep.getOutInterceptors().add(new TestAttachmentOutInterceptor()); //ep.getInInterceptors().add(new LoggingInInterceptor()); //ep.getOutInterceptors().add(new LoggingOutInterceptor()); SOAPBinding jaxWsSoapBinding = (SOAPBinding)ep.getBinding(); jaxWsSoapBinding.setMTOMEnabled(true); ep.publish(); }
Example #4
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 6 votes |
public static PooledConnectionFactory getPooledConnectionFactory(String brokerUrl) { final String brokerClusterUrl=brokerUrl.replace(";",","); PooledConnectionFactory connectionFactory = null; //((ActiveMQConnectionFactory)connectionFactory.getConnectionFactory()).get; synchronized(lock) { if(producerConnectionFactoryMap.containsKey(brokerClusterUrl)) { connectionFactory = producerConnectionFactoryMap.get(brokerClusterUrl); } else { ProducerConnctionFactory producerConnctionFactory=new ProducerConnctionFactory(); //producerConnctionFactory.init(); connectionFactory=producerConnctionFactory.create(brokerClusterUrl); producerConnectionFactoryMap.put(brokerClusterUrl, connectionFactory); } return connectionFactory; } }
Example #5
Source File: ConsumerConnctionFactory.java From jim-framework with Apache License 2.0 | 5 votes |
public PooledConnectionFactory create(String brokerClusterUrl){ ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(); mqConnectionFactory.setBrokerURL(brokerClusterUrl); mqConnectionFactory.setTransportListener(this); //mqConnectionFactory. PooledConnectionFactory connectionFactory = new JimPooledConnectionFactory(mqConnectionFactory); connectionFactory.setMaxConnections(1); connectionFactory.setCreateConnectionOnStartup(true); return connectionFactory; }
Example #6
Source File: AbstractVmJMSTest.java From cxf with Apache License 2.0 | 5 votes |
public static void startBusAndJMS(String brokerURI) { bus = BusFactory.getDefaultBus(); ActiveMQConnectionFactory cf1 = new ActiveMQConnectionFactory(brokerURI); RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy(); redeliveryPolicy.setMaximumRedeliveries(1); redeliveryPolicy.setInitialRedeliveryDelay(1000); cf1.setRedeliveryPolicy(redeliveryPolicy()); cf = new PooledConnectionFactory(cf1); cff = new ConnectionFactoryFeature(cf); }
Example #7
Source File: MultiTransportClientServerTest.java From cxf with Apache License 2.0 | 5 votes |
@BeforeClass public static void startServers() throws Exception { bus = BusFactory.getDefaultBus(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); PooledConnectionFactory cfp = new PooledConnectionFactory(cf); cff = new ConnectionFactoryFeature(cfp); String address = "http://localhost:" + PORT + "/SOAPDocLitService/SoapPort"; Endpoint.publish(address, new HTTPGreeterImpl()); EndpointImpl ep1 = (EndpointImpl)Endpoint.create(new JMSGreeterImpl()); ep1.setBus(bus); ep1.getFeatures().add(cff); ep1.publish(); }
Example #8
Source File: ActiveMQPool.java From jea with Apache License 2.0 | 5 votes |
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; }
Example #9
Source File: ApplicationAuditLogger.java From oxAuth with MIT License | 5 votes |
private boolean tryToEstablishJMSConnectionImpl() { Set<String> jmsBrokerURISet = appConfiguration.getJmsBrokerURISet(); if (!enabled || CollectionUtils.isEmpty(jmsBrokerURISet)) { return false; } this.jmsBrokerURISet = new HashSet<String>(jmsBrokerURISet); this.jmsUserName = appConfiguration.getJmsUserName(); this.jmsPassword = appConfiguration.getJmsPassword(); Iterator<String> jmsBrokerURIIterator = jmsBrokerURISet.iterator(); StringBuilder uriBuilder = new StringBuilder(); while (jmsBrokerURIIterator.hasNext()) { String jmsBrokerURI = jmsBrokerURIIterator.next(); uriBuilder.append("tcp://"); uriBuilder.append(jmsBrokerURI); if (jmsBrokerURIIterator.hasNext()) { uriBuilder.append(","); } } String brokerUrl = BROKER_URL_PREFIX + uriBuilder + BROKER_URL_SUFFIX; ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.jmsUserName, this.jmsPassword, brokerUrl); this.pooledConnectionFactory = new PooledConnectionFactory(connectionFactory); pooledConnectionFactory.setIdleTimeout(5000); pooledConnectionFactory.setMaxConnections(10); pooledConnectionFactory.start(); return true; }
Example #10
Source File: CamelConfig.java From spring-boot-samples with Apache License 2.0 | 5 votes |
@Bean ConnectionFactory jmsConnectionFactory() { // use a pool for ActiveMQ connections PooledConnectionFactory pool = new PooledConnectionFactory(); pool.setConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61616")); return pool; }
Example #11
Source File: SensorPublisher.java From oneops with Apache License 2.0 | 5 votes |
/** * Close connection. */ public void closeConnection() { for (JmsTemplate jt : producers) { ((PooledConnectionFactory) jt.getConnectionFactory()).stop(); } producers = null; }
Example #12
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 5 votes |
public static void producerConnectionFactoryResetExpiryTimeout(){ for(Map.Entry<String,PooledConnectionFactory> entry: producerConnectionFactoryMap.entrySet()){ PooledConnectionFactory pooledConnectionFactory=entry.getValue(); if(null!=pooledConnectionFactory){ if(pooledConnectionFactory.getExpiryTimeout()!=0) { pooledConnectionFactory.setExpiryTimeout(0); System.out.println("expirytimeount set to 0"); } } } }
Example #13
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 5 votes |
public static void producerConnectionFactoryRebalance(){ for(Map.Entry<String,PooledConnectionFactory> entry: producerConnectionFactoryMap.entrySet()){ PooledConnectionFactory pooledConnectionFactory=entry.getValue(); if(null!=pooledConnectionFactory){ pooledConnectionFactory.setExpiryTimeout(30*1*1000); System.out.println("expirytimeount set to 60*2*1000"); } } }
Example #14
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 5 votes |
public static void stopProducerConnectionFactory(){ for(Map.Entry<String,PooledConnectionFactory> entry: producerConnectionFactoryMap.entrySet()){ PooledConnectionFactory pooledConnectionFactory=entry.getValue(); if(null!=pooledConnectionFactory){ //pooledConnectionFactory.stop(); needToRemoveConnctionFactories.add(pooledConnectionFactory); producerConnectionFactoryMap.remove(entry.getKey()); } } }
Example #15
Source File: ActivemqConfiguration.java From jim-framework with Apache License 2.0 | 5 votes |
@PostConstruct public void init(){ String brokerClusterString=ConnectionFactoryContainer.buildProducerBrokerClusterUri(Constans.PRODUCER_BROKER_URL); PooledConnectionFactory pooledConnectionFactory= ConnectionFactoryContainer.getPooledConnectionFactory(brokerClusterString); JmsTemplate jmsTemplate=new JmsTemplate(pooledConnectionFactory); QueueJmsTemplateContainer.setQueJmsTemplateMap(Constans.QUEUE_NAME,jmsTemplate); }
Example #16
Source File: ProductController.java From jim-framework with Apache License 2.0 | 5 votes |
@RequestMapping("/test/{productId}") public Long test(@PathVariable final long productId) { productProducer.sendMessage(productId); Map<String,PooledConnectionFactory> pooledConnectionFactoryMap= ConnectionFactoryContainer.getAllPooledConnectionFactory(); for(Map.Entry<String,PooledConnectionFactory> entry:pooledConnectionFactoryMap.entrySet()) { JimPooledConnectionFactory jimPooledConnectionFactory=(JimPooledConnectionFactory) entry.getValue(); //jimPooledConnectionFactory.setExpiryTimeout(); GenericKeyedObjectPool<ConnectionKey, ConnectionPool> jimConnectionsPool = ((JimPooledConnectionFactory) entry.getValue()).getJimConnectionsPool(); //jimConnectionsPool. jimConnectionsPool.clearOldest(); //jimConnectionsPool.set Map<String, List<DefaultPooledObjectInfo>> defStringListMap= jimConnectionsPool.listAllObjects(); for(Map.Entry<String,List<DefaultPooledObjectInfo>> entry1 : defStringListMap.entrySet()){ List<DefaultPooledObjectInfo> defaultPooledObjectInfos=entry1.getValue(); System.out.println("123"); for(DefaultPooledObjectInfo defaultPooledObjectInfo:defaultPooledObjectInfos){ //defaultPooledObjectInfo. System.out.println("123"); //((ConnectionPool)defaultPooledObjectInfo.pooledObject.getObject()).connection; } } //jimConnectionsPool.get System.out.println("123"); //((ObjectDeque)((java.util.concurrent.ConcurrentHashMap.MapEntry)((java.util.concurrent.ConcurrentHashMap)jimConnectionsPool.poolMap).entrySet().toArray()[0]).getValue()).allObjects } return productId; }
Example #17
Source File: ProducerConnctionFactory.java From jim-framework with Apache License 2.0 | 5 votes |
public PooledConnectionFactory create(String brokerClusterUrl){ ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(); mqConnectionFactory.setBrokerURL(brokerClusterUrl); mqConnectionFactory.setTransportListener(this); //mqConnectionFactory. PooledConnectionFactory connectionFactory = new JimPooledConnectionFactory(mqConnectionFactory); connectionFactory.setMaxConnections(10); connectionFactory.setTimeBetweenExpirationCheckMillis(1000); //connectionFactory.setCreateConnectionOnStartup(true); return connectionFactory; }
Example #18
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 4 votes |
public static PooledConnectionFactory createPooledConnectionFactory(String brokerUrl) { final String brokerClusterUrl=brokerUrl.replace(";",","); PooledConnectionFactory connectionFactory = null; //((ActiveMQConnectionFactory)connectionFactory.getConnectionFactory()).get; synchronized(lock) { if(producerConnectionFactoryMap.containsKey(brokerClusterUrl)) { connectionFactory = producerConnectionFactoryMap.get(brokerClusterUrl); needToRemoveConnctionFactories.add(connectionFactory); producerConnectionFactoryMap.remove(brokerUrl); } ProducerConnctionFactory producerConnctionFactory=new ProducerConnctionFactory(); //producerConnctionFactory.init(); connectionFactory=producerConnctionFactory.create(brokerClusterUrl); producerConnectionFactoryMap.put(brokerClusterUrl, connectionFactory); return connectionFactory; } }
Example #19
Source File: SensorPublisher.java From oneops with Apache License 2.0 | 4 votes |
/** * 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; } }
Example #20
Source File: ConnectionFactoryContainer.java From jim-framework with Apache License 2.0 | 4 votes |
public static Map<String,PooledConnectionFactory> getAllPooledConnectionFactory(){ return producerConnectionFactoryMap; }
Example #21
Source File: ActiveMQAutoConfiguration.java From mykit-delay with Apache License 2.0 | 4 votes |
@Bean public PooledConnectionFactory connectionFactory(){ PooledConnectionFactory factory = new PooledConnectionFactory(); factory.setConnectionFactory(activeMQConnectionFactory()); return factory; }