Java Code Examples for org.apache.activemq.artemis.api.jms.ActiveMQJMSClient#createConnectionFactoryWithoutHA()

The following examples show how to use org.apache.activemq.artemis.api.jms.ActiveMQJMSClient#createConnectionFactoryWithoutHA() . 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: ConnectionFactoryProvider.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   Map<String, Object> params = new HashMap<>();
   params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1");
   final ActiveMQConnectionFactory activeMQConnectionFactory;
   if (configuration.getUrl() != null) {
      activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null);
   } else {
      if (configuration.getHost() != null) {
         params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost());
         params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort());
      }
      if (configuration.isHa()) {
         activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
      } else {
         activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
      }
   }
   if (configuration.hasAuthentication()) {
      activeMQConnectionFactory.setUser(configuration.getUsername());
      activeMQConnectionFactory.setPassword(configuration.getPassword());
   }
   // The CF will probably be GCed since it was injected, so we disable the finalize check
   return activeMQConnectionFactory.disableFinalizeChecks();
}
 
Example 2
Source File: TCPSchema.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected ActiveMQConnectionFactory internalNewObject(URI uri,
                                                      Map<String, String> query,
                                                      String name) throws Exception {
   JMSConnectionOptions options = newConectionOptions(uri, query);

   List<TransportConfiguration> configurations = TCPTransportConfigurationSchema.getTransportConfigurations(uri, query, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, name, NettyConnectorFactory.class.getName());

   TransportConfiguration[] tcs = new TransportConfiguration[configurations.size()];

   configurations.toArray(tcs);

   ActiveMQConnectionFactory factory;

   if (options.isHa()) {
      factory = ActiveMQJMSClient.createConnectionFactoryWithHA(options.getFactoryTypeEnum(), tcs);
   } else {
      factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs);
   }

   setData(uri, query, factory);

   checkIgnoredQueryFields(factory, query);

   return factory;
}
 
Example 3
Source File: UDPSchema.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ActiveMQConnectionFactory internalNewObject(URI uri,
                                                   Map<String, String> query,
                                                   String name) throws Exception {
   JMSConnectionOptions options = newConectionOptions(uri, query);

   DiscoveryGroupConfiguration dgc = UDPServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, getHost(uri), getPort(uri), name);

   ActiveMQConnectionFactory factory;
   if (options.isHa()) {
      factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, options.getFactoryTypeEnum());
   } else {
      factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum());
   }
   return setData(uri, query, factory);
}
 
Example 4
Source File: JGroupsSchema.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ActiveMQConnectionFactory internalNewObject(URI uri,
                                                   Map<String, String> query,
                                                   String name) throws Exception {
   JMSConnectionOptions options = newConectionOptions(uri, query);

   DiscoveryGroupConfiguration dcConfig = JGroupsServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, name);

   ActiveMQConnectionFactory factory;
   if (options.isHa()) {
      factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dcConfig, options.getFactoryTypeEnum());
   } else {
      factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum());
   }
   return setData(uri, query, factory);
}
 
Example 5
Source File: ConcurrentSessionCloseTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
}
 
Example 6
Source File: ExceptionListenerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false));
   server.start();
   cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
   cf.setBlockOnDurableSend(true);
   cf.setPreAcknowledge(true);
}
 
Example 7
Source File: JMSUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static ConnectionFactory createFactory(final String connectorFactory,
                                              final long connectionTTL,
                                              final long clientFailureCheckPeriod) throws JMSException {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));

   cf.setBlockOnNonDurableSend(true);
   cf.setBlockOnDurableSend(true);
   cf.setBlockOnAcknowledge(true);
   cf.setConnectionTTL(connectionTTL);
   cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);

   return cf;
}
 
Example 8
Source File: AutoGroupingTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ConnectionFactory getCF() throws Exception {
   ActiveMQJMSConnectionFactory cf1 = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   cf1.setAutoGroup(true);

   return cf1;
}
 
Example 9
Source File: GroupIDTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ConnectionFactory getCF() throws Exception {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   cf.setGroupID("wibble");

   return cf;
}
 
Example 10
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testIPv6() throws Exception {
   for (String IPV6 : V6IPs) {
      Map<String, Object> params = new HashMap<>();
      params.put("host", IPV6);
      params.put("port", 5445);
      TransportConfiguration transport = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);
      ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transport);

      persistIP6(IPV6, factory);
   }
}
 
Example 11
Source File: CloseDestroyedConnectionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
   cf.setBlockOnDurableSend(true);
   cf.setPreAcknowledge(true);
}
 
