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


Java ActiveMQConnectionFactory类代码示例

本文整理汇总了Java中org.apache.activemq.ActiveMQConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQConnectionFactory类的具体用法?Java ActiveMQConnectionFactory怎么用?Java ActiveMQConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: startBroker

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Before
public void startBroker() throws Exception {
  broker = new BrokerService();
  broker.setUseJmx(false);
  broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
  broker.addConnector(BROKER_URL);
  broker.setBrokerName("localhost");
  broker.setPopulateJMSXUserID(true);
  broker.setUseAuthenticatedPrincipalForJMSXUserID(true);

  // enable authentication
  List<AuthenticationUser> users = new ArrayList<>();
  // username and password to use to connect to the broker.
  // This user has users privilege (able to browse, consume, produce, list destinations)
  users.add(new AuthenticationUser(USERNAME, PASSWORD, "users"));
  SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users);
  BrokerPlugin[] plugins = new BrokerPlugin[]{ plugin };
  broker.setPlugins(plugins);

  broker.start();

  // create JMS connection factory
  connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
  connectionFactoryWithoutPrefetch =
      new ActiveMQConnectionFactory(BROKER_URL + "?jms.prefetchPolicy.all=0");
}
 
开发者ID:apache,项目名称:beam,代码行数:27,代码来源:JmsIOTest.java

