Search in sources :

Example 21 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.

the class PagingOrderTest method testPagingOverCreatedDestinationQueues.

@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());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) BytesMessage(javax.jms.BytesMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(org.apache.activemq.artemis.core.server.Queue) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 22 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.

the class JmsReceive method main.

public static void main(String[] args) throws Exception {
    System.out.println("Receive Setup...");
    ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
    Destination destination = ActiveMQDestination.fromPrefixedName("queue://orders");
    try (Connection conn = factory.createConnection()) {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                System.out.println("Received Message: ");
                Order order = Jms.getEntity(message, Order.class);
                System.out.println(order);
            }
        });
        conn.start();
        Thread.sleep(1000000);
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 23 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.

the class ReceiveShipping method main.

public static void main(String[] args) throws Exception {
    ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
    Destination destination = ActiveMQDestination.fromPrefixedName("queue://shipping");
    try (Connection conn = factory.createConnection()) {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(Message message) {
                System.out.println("Received Message: ");
                Order order = Jms.getEntity(message, Order.class);
                System.out.println(order);
            }
        });
        conn.start();
        Thread.sleep(1000000);
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 24 with ActiveMQJMSConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.

the class GroupIDTest method getCF.

@Override
protected ConnectionFactory getCF() throws Exception {
    ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    cf.setGroupID("wibble");
    return cf;
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Aggregations

ActiveMQJMSConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)13 Connection (javax.jms.Connection)12 Test (org.junit.Test)11 Session (javax.jms.Session)9 ConnectionFactory (javax.jms.ConnectionFactory)8 MessageProducer (javax.jms.MessageProducer)7 Destination (javax.jms.Destination)6 JMSException (javax.jms.JMSException)6 ConnectionFactoryFactory (org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory)6 DestinationFactory (org.apache.activemq.artemis.jms.bridge.DestinationFactory)6 TransactionManager (javax.transaction.TransactionManager)5 JMSBridgeImpl (org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl)5 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)5 MessageConsumer (javax.jms.MessageConsumer)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 HashMap (java.util.HashMap)2