Java Code Examples for org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory#createConnection()

The following examples show how to use org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory#createConnection() . 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: JMSUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static Connection createConnection(final String connectorFactory) throws JMSException {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));

   cf.setBlockOnNonDurableSend(true);
   cf.setBlockOnDurableSend(true);
   cf.setBlockOnAcknowledge(true);

   return cf.createConnection();
}
 
Example 2
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 3
Source File: PagingOrderTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testPagingOverCreatedDestinationTopics() throws Exception {

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

   ActiveMQServer server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

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

   jmsServer.createTopic(true, "tt", "/topic/TT");

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

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

   Connection conn = cf.createConnection();
   conn.setClientID("tst");
   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Topic topic = (Topic) context.lookup("/topic/TT");
   sess.createDurableSubscriber(topic, "t1");

   MessageProducer prod = sess.createProducer(topic);
   prod.setDeliveryMode(DeliveryMode.PERSISTENT);
   TextMessage txt = sess.createTextMessage("TST");
   prod.send(txt);

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

   assertEquals(1024 * 1024, store.getMaxSize());
   assertEquals(10 * 1024, store.getPageSizeBytes());

   jmsServer.stop();

   server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

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

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

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

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

   conn.close();

   server.stop();

}