Search in sources :

Example 66 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class JMSBridgeImplTest method doTestAutoAckOnSource.

public void doTestAutoAckOnSource(int maxBatchSize) throws Exception {
    final int numMessages = maxBatchSize;
    ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
    ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
    DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
    DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
    TransactionManager tm = JMSBridgeImplTest.newTransactionManager();
    JMSBridgeImpl bridge = new JMSBridgeImpl();
    Assert.assertNotNull(bridge);
    bridge.setSourceConnectionFactoryFactory(sourceCFF);
    bridge.setSourceDestinationFactory(sourceDF);
    bridge.setTargetConnectionFactoryFactory(targetCFF);
    bridge.setTargetDestinationFactory(targetDF);
    bridge.setFailureRetryInterval(10);
    bridge.setMaxRetries(1);
    bridge.setMaxBatchSize(maxBatchSize);
    bridge.setMaxBatchTime(-1);
    bridge.setTransactionManager(tm);
    bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
    Assert.assertFalse(bridge.isStarted());
    bridge.start();
    Assert.assertTrue(bridge.isStarted());
    Connection sourceConn = JMSBridgeImplTest.createConnectionFactory().createConnection();
    Session sourceSess = sourceConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sourceSess.createProducer(sourceDF.createDestination());
    for (int i = 0; i < numMessages; i++) {
        TextMessage msg = sourceSess.createTextMessage();
        producer.send(msg);
        JMSBridgeImplTest.log.info("sent message " + i);
    }
    sourceConn.close();
    SimpleString add = new SimpleString(JMSBridgeImplTest.SOURCE);
    QueueControl jmsQueueControl = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), ObjectNameBuilder.DEFAULT.getQueueObjectName(add, add, RoutingType.ANYCAST), QueueControl.class, false);
    assertNotEquals(jmsQueueControl.getDeliveringCount(), numMessages);
    bridge.stop();
    Assert.assertFalse(bridge.isStarted());
}
Also used : DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) TransactionManager(javax.transaction.TransactionManager) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Session(javax.jms.Session)

Example 67 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testCreateAndDestroyQueue.

@Test
public void testCreateAndDestroyQueue() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createAddress(address.toString(), "ANYCAST");
    serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, true, -1, false, false);
    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(true, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());
    serverControl.destroyQueue(name.toString());
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 68 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testCreateAndDestroyQueueWithNullFilter.

@Test
public void testCreateAndDestroyQueueWithNullFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = null;
    boolean durable = true;
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createAddress(address.toString(), "ANYCAST");
    serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), filter, durable, -1, false, false);
    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());
    serverControl.destroyQueue(name.toString());
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 69 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class ManagementWithPagingServerTest method testListMessagesAsJSON.

@Test
public void testListMessagesAsJSON() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session1.createQueue(address, queue, null, true);
    QueueControl queueControl = createManagementControl(address, queue);
    int num = 1000;
    SenderThread sender = new SenderThread(address, num, 0);
    ReceiverThread receiver = new ReceiverThread(queue, num, 0);
    // kick off sender
    sender.start();
    // wait for all messages sent
    sender.join();
    assertNull(sender.getError());
    long count = queueControl.countMessages(null);
    assertEquals(num, count);
    String result = queueControl.listMessagesAsJSON(null);
    JsonArray array = JsonUtil.readJsonArray(result);
    List<Long> longs = new ArrayList<>();
    for (JsonValue jsonValue : array) {
        JsonValue val = ((JsonObject) jsonValue).get("messageID");
        Long l = ((JsonLongImpl) val).longValue();
        if (longs.contains(l)) {
            System.out.println("ManagementWithPagingServerTest.testListMessagesAsJSON");
        }
        longs.add(l);
        System.out.println("jsonValue = " + jsonValue);
    }
    assertEquals(num, array.size());
    // kick off receiver
    receiver.start();
    receiver.join();
    assertNull(receiver.getError());
    result = queueControl.listMessagesAsJSON(null);
    array = JsonUtil.readJsonArray(result);
    assertEquals(0, array.size());
}
Also used : JsonLongImpl(org.apache.johnzon.core.JsonLongImpl) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) JsonArray(javax.json.JsonArray) Test(org.junit.Test)

Example 70 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class ManagementWithPagingServerTest method testListMessagesAsJSONWithFilter.

@Test
public void testListMessagesAsJSONWithFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session1.createQueue(address, queue, null, true);
    QueueControl queueControl = createManagementControl(address, queue);
    int num = 1000;
    SimpleString key = new SimpleString("key");
    long matchingValue = RandomUtil.randomLong();
    long unmatchingValue = matchingValue + 1;
    String filter = key + " =" + matchingValue;
    byte[] body = new byte[64];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= 64; j++) {
        bb.put(getSamplebyte(j));
    }
    ClientProducer producer = session1.createProducer(address);
    for (int i = 0; i < num; i++) {
        ClientMessage message = session1.createMessage(true);
        if (i % 2 == 0) {
            message.putLongProperty(key, matchingValue);
        } else {
            message.putLongProperty(key, unmatchingValue);
        }
        producer.send(message);
    }
    String jsonString = queueControl.listMessagesAsJSON(filter);
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(num / 2, array.size());
    long l = Long.parseLong(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
    Assert.assertEquals(matchingValue, l);
    long n = queueControl.countMessages(filter);
    assertEquals(num / 2, n);
    // drain out messages
    ReceiverThread receiver = new ReceiverThread(queue, num, 1);
    receiver.start();
    receiver.join();
}
Also used : JsonArray(javax.json.JsonArray) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Aggregations

QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)109 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)87 Test (org.junit.Test)79 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)50 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)33 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)24 HashMap (java.util.HashMap)21 Map (java.util.Map)18 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)9 ArrayList (java.util.ArrayList)7 JsonObject (javax.json.JsonObject)7 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)7 MessageProducer (javax.jms.MessageProducer)6 TextMessage (javax.jms.TextMessage)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Session (javax.jms.Session)5 JsonArray (javax.json.JsonArray)5 Queue (org.apache.activemq.artemis.core.server.Queue)5