Search in sources :

Example 1 with TransportConfiguration

use of org.hornetq.api.core.TransportConfiguration in project perun by CESNET.

the class SystemQueueProcessor method startProcessingSystemMessages.

public void startProcessingSystemMessages() {
    connection = null;
    try {
        // Step 2. Instantiate the TransportConfiguration object which
        // contains the knowledge of what transport to use,
        // The server port etc.
        log.debug("Creating transport configuration...");
        Map<String, Object> connectionParams = new HashMap<String, Object>();
        if (log.isDebugEnabled()) {
            log.debug("Gonna connect to the host[" + dispatcherPropertiesBean.getProperty("dispatcher.ip.address") + "] on port[" + dispatcherPropertiesBean.getProperty("dispatcher.port") + "]...");
        }
        connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.parseInt(dispatcherPropertiesBean.getProperty("dispatcher.port")));
        connectionParams.put(TransportConstants.HOST_PROP_NAME, dispatcherPropertiesBean.getProperty("dispatcher.ip.address"));
        TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
        // Step 3 Directly instantiate the JMS ConnectionFactory object
        // using that TransportConfiguration
        log.debug("Creating connection factory...");
        cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
        ((HornetQConnectionFactory) cf).setUseGlobalPools(false);
        // Step 4.Create a JMS Connection
        log.debug("Creating connection...");
        connection = cf.createConnection();
        // Step 5. Create a JMS Session
        log.debug("Creating session...");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 10. Start the Connection
        log.debug("Starting connection...");
        connection.start();
        if (processingMessages) {
            systemQueueReceiver.stop();
        }
        systemQueueReceiver.setUp("systemQueue", session);
        log.debug("Executor: taskExecutor.execute(systemQueueReceiver)...");
        taskExecutor.execute(systemQueueReceiver);
        log.debug("Initialization done.");
        processingMessages = true;
    } catch (JMSException e) {
        // If unable to connect to the server...
        log.error("Connection failed. \nThis is weird...are you sure that the Perun-Dispatcher is running on host[" + dispatcherPropertiesBean.getProperty("dispatcher.ip.address") + "] on port[" + dispatcherPropertiesBean.getProperty("dispatcher.port") + "] ? \nSee: perun-dispatcher.properties. We gonna wait 5 sec and try again...", e);
        throw new RuntimeException(e);
    } catch (Exception e) {
        log.error(e.toString(), e);
    }
}
Also used : HornetQConnectionFactory(org.hornetq.jms.client.HornetQConnectionFactory) NettyConnectorFactory(org.hornetq.core.remoting.impl.netty.NettyConnectorFactory) HashMap(java.util.HashMap) TransportConfiguration(org.hornetq.api.core.TransportConfiguration) JMSException(javax.jms.JMSException) MessageFormatException(cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException) JMSException(javax.jms.JMSException) PerunHornetQServerException(cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException)

Example 2 with TransportConfiguration

use of org.hornetq.api.core.TransportConfiguration in project perun by CESNET.

the class JMSQueueManager method initiateConnection.

public void initiateConnection() {
    while (needToConnect) {
        try {
            // Step 2. Instantiate the TransportConfiguration object which
            // contains the knowledge of what transport to use,
            // The server port etc.
            Map<String, Object> connectionParams = new HashMap<String, Object>();
            if (log.isDebugEnabled()) {
                log.debug("Gonna connect to the host[" + propertiesBean.getProperty("dispatcher.ip.address") + "] on port[" + propertiesBean.getProperty("dispatcher.port") + "]...");
            }
            connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.parseInt(propertiesBean.getProperty("dispatcher.port")));
            connectionParams.put(TransportConstants.HOST_PROP_NAME, propertiesBean.getProperty("dispatcher.ip.address"));
            TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
            // Step 3 Directly instantiate the JMS ConnectionFactory object
            // using that TransportConfiguration
            ConnectionFactory cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
            // Step 4.Create a JMS Connection
            connection = cf.createConnection();
            // Step 5. Create a JMS Session
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            // Step 10. Start the Connection
            connection.start();
            systemInitiated = true;
            needToConnect = false;
            waitTime = 0;
        } catch (JMSException e) {
            // If unable to connect to the server...
            needToConnect = true;
            waitTime = waitTime + 10000;
            log.error("Connection failed. We gonna wait " + (waitTime / 1000) + " s and try again...", e);
            try {
                Thread.sleep(waitTime);
            } catch (InterruptedException e1) {
                log.error(e1.toString(), e1);
            }
        }
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) NettyConnectorFactory(org.hornetq.core.remoting.impl.netty.NettyConnectorFactory) HashMap(java.util.HashMap) TransportConfiguration(org.hornetq.api.core.TransportConfiguration) JMSException(javax.jms.JMSException)

