org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection()方法的一些代码示例,展示了ActiveMQConnectionFactory.createConnection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ActiveMQConnectionFactory.createConnection()方法的具体详情如下:
包路径:org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
类名称:ActiveMQConnectionFactory
方法名:createConnection

ActiveMQConnectionFactory.createConnection介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
public Connection createConnection() throws JMSException {
 return createConnection(user, password);
}

代码示例来源:origin: apache/activemq-artemis

@Override
public Connection createConnection() throws JMSException {
 return createConnection(user, password);
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

@Override
public Connection createConnection() throws JMSException {
 return createConnection(user, password);
}

代码示例来源:origin: apache/activemq-artemis

@Override
public Connection createConnection() throws JMSException {
 return createConnection(user, password);
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
public Connection createConnection() throws JMSException {
 return createConnection(user, password);
}

代码示例来源:origin: apache/activemq-artemis

public static void waitForServerToStart(String uri, long timeout) throws InterruptedException {
 long realTimeout = System.currentTimeMillis() + timeout;
 while (System.currentTimeMillis() < realTimeout) {
   try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) {
    cf.createConnection().close();
    System.out.println("server " + uri + " started");
   } catch (Exception e) {
    System.out.println("awaiting server " + uri + " start at ");
    Thread.sleep(500);
    continue;
   }
   break;
 }
}

代码示例来源:origin: org.apache.activemq/artemis-cli

public static void waitForServerToStart(String uri, long timeout) throws InterruptedException {
 long realTimeout = System.currentTimeMillis() + timeout;
 while (System.currentTimeMillis() < realTimeout) {
   try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) {
    cf.createConnection().close();
    System.out.println("server " + uri + " started");
   } catch (Exception e) {
    System.out.println("awaiting server " + uri + " start at ");
    Thread.sleep(500);
    continue;
   }
   break;
 }
}

代码示例来源:origin: apache/activemq-artemis

private boolean tryConsume() throws JMSException {
 try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    Connection connection = factory.createConnection();
    Session session = connection.createSession(Session.AUTO_ACKNOWLEDGE)) {
   Queue queue = session.createQueue("NewQueue");
   MessageConsumer consumer = session.createConsumer(queue);
   return true;
 } catch (JMSException e) {
   return false;
 }
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testTwoConnectionsSameIDThroughCF() throws Exception {
 ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid");
 conn = connectionFactory.createConnection();
 try {
   conn2 = connectionFactory.createConnection();
   Assert.fail("Exception expected");
 } catch (InvalidClientIDException expected) {
   // expected
 }
 Session session1 = conn.createSession();
 Session session2 = conn.createSession();
 session1.close();
 session2.close();
}

代码示例来源:origin: apache/activemq-artemis

private void sendObjectMessage(String qname, Serializable obj) throws Exception {
 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0");
 Connection connection = factory.createConnection();
 try {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue q = session.createQueue(qname);
   MessageProducer producer = session.createProducer(q);
   ObjectMessage objMessage = session.createObjectMessage();
   objMessage.setObject(obj);
   producer.send(objMessage);
 } finally {
   connection.close();
 }
}

代码示例来源:origin: apache/activemq-artemis

public static ActiveMQConnection createConnectionAndWaitForTopology(ActiveMQConnectionFactory factory,
                                  int topologyMembers,
                                  int timeout) throws Exception {
 ActiveMQConnection conn;
 CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);
 ServerLocator locator = factory.getServerLocator();
 locator.addClusterTopologyListener(new FailoverTestBase.LatchClusterTopologyListener(countDownLatch));
 conn = (ActiveMQConnection) factory.createConnection();
 boolean ok = countDownLatch.await(timeout, TimeUnit.SECONDS);
 if (!ok) {
   throw new IllegalStateException("timed out waiting for topology");
 }
 return conn;
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testSetClientIdAfterGetExceptionListener() throws Exception {
 Connection conn = cf.createConnection();
 conn.getExceptionListener();
 conn.setClientID("clientId");
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testDefaultConstructorAndSetConnectorPairs() throws Exception {
 ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
 assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
 Connection conn = cf.createConnection();
 conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 testSettersThrowException(cf);
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testStaticConnectorListConstructor() throws Exception {
 ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
 assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
 Connection conn = cf.createConnection();
 conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 testSettersThrowException(cf);
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testStaticConnectorLiveConstructor() throws Exception {
 ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
 assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
 Connection conn = cf.createConnection();
 conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 testSettersThrowException(cf);
 cf.close();
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testNoReconnectCloseAfterFailToReconnectWithTempQueue() throws Exception {
 ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
 jbcf.setReconnectAttempts(0);
 Connection conn = jbcf.createConnection();
 Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 sess.createTemporaryQueue();
 Thread.sleep(2000);
 this.server.stop();
 this.server.start();
 sess.close();
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testListenerCalledForOneConnection() throws Exception {
 Connection conn = cf.createConnection();
 CountDownLatch latch = new CountDownLatch(1);
 MyExceptionListener listener = new MyExceptionListener(latch);
 conn.setExceptionListener(listener);
 ClientSessionInternal coreSession = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession();
 coreSession.getConnection().fail(new ActiveMQInternalErrorException("blah"));
 latch.await(5, TimeUnit.SECONDS);
 Assert.assertEquals(1, listener.numCalls);
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testCloseConnectionAfterServerIsShutdown() throws Exception {
 server.start();
 jbcf = createConnectionFactory();
 jbcf.setBlockOnDurableSend(true);
 jbcf.setBlockOnNonDurableSend(true);
 jbcf.setReconnectAttempts(-1);
 conn = jbcf.createConnection();
 server.stop();
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

@Test
public void testDiscoveryConstructor() throws Exception {
 DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort));
 ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF);
 assertFactoryParams(cf, null, groupConfiguration, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
 Connection conn = cf.createConnection();
 conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 testSettersThrowException(cf);
 conn.close();
}

代码示例来源:origin: apache/activemq-artemis

private void testThroughNewConnectionFactory(ActiveMQConnectionFactory factory) throws Exception {
 Connection conn = factory.createConnection();
 conn.close();
 try (JMSContext ctx = factory.createContext()) {
   ctx.createProducer().send(ctx.createQueue("queue"), "Test");
 }
 try (JMSContext ctx = factory.createContext()) {
   Assert.assertNotNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait());
   Assert.assertNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait());
 }
 factory.close();
}

相关文章

微信公众号

最新文章

更多

ActiveMQConnectionFactory类方法