Search in sources :

Example 6 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 7 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)

Example 8 with ClientSessionFactory

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

the class ActiveMQActivation method setup.

/**
 * Setup the activation
 *
 * @throws Exception Thrown if an error occurs
 */
protected synchronized void setup() throws Exception {
    logger.debug("Setting up " + spec);
    setupCF();
    setupDestination();
    Exception firstException = null;
    for (int i = 0; i < spec.getMaxSession(); i++) {
        ClientSessionFactory cf = null;
        ClientSession session = null;
        try {
            cf = factory.getServerLocator().createSessionFactory();
            session = setupSession(cf);
            ActiveMQMessageHandler handler = new ActiveMQMessageHandler(factory, this, ra.getTM(), (ClientSessionInternal) session, cf, i);
            handler.setup();
            handlers.add(handler);
        } catch (Exception e) {
            if (cf != null) {
                cf.close();
            }
            if (session != null) {
                session.close();
            }
            if (firstException == null) {
                firstException = e;
            }
        }
    }
    // we don't want partially configured activations, i.e. only 8 out of 15 sessions started so best to stop and log the error.
    if (firstException != null) {
        for (ActiveMQMessageHandler handler : handlers) {
            handler.teardown();
        }
        throw firstException;
    }
    // now start them all together.
    for (ActiveMQMessageHandler handler : handlers) {
        handler.start();
    }
    Map<String, String> recoveryConfProps = new HashMap<>();
    recoveryConfProps.put(XARecoveryConfig.JNDI_NAME_PROPERTY_KEY, ra.getJndiName());
    resourceRecovery = ra.getRecoveryManager().register(factory, spec.getUser(), spec.getPassword(), recoveryConfProps);
    if (spec.isRebalanceConnections()) {
        factory.getServerLocator().addClusterTopologyListener(new RebalancingListener());
    }
    logger.debug("Setup complete " + this);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ResourceException(javax.resource.ResourceException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)

Example 9 with ClientSessionFactory

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

the class ActiveMQConnectionFactory method createConnectionInternal.

// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
protected synchronized ActiveMQConnection createConnectionInternal(final String username, final String password, final boolean isXA, final int type) throws JMSException {
    readOnly = true;
    ClientSessionFactory factory;
    try {
        factory = serverLocator.createSessionFactory();
    } catch (Exception e) {
        JMSException jmse = new JMSException("Failed to create session factory");
        jmse.initCause(e);
        jmse.setLinkedException(e);
        throw jmse;
    }
    ActiveMQConnection connection = null;
    if (isXA) {
        if (type == ActiveMQConnection.TYPE_GENERIC_CONNECTION) {
            connection = new ActiveMQXAConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        } else if (type == ActiveMQConnection.TYPE_QUEUE_CONNECTION) {
            connection = new ActiveMQXAConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        } else if (type == ActiveMQConnection.TYPE_TOPIC_CONNECTION) {
            connection = new ActiveMQXAConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        }
    } else {
        if (type == ActiveMQConnection.TYPE_GENERIC_CONNECTION) {
            connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        } else if (type == ActiveMQConnection.TYPE_QUEUE_CONNECTION) {
            connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        } else if (type == ActiveMQConnection.TYPE_TOPIC_CONNECTION) {
            connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, factory);
        }
    }
    if (connection == null) {
        throw new JMSException("Failed to create connection: invalid type " + type);
    }
    connection.setReference(this);
    try {
        connection.authorize();
    } catch (JMSException e) {
        try {
            connection.close();
        } catch (JMSException me) {
        }
        throw e;
    }
    return connection;
}
Also used : JMSException(javax.jms.JMSException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) InvalidObjectException(java.io.InvalidObjectException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSSecurityException(javax.jms.JMSSecurityException) JMSSecurityRuntimeException(javax.jms.JMSSecurityRuntimeException)

Example 10 with ClientSessionFactory

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

the class JmsQueueCompositeSendReceiveTest method testDuplicate.

public void testDuplicate() throws Exception {
    ActiveMQDestination queue = (ActiveMQDestination) session.createQueue("TEST,TEST");
    for (int i = 0; i < data.length; i++) {
        Message message = createMessage(i);
        configureMessage(message);
        if (verbose) {
            LOG.info("About to send a message: " + message + " with text: " + data[i]);
        }
        producer.send(queue, message);
    }
    // wait for messages to be queue;
    Thread.sleep(200);
    try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
        ClientSessionFactory factory = locator.createSessionFactory();
        ClientSession session = factory.createSession()) {
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString("TEST"));
        assertNotNull(query);
        assertEquals(data.length, query.getMessageCount());
    }
}
Also used : Message(javax.jms.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

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)465 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