Example 3 with TransportConfiguration

use of org.hornetq.api.core.TransportConfiguration in project wildfly by wildfly.

the class LegacyConnectionFactoryService method start.

@Override
public void start(StartContext context) throws StartException {
    ActiveMQServer activeMQServer = injectedActiveMQServer.getValue();
    DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
    if (discoveryGroupName != null) {
        if (activeMQServer.getConfiguration().getDiscoveryGroupConfigurations().keySet().contains(discoveryGroupName)) {
            discoveryGroupConfiguration = translateDiscoveryGroupConfiguration(activeMQServer.getConfiguration().getDiscoveryGroupConfigurations().get(discoveryGroupName));
        } else {
            throw MessagingLogger.ROOT_LOGGER.discoveryGroupIsNotDefined(discoveryGroupName);
        }
    }
    TransportConfiguration[] transportConfigurations = translateTransportGroupConfigurations(activeMQServer.getConfiguration().getConnectorConfigurations(), connectors);
    JMSFactoryType factoryType = JMSFactoryType.valueOf(uncompletedConnectionFactory.getFactoryType());
    if (uncompletedConnectionFactory.isHA()) {
        if (discoveryGroupConfiguration != null) {
            connectionFactory = HornetQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, factoryType);
        } else {
            connectionFactory = HornetQJMSClient.createConnectionFactoryWithHA(factoryType, transportConfigurations);
        }
    } else {
        if (discoveryGroupConfiguration != null) {
            connectionFactory = HornetQJMSClient.createConnectionFactoryWithoutHA(discoveryGroupConfiguration, factoryType);
        } else {
            connectionFactory = HornetQJMSClient.createConnectionFactoryWithoutHA(factoryType, transportConfigurations);
        }
    }
    connectionFactory.setAutoGroup(uncompletedConnectionFactory.isAutoGroup());
    connectionFactory.setBlockOnAcknowledge(uncompletedConnectionFactory.isBlockOnAcknowledge());
    connectionFactory.setBlockOnDurableSend(uncompletedConnectionFactory.isBlockOnDurableSend());
    connectionFactory.setBlockOnNonDurableSend(uncompletedConnectionFactory.isBlockOnNonDurableSend());
    connectionFactory.setCacheLargeMessagesClient(uncompletedConnectionFactory.isCacheLargeMessagesClient());
    connectionFactory.setCallFailoverTimeout(uncompletedConnectionFactory.getCallFailoverTimeout());
    connectionFactory.setCallTimeout(uncompletedConnectionFactory.getCallTimeout());
    connectionFactory.setClientFailureCheckPeriod(uncompletedConnectionFactory.getClientFailureCheckPeriod());
    connectionFactory.setClientID(uncompletedConnectionFactory.getClientID());
    connectionFactory.setCompressLargeMessage(uncompletedConnectionFactory.isCompressLargeMessage());
    connectionFactory.setConfirmationWindowSize(uncompletedConnectionFactory.getConfirmationWindowSize());
    connectionFactory.setConnectionLoadBalancingPolicyClassName(uncompletedConnectionFactory.getConnectionLoadBalancingPolicyClassName());
    connectionFactory.setConnectionTTL(uncompletedConnectionFactory.getConnectionTTL());
    connectionFactory.setConsumerMaxRate(uncompletedConnectionFactory.getConsumerMaxRate());
    connectionFactory.setConsumerWindowSize(uncompletedConnectionFactory.getConsumerWindowSize());
    connectionFactory.setConfirmationWindowSize(uncompletedConnectionFactory.getConfirmationWindowSize());
    connectionFactory.setDupsOKBatchSize(uncompletedConnectionFactory.getDupsOKBatchSize());
    connectionFactory.setFailoverOnInitialConnection(uncompletedConnectionFactory.isFailoverOnInitialConnection());
    connectionFactory.setGroupID(uncompletedConnectionFactory.getGroupID());
    connectionFactory.setInitialConnectAttempts(uncompletedConnectionFactory.getInitialConnectAttempts());
    connectionFactory.setInitialMessagePacketSize(uncompletedConnectionFactory.getInitialMessagePacketSize());
    connectionFactory.setMaxRetryInterval(uncompletedConnectionFactory.getMaxRetryInterval());
    connectionFactory.setMinLargeMessageSize(uncompletedConnectionFactory.getMinLargeMessageSize());
    connectionFactory.setPreAcknowledge(uncompletedConnectionFactory.isPreAcknowledge());
    connectionFactory.setProducerMaxRate(uncompletedConnectionFactory.getProducerMaxRate());
    connectionFactory.setProducerWindowSize(uncompletedConnectionFactory.getProducerWindowSize());
    connectionFactory.setReconnectAttempts(uncompletedConnectionFactory.getReconnectAttempts());
    connectionFactory.setRetryInterval(uncompletedConnectionFactory.getRetryInterval());
    connectionFactory.setRetryIntervalMultiplier(uncompletedConnectionFactory.getRetryIntervalMultiplier());
    connectionFactory.setScheduledThreadPoolMaxSize(uncompletedConnectionFactory.getScheduledThreadPoolMaxSize());
    connectionFactory.setThreadPoolMaxSize(uncompletedConnectionFactory.getThreadPoolMaxSize());
    connectionFactory.setTransactionBatchSize(uncompletedConnectionFactory.getTransactionBatchSize());
    connectionFactory.setUseGlobalPools(uncompletedConnectionFactory.isUseGlobalPools());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSFactoryType(org.hornetq.api.jms.JMSFactoryType) TransportConfiguration(org.hornetq.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.hornetq.api.core.DiscoveryGroupConfiguration)