Example 12
Source File: FailureDeadlockTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();
   server = createServer(false, createDefaultInVMConfig());
   server.start();

   cf1 = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
   cf2 = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
}
 
Example 13
Source File: JMSBridgeTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCrashDestStopBridge() throws Exception {
   cff1xa = new ConnectionFactoryFactory() {
      @Override
      public Object createConnectionFactory() throws Exception {
         ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));

         cf.setReconnectAttempts(-1);
         cf.setCallFailoverTimeout(-1);
         cf.setCallTimeout(10000);
         cf.setBlockOnNonDurableSend(true);
         cf.setBlockOnDurableSend(true);
         cf.setCacheLargeMessagesClient(true);

         return cf;
      }

   };

   JMSBridgeImpl bridge = new JMSBridgeImpl(cff0xa, cff1xa, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, 10, 5000, null, null, false).setBridgeName("test-bridge");
   addActiveMQComponent(bridge);
   bridge.setTransactionManager(newTransactionManager());

   bridge.start();

   // Now crash the dest server

   instanceLog.debug("About to crash server");

   server1.stop();

   // Now stop the bridge while the failover is happening

   instanceLog.debug("About to stop the bridge");

   bridge.stop();

   // Shutdown the source server

   server0.stop();
}
 
Example 14
Source File: JMSUtil.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static String[] sendMessages(final Destination destination, final int messagesToSend) throws Exception {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(InVMConnectorFactory.class.getName()));
   return JMSUtil.sendMessages(cf, destination, messagesToSend);
}
 
Example 15
Source File: JMSReconnectTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 16
Source File: PagingOrderTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPagingOverCreatedDestinationQueues() throws Exception {

   Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);

   ActiveMQServer server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
   server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);

   JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
   InVMNamingContext context = new InVMNamingContext();
   jmsServer.setRegistry(new JndiBindingRegistry(context));
   jmsServer.start();

   server.getActiveMQServerControl().addAddressSettings("Q1", "DLQ", "DLQ", -1, false, 5, 100 * 1024, 10 * 1024, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);

   jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");

   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   conn = cf.createConnection();
   conn.setClientID("tst");
   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");

   MessageProducer prod = sess.createProducer(queue);
   prod.setDeliveryMode(DeliveryMode.PERSISTENT);
   BytesMessage bmt = sess.createBytesMessage();

   bmt.writeBytes(new byte[1024]);

   for (int i = 0; i < 500; i++) {
      prod.send(bmt);
   }

   PagingStore store = server.getPagingManager().getPageStore(new SimpleString("Q1"));

   assertEquals(100 * 1024, store.getMaxSize());
   assertEquals(10 * 1024, store.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());

   jmsServer.stop();

   server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
   server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);

   jmsServer = new JMSServerManagerImpl(server);
   context = new InVMNamingContext();
   jmsServer.setRegistry(new JndiBindingRegistry(context));
   jmsServer.start();

   AddressSettings settings = server.getAddressSettingsRepository().getMatch("Q1");

   assertEquals(100 * 1024, settings.getMaxSizeBytes());
   assertEquals(10 * 1024, settings.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

   store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
   assertEquals(100 * 1024, store.getMaxSize());
   assertEquals(10 * 1024, store.getPageSizeBytes());
   assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
}
 
Example 17
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@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();

}
 
Example 18
Source File: RemoteConnectionStressTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testSimpleRemoteConnections() throws Exception {
   for (int i = 0; i < 1000; i++) {

      TransportConfiguration config = new TransportConfiguration(NETTY_CONNECTOR_FACTORY);
      ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, config);
      cf.setInitialConnectAttempts(10);
      cf.setRetryInterval(100);

      Connection conn = cf.createConnection();

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Queue queue = session.createQueue("SomeQueue");

      MessageProducer producer = session.createProducer(queue);

      TextMessage msg = session.createTextMessage();
      msg.setText("Message " + i);

      producer.send(msg);

      producer.close();
      session.close();
      conn.close();

      cf.close();

   }
}
 
Example 19
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@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();
}
 
Example 20
Source File: JMSReconnectTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testNoReconnectCloseAfterFailToReconnectWithTopicConsumer() 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);

   ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();

   coreSession.createQueue(new QueueConfiguration("blahblah").setAddress("mytopic").setDurable(false));

   Topic topic = ActiveMQJMSClient.createTopic("mytopic");

   //Create a non durable subscriber
   sess.createConsumer(topic);

   Thread.sleep(2000);

   this.server.stop();

   this.server.start();

   sess.close();

   conn.close();
}