Search in sources :

Example 61 with ActiveMQException

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

the class NIOMultiThreadCompactorStressTest method addBogusData.

/**
 * @throws ActiveMQException
 */
private void addBogusData(final int nmessages, final String queue) throws ActiveMQException {
    ClientSession session = sf.createSession(false, false);
    try {
        session.createQueue(queue, queue, true);
    } catch (Exception ignored) {
    }
    ClientProducer prod = session.createProducer(queue);
    for (int i = 0; i < nmessages; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.getBodyBuffer().writeBytes(new byte[1024]);
        prod.send(msg);
    }
    session.commit();
    session.start();
    ClientConsumer cons = session.createConsumer(queue);
    Assert.assertNotNull(cons.receive(1000));
    session.rollback();
    session.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 62 with ActiveMQException

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

the class ClusterConnectionBridge method setupNotificationConsumer.

private void setupNotificationConsumer() throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Setting up notificationConsumer between " + this.clusterConnection.getConnector() + " and " + flowRecord.getBridge().getForwardingConnection() + " clusterConnection = " + this.clusterConnection.getName() + " on server " + clusterConnection.getServer());
    }
    if (flowRecord != null) {
        flowRecord.reset();
        if (notifConsumer != null) {
            try {
                logger.debug("Closing notification Consumer for reopening " + notifConsumer + " on bridge " + this.getName());
                notifConsumer.close();
                notifConsumer = null;
            } catch (ActiveMQException e) {
                ActiveMQServerLogger.LOGGER.errorClosingConsumer(e);
            }
        }
        // Get the queue data
        String qName = "notif." + UUIDGenerator.getInstance().generateStringUUID() + "." + clusterConnection.getServer().toString().replaceAll(CompositeAddress.SEPARATOR, "_");
        SimpleString notifQueueName = new SimpleString(qName);
        SimpleString filter = new SimpleString(ManagementHelper.HDR_BINDING_TYPE + "<>" + BindingType.DIVERT.toInt() + " AND " + ManagementHelper.HDR_NOTIFICATION_TYPE + " IN ('" + CoreNotificationType.BINDING_ADDED + "','" + CoreNotificationType.BINDING_REMOVED + "','" + CoreNotificationType.CONSUMER_CREATED + "','" + CoreNotificationType.CONSUMER_CLOSED + "','" + CoreNotificationType.PROPOSAL + "','" + CoreNotificationType.PROPOSAL_RESPONSE + "','" + CoreNotificationType.UNPROPOSAL + "') AND " + ManagementHelper.HDR_DISTANCE + "<" + flowRecord.getMaxHops() + " AND (" + createSelectorFromAddress(appendIgnoresToFilter(flowRecord.getAddress())) + ")");
        sessionConsumer.createTemporaryQueue(managementNotificationAddress, notifQueueName, filter);
        notifConsumer = sessionConsumer.createConsumer(notifQueueName);
        notifConsumer.setMessageHandler(flowRecord);
        sessionConsumer.start();
        ClientMessage message = sessionConsumer.createMessage(false);
        if (logger.isTraceEnabled()) {
            logger.trace("Requesting sendQueueInfoToQueue through " + this, new Exception("trace"));
        }
        ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "sendQueueInfoToQueue", notifQueueName.toString(), flowRecord.getAddress());
        try (ClientProducer prod = sessionConsumer.createProducer(managementAddress)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Cluster connection bridge on " + clusterConnection + " requesting information on queues");
            }
            prod.send(message);
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 63 with ActiveMQException

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

the class MQTTInterceptorPropertiesTest method testCheckInterceptedMQTTMessageProperties.