Example 4 with TransportConfiguration

use of org.hornetq.api.core.TransportConfiguration in project wildfly by wildfly.

the class LegacyConnectionFactoryService method translateTransportGroupConfigurations.

private TransportConfiguration[] translateTransportGroupConfigurations(Map<String, org.apache.activemq.artemis.api.core.TransportConfiguration> connectorConfigurations, List<String> connectors) throws StartException {
    List<org.hornetq.api.core.TransportConfiguration> legacyConnectorConfigurations = new ArrayList<>();
    for (String connectorName : connectors) {
        org.apache.activemq.artemis.api.core.TransportConfiguration newTransportConfiguration = connectorConfigurations.get(connectorName);
        String legacyFactoryClassName = translateFactoryClassName(newTransportConfiguration.getFactoryClassName());
        Map legacyParams = translateParams(newTransportConfiguration.getParams());
        org.hornetq.api.core.TransportConfiguration legacyTransportConfiguration = new org.hornetq.api.core.TransportConfiguration(legacyFactoryClassName, legacyParams, newTransportConfiguration.getName());
        legacyConnectorConfigurations.add(legacyTransportConfiguration);
    }
    return legacyConnectorConfigurations.toArray(new org.hornetq.api.core.TransportConfiguration[legacyConnectorConfigurations.size()]);
}
Also used : ArrayList(java.util.ArrayList) TransportConfiguration(org.hornetq.api.core.TransportConfiguration) TransportConfiguration(org.hornetq.api.core.TransportConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TransportConfiguration (org.hornetq.api.core.TransportConfiguration)4 HashMap (java.util.HashMap)3 JMSException (javax.jms.JMSException)2 NettyConnectorFactory (org.hornetq.core.remoting.impl.netty.NettyConnectorFactory)2 MessageFormatException (cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException)1 PerunHornetQServerException (cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConnectionFactory (javax.jms.ConnectionFactory)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 DiscoveryGroupConfiguration (org.hornetq.api.core.DiscoveryGroupConfiguration)1 JMSFactoryType (org.hornetq.api.jms.JMSFactoryType)1 HornetQConnectionFactory (org.hornetq.jms.client.HornetQConnectionFactory)1