示例2: putTopic

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
private void putTopic(List<String> events) throws Exception {
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  Connection connection = factory.createConnection();
  connection.start();

  Session session = connection.createSession(true,
      Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createTopic(DESTINATION_NAME);
  MessageProducer producer = session.createProducer(destination);

  for (String event : events) {
    TextMessage message = session.createTextMessage();
    message.setText(event);
    producer.send(message);
  }
  session.commit();
  session.close();
  connection.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestIntegrationActiveMQ.java

示例3: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setSchedulerSupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();
    connectionUri = connector.getPublishableConnectString();
    factory = new ActiveMQConnectionFactory(connectionUri);
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
    pooledFactory.setMaxConnections(1);
    pooledFactory.setBlockIfSessionPoolIsFull(false);
    pooledFactory.setMaximumActiveSessionPerConnection(1);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:PooledSessionExhaustionTest.java

示例4: connectionFactory

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的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;
	}
 
开发者ID:eXcellme,项目名称:eds,代码行数:21,代码来源:EdsCamelConfig.java

示例5: testMaxConnectionsAreCreated

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Test(timeout = 60000)
public void testMaxConnectionsAreCreated() throws Exception {

    ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory(
        "vm://broker1?marshal=false&broker.persistent=false&broker.useJmx=false");
    JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(amq);
    cf.setMaxConnections(3);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn3 = (JmsPoolConnection) cf.createConnection();

    assertNotSame(conn1.getConnection(), conn2.getConnection());
    assertNotSame(conn1.getConnection(), conn3.getConnection());
    assertNotSame(conn2.getConnection(), conn3.getConnection());

    assertEquals(3, cf.getNumConnections());

    cf.stop();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:22,代码来源:PooledConnectionFactoryTest.java

示例6: testConnectionsAreRotated

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Test(timeout = 60000)
public void testConnectionsAreRotated() throws Exception {

    ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory(
        "vm://broker1?marshal=false&broker.persistent=false&broker.useJmx=false");
    JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(amq);
    cf.setMaxConnections(10);

    Connection previous = null;

    // Front load the pool.
    for (int i = 0; i < 10; ++i) {
        cf.createConnection();
    }

    for (int i = 0; i < 100; ++i) {
        Connection current = ((JmsPoolConnection) cf.createConnection()).getConnection();
        assertNotSame(previous, current);
        previous = current;
    }

    cf.stop();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:25,代码来源:PooledConnectionFactoryTest.java

示例7: testConnectionsArePooled

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Test(timeout = 60000)
public void testConnectionsArePooled() throws Exception {

    ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
    JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(amq);
    cf.setMaxConnections(1);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn3 = (JmsPoolConnection) cf.createConnection();

    assertSame(conn1.getConnection(), conn2.getConnection());
    assertSame(conn1.getConnection(), conn3.getConnection());
    assertSame(conn2.getConnection(), conn3.getConnection());

    assertEquals(1, cf.getNumConnections());

    cf.stop();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:21,代码来源:PooledConnectionFactoryTest.java

示例8: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setSchedulerSupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();

    connectionUri = connector.getPublishableConnectString();
    factory = new ActiveMQConnectionFactory(connectionUri);
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
    pooledFactory.setMaxConnections(1);
    pooledFactory.setBlockIfSessionPoolIsFull(false);
    pooledFactory.setUseAnonymousProducers(false);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:22,代码来源:PooledSessionNoPublisherCachingTest.java

示例9: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(true);
    brokerService.getManagementContext().setCreateConnector(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setSchedulerSupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();

    connectionUri = connector.getPublishableConnectString();
    factory = new ActiveMQConnectionFactory(connectionUri);
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
    pooledFactory.setMaxConnections(1);
    pooledFactory.setBlockIfSessionPoolIsFull(false);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:22,代码来源:PooledSessionTest.java

示例10: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.setSchedulerSupport(false);
    brokerService.setAdvisorySupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();

    connectionUri = connector.getPublishableConnectString();
    factory = new ActiveMQConnectionFactory(connectionUri);
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
    pooledFactory.setMaxConnections(1);
    pooledFactory.setBlockIfSessionPoolIsFull(true);
    pooledFactory.setBlockIfSessionPoolIsFullTimeout(500);
    pooledFactory.setMaximumActiveSessionPerConnection(1);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:22,代码来源:PooledSessionExhaustionBlockTimeoutTest.java

示例11: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setUseJmx(false);
    brokerService.setPersistent(false);
    brokerService.setSchedulerSupport(false);
    brokerService.setAdvisorySupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();
    factory = new ActiveMQConnectionFactory("mock:" + connector.getConnectUri() + "?closeAsync=false");
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:17,代码来源:PooledConnectionFactoryWithTemporaryDestinationsTest.java

示例12: testFailoverWithInvalidCredentialsCanConnect

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Test
public void testFailoverWithInvalidCredentialsCanConnect() throws JMSException {

    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(
        "failover:(" + connectionURI + ")");

    pooledConnFact = new JmsPoolConnectionFactory();
    pooledConnFact.setConnectionFactory(cf);
    pooledConnFact.setMaxConnections(1);

    Connection connection = pooledConnFact.createConnection("invalid", "credentials");

    try {
        connection.start();
        fail("Should fail to connect");
    } catch (JMSSecurityException ex) {
        LOG.info("Caught expected security error");
    }

    connection = pooledConnFact.createConnection("system", "manager");
    connection.start();

    LOG.info("Successfully create new connection.");

    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:27,代码来源:PooledConnectionSecurityExceptionTest.java

示例13: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setUseJmx(false);
    brokerService.setPersistent(false);
    brokerService.setSchedulerSupport(false);
    brokerService.setAdvisorySupport(false);
    TransportConnector connector = brokerService.addConnector("tcp://localhost:0");
    brokerService.start();
    factory = new ActiveMQConnectionFactory("mock:" + connector.getConnectUri());
    pooledFactory = new JmsPoolConnectionFactory();
    pooledFactory.setConnectionFactory(factory);
    pooledFactory.setMaxConnections(1);
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:18,代码来源:PooledConnectionExpiryEvictsFromPoolTest.java

示例14: createConnectionFactory

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
private static ConnectionFactory createConnectionFactory(String options, Integer maximumRedeliveries) {
        // using a unique broker name improves testing when running the entire test suite in the same JVM
        int id = counter.incrementAndGet();
        String url = "tcp://192.168.3.103:61618";
//        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);
        if (maximumRedeliveries != null) {
            connectionFactory.getRedeliveryPolicy().setMaximumRedeliveries(maximumRedeliveries);
        }
//        connectionFactory.setTrustAllPackages(true);
        return connectionFactory;
    }
 
开发者ID:eXcellme,项目名称:eds,代码行数:24,代码来源:CamelJmsTestHelper.java

示例15: createPersistentConnectionFactory

import org.apache.activemq.ActiveMQConnectionFactory; //导入依赖的package包/类
private 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.setAlwaysSessionAsync(false);
//        connectionFactory.setTrustAllPackages(true);
        return connectionFactory;
    }
 
开发者ID:eXcellme,项目名称:eds,代码行数:24,代码来源:CamelJmsTestHelper.java


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