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);
}
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);
}
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);
}
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;
}
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());
}
}
Aggregations