Search in sources :

Example 1 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project candlepin by candlepin.

the class ActiveMQContextListener method cleanupOldQueues.

/**
 * Remove any old message queues that have a 0 message count in them.
 * This lets us not worry about changing around the registered listeners.
 */
private void cleanupOldQueues() {
    log.debug("Cleaning old message queues");
    try {
        String[] queues = activeMQServer.getActiveMQServer().getActiveMQServerControl().getQueueNames();
        ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName()));
        ClientSessionFactory factory = locator.createSessionFactory();
        ClientSession session = factory.createSession(true, true);
        session.start();
        for (int i = 0; i < queues.length; i++) {
            long msgCount = session.queueQuery(new SimpleString(queues[i])).getMessageCount();
            if (msgCount == 0) {
                log.debug(String.format("found queue '%s' with 0 messages. deleting", queues[i]));
                session.deleteQueue(queues[i]);
            } else {
                log.debug(String.format("found queue '%s' with %d messages. kept", queues[i], msgCount));
            }
        }
        session.stop();
        session.close();
    } catch (Exception e) {
        log.error("Problem cleaning old message queues:", e);
        throw new RuntimeException("Problem cleaning message queue", e);
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 2 with ClientSessionFactory

use of org.apache.activemq.artemis.api.core.client.ClientSessionFactory in project candlepin by candlepin.

the class EventSinkImplTest method eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor.

/**
 *Set up the {@link ClientSessionFactory} to throw an exception when
 * {@link ClientSessionFactory#createSession()} is called.
 * Make sure, we throw up our hands saying "I am not dealing with this".
 * @throws Exception
 */
@Test(expected = RuntimeException.class)
public void eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor() throws Exception {
    final ClientSessionFactory csFactory = mock(ClientSessionFactory.class);
    doThrow(new ActiveMQException()).when(csFactory.createSession());
    createEventSink(csFactory);
    fail("Runtime exception should have been thrown.");
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Test(org.junit.Test)

Example 3 with ClientSessionFactory

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

the class ServerLocatorImpl method notifyNodeUp.

@Override
public void notifyNodeUp(long uniqueEventID, final String nodeID, final String backupGroupName, final String scaleDownGroupName, final Pair<TransportConfiguration, TransportConfiguration> connectorPair, final boolean last) {
    if (logger.isTraceEnabled()) {
        logger.trace("NodeUp " + this + "::nodeID=" + nodeID + ", connectorPair=" + connectorPair, new Exception("trace"));
    }
    TopologyMemberImpl member = new TopologyMemberImpl(nodeID, backupGroupName, scaleDownGroupName, connectorPair.getA(), connectorPair.getB());
    topology.updateMember(uniqueEventID, nodeID, member);
    TopologyMember actMember = topology.getMember(nodeID);
    if (actMember != null && actMember.getLive() != null && actMember.getBackup() != null) {
        HashSet<ClientSessionFactory> clonedFactories = new HashSet<>();
        synchronized (factories) {
            clonedFactories.addAll(factories);
        }
        for (ClientSessionFactory factory : clonedFactories) {
            ((ClientSessionFactoryInternal) factory).setBackupConnector(actMember.getLive(), actMember.getBackup());
        }
    }
    updateArraysAndPairs(uniqueEventID);
    if (last) {
        receivedTopology = true;
    }
}
Also used : TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ObjectStreamException(java.io.ObjectStreamException) HashSet(java.util.HashSet)

Example 4 with ClientSessionFactory

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

the class ClientConsumerImpl method handleLargeMessage.

@Override
public synchronized void handleLargeMessage(final ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) throws Exception {
    if (closing) {
        // This is ok - we just ignore the message
        return;
    }
    // Flow control for the first packet, we will have others
    File largeMessageCache = null;
    if (session.isCacheLargeMessageClient()) {
        largeMessageCache = File.createTempFile("tmp-large-message-" + clientLargeMessage.getMessageID() + "-", ".tmp");
        largeMessageCache.deleteOnExit();
    }
    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();
    currentLargeMessageController = new LargeMessageControllerImpl(this, largeMessageSize, callTimeout, largeMessageCache);
    if (clientLargeMessage.isCompressed()) {
        clientLargeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    } else {
        clientLargeMessage.setLargeMessageController(currentLargeMessageController);
    }
    handleRegularMessage(clientLargeMessage);
}
Also used : ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 5 with ClientSessionFactory

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

the class XmlDataImporter method process.

public void process(InputStream inputStream, String host, int port, boolean transactional) throws Exception {
    HashMap<String, Object> connectionParams = new HashMap<>();
    connectionParams.put(TransportConstants.HOST_PROP_NAME, host);
    connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.toString(port));
    ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams));
    ClientSessionFactory sf = serverLocator.createSessionFactory();
    ClientSession session;
    ClientSession managementSession;
    if (user != null || password != null) {
        session = sf.createSession(user, password, false, !transactional, true, false, 0);
        managementSession = sf.createSession(user, password, false, true, true, false, 0);
    } else {
        session = sf.createSession(false, !transactional, true);
        managementSession = sf.createSession(false, true, true);
    }
    localSession = true;
    process(inputStream, session, managementSession);
}
Also used : HashMap(java.util.HashMap) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Aggregations

ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)601 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)518 Test (org.junit.Test)464 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)395 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)372 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)350 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)277 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)254 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)206 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)108 Configuration (org.apache.activemq.artemis.core.config.Configuration)78 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)65 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)63 CountDownLatch (java.util.concurrent.CountDownLatch)54 Queue (org.apache.activemq.artemis.core.server.Queue)49 ArrayList (java.util.ArrayList)44 HashMap (java.util.HashMap)43 HashSet (java.util.HashSet)42 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)42 Message (org.apache.activemq.artemis.api.core.Message)41