@Test(timeout = 60000)
public void testCheckInterceptedMQTTMessageProperties() throws Exception {
    final String addressQueue = name.getMethodName();
    final String msgText = "Test intercepted message";
    final boolean retained = true;
    Map<String, Object> expectedProperties = new ArrayMap<>();
    expectedProperties.put(ADDRESS, addressQueue);
    expectedProperties.put(MESSAGE_TEXT, msgText);
    expectedProperties.put(RETAINED, retained);
    final MQTTClientProvider subscribeProvider = getMQTTClientProvider();
    initializeConnection(subscribeProvider);
    subscribeProvider.subscribe(addressQueue, AT_MOST_ONCE);
    final CountDownLatch latch = new CountDownLatch(1);
    MQTTInterceptor incomingInterceptor = new MQTTInterceptor() {

        @Override
        public boolean intercept(MqttMessage packet, RemotingConnection connection) throws ActiveMQException {
            System.out.println("incoming");
            if (packet.getClass() == MqttPublishMessage.class) {
                return checkMessageProperties(packet, expectedProperties);
            } else {
                return true;
            }
        }
    };
    MQTTInterceptor outgoingInterceptor = new MQTTInterceptor() {

        @Override
        public boolean intercept(MqttMessage packet, RemotingConnection connection) throws ActiveMQException {
            System.out.println("outgoing");
            if (packet.getClass() == MqttPublishMessage.class) {
                return checkMessageProperties(packet, expectedProperties);
            } else {
                return true;
            }
        }
    };
    server.getRemotingService().addIncomingInterceptor(incomingInterceptor);
    server.getRemotingService().addOutgoingInterceptor(outgoingInterceptor);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                byte[] payload = subscribeProvider.receive(10000);
                assertNotNull("Should get a message", payload);
                latch.countDown();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    thread.start();
    final MQTTClientProvider publishProvider = getMQTTClientProvider();
    initializeConnection(publishProvider);
    publishProvider.publish(addressQueue, msgText.getBytes(), AT_MOST_ONCE, retained);
    latch.await(10, TimeUnit.SECONDS);
    subscribeProvider.disconnect();
    publishProvider.disconnect();
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ArrayMap(org.apache.felix.resolver.util.ArrayMap) CountDownLatch(java.util.concurrent.CountDownLatch) MQTTInterceptor(org.apache.activemq.artemis.core.protocol.mqtt.MQTTInterceptor) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 64 with ActiveMQException

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

the class CloseDestroyedConnectionTest method testClosingTemporaryTopicDeletesQueue.

@Test
public void testClosingTemporaryTopicDeletesQueue() throws JMSException, ActiveMQException {
    conn = cf.createConnection();
    Assert.assertEquals(1, server.getRemotingService().getConnections().size());
    session1 = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session1.createTemporaryTopic();
    String address = topic.getAddress();
    session1.close();
    conn.close();
    conn2 = cf.createConnection();
    session2 = (ActiveMQSession) conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ClientSession cs = session2.getCoreSession();
    try {
        cs.createConsumer(address);
        fail("the address from the TemporaryTopic still exists!");
    } catch (ActiveMQException e) {
        assertEquals("expecting 'queue does not exist'", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, e.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQTemporaryTopic(org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic) Test(org.junit.Test)

Example 65 with ActiveMQException

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

the class AcceptorControlTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
    Configuration config = createBasicConfig().addAcceptorConfiguration(acceptorConfig);
    ActiveMQServer service = createServer(false, config);
    service.setMBeanServer(mbeanServer);
    service.start();
    AcceptorControl acceptorControl = createManagementControl(acceptorConfig.getName());
    // started by the server
    Assert.assertTrue(acceptorControl.isStarted());
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    acceptorControl.stop();
    Assert.assertFalse(acceptorControl.isStarted());
    try {
        sf.createSession(false, true, true);
        Assert.fail("acceptor must not accept connections when stopped accepting");
    } catch (ActiveMQException e) {
    }
    acceptorControl.start();
    Assert.assertTrue(acceptorControl.isStarted());
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    acceptorControl.stop();
    Assert.assertFalse(acceptorControl.isStarted());
    try {
        sf.createSession(false, true, true);
        Assert.fail("acceptor must not accept connections when stopped accepting");
    } catch (ActiveMQException e) {
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AcceptorControl(org.apache.activemq.artemis.api.core.management.AcceptorControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)140 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15