Search in sources :

Example 1 with HornetQConnectionFactory

use of org.hornetq.jms.client.HornetQConnectionFactory 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 HornetQConnectionFactory

use of org.hornetq.jms.client.HornetQConnectionFactory in project wildfly by wildfly.

the class LegacyConnectionFactoryAdd method createLegacyConnectionFactory.

private HornetQConnectionFactory createLegacyConnectionFactory(OperationContext context, ModelNode model) throws OperationFailedException {
    boolean ha = LegacyConnectionFactoryDefinition.HA.resolveModelAttribute(context, model).asBoolean();
    String factoryTypeStr = LegacyConnectionFactoryDefinition.FACTORY_TYPE.resolveModelAttribute(context, model).asString();
    JMSFactoryType factoryType = LegacyConnectionFactoryDefinition.HornetQConnectionFactoryType.valueOf(factoryTypeStr).getType();
    final HornetQConnectionFactory incompleteCF;
    if (ha) {
        incompleteCF = HornetQJMSClient.createConnectionFactoryWithHA(factoryType);
    } else {
        incompleteCF = HornetQJMSClient.createConnectionFactoryWithoutHA(factoryType);
    }
    incompleteCF.setAutoGroup(AUTO_GROUP.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setBlockOnAcknowledge(BLOCK_ON_ACKNOWLEDGE.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setBlockOnDurableSend(BLOCK_ON_DURABLE_SEND.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setBlockOnNonDurableSend(BLOCK_ON_NON_DURABLE_SEND.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setCacheLargeMessagesClient(CACHE_LARGE_MESSAGE_CLIENT.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setCallFailoverTimeout(CALL_FAILOVER_TIMEOUT.resolveModelAttribute(context, model).asLong());
    incompleteCF.setCallTimeout(CALL_TIMEOUT.resolveModelAttribute(context, model).asLong());
    incompleteCF.setClientFailureCheckPeriod(CLIENT_FAILURE_CHECK_PERIOD.resolveModelAttribute(context, model).asLong());
    final ModelNode clientID = CLIENT_ID.resolveModelAttribute(context, model);
    if (clientID.isDefined()) {
        incompleteCF.setClientID(clientID.asString());
    }
    incompleteCF.setCompressLargeMessage(COMPRESS_LARGE_MESSAGES.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setConfirmationWindowSize(CONFIRMATION_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    final ModelNode connectionLoadBalancingClassName = CONNECTION_LOAD_BALANCING_CLASS_NAME.resolveModelAttribute(context, model);
    if (connectionLoadBalancingClassName.isDefined()) {
        incompleteCF.setConnectionLoadBalancingPolicyClassName(connectionLoadBalancingClassName.asString());
    }
    incompleteCF.setConnectionTTL(CONNECTION_TTL.resolveModelAttribute(context, model).asLong());
    incompleteCF.setConsumerMaxRate(CONSUMER_MAX_RATE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setConsumerWindowSize(CONSUMER_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setConfirmationWindowSize(CONFIRMATION_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setDupsOKBatchSize(DUPS_OK_BATCH_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setFailoverOnInitialConnection(FAILOVER_ON_INITIAL_CONNECTION.resolveModelAttribute(context, model).asBoolean());
    final ModelNode groupID = GROUP_ID.resolveModelAttribute(context, model);
    if (groupID.isDefined()) {
        incompleteCF.setGroupID(groupID.asString());
    }
    incompleteCF.setInitialConnectAttempts(INITIAL_CONNECT_ATTEMPTS.resolveModelAttribute(context, model).asInt());
    incompleteCF.setInitialMessagePacketSize(INITIAL_MESSAGE_PACKET_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setMaxRetryInterval(MAX_RETRY_INTERVAL.resolveModelAttribute(context, model).asLong());
    incompleteCF.setMinLargeMessageSize(MIN_LARGE_MESSAGE_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setPreAcknowledge(PRE_ACKNOWLEDGE.resolveModelAttribute(context, model).asBoolean());
    incompleteCF.setProducerMaxRate(PRODUCER_MAX_RATE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setProducerWindowSize(PRODUCER_WINDOW_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setReconnectAttempts(RECONNECT_ATTEMPTS.resolveModelAttribute(context, model).asInt());
    incompleteCF.setRetryInterval(RETRY_INTERVAL.resolveModelAttribute(context, model).asLong());
    incompleteCF.setRetryIntervalMultiplier(RETRY_INTERVAL_MULTIPLIER.resolveModelAttribute(context, model).asDouble());
    incompleteCF.setScheduledThreadPoolMaxSize(SCHEDULED_THREAD_POOL_MAX_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setThreadPoolMaxSize(THREAD_POOL_MAX_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setTransactionBatchSize(TRANSACTION_BATCH_SIZE.resolveModelAttribute(context, model).asInt());
    incompleteCF.setUseGlobalPools(USE_GLOBAL_POOLS.resolveModelAttribute(context, model).asBoolean());
    return incompleteCF;
}
Also used : HornetQConnectionFactory(org.hornetq.jms.client.HornetQConnectionFactory) JMSFactoryType(org.hornetq.api.jms.JMSFactoryType) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with HornetQConnectionFactory

use of org.hornetq.jms.client.HornetQConnectionFactory in project wildfly by wildfly.

the class LegacyConnectionFactoryAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    String name = context.getCurrentAddressValue();
    final ServiceName activeMQServerServiceName = MessagingServices.getActiveMQServiceName(context.getCurrentAddress());
    HornetQConnectionFactory incompleteCF = createLegacyConnectionFactory(context, model);
    ModelNode discoveryGroup = DISCOVERY_GROUP.resolveModelAttribute(context, model);
    String discoveryGroupName = discoveryGroup.isDefined() ? discoveryGroup.asString() : null;
    LegacyConnectionFactoryService service = LegacyConnectionFactoryService.installService(name, activeMQServerServiceName, context.getServiceTarget(), incompleteCF, discoveryGroupName, CONNECTORS.unwrap(context, model));
    for (String legacyEntry : LegacyConnectionFactoryDefinition.ENTRIES.unwrap(context, model)) {
        BinderServiceUtil.installBinderService(context.getServiceTarget(), legacyEntry, service, new ServiceName[0]);
    }
}
Also used : HornetQConnectionFactory(org.hornetq.jms.client.HornetQConnectionFactory) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

HornetQConnectionFactory (org.hornetq.jms.client.HornetQConnectionFactory)3 ModelNode (org.jboss.dmr.ModelNode)2 MessageFormatException (cz.metacentrum.perun.dispatcher.exceptions.MessageFormatException)1 PerunHornetQServerException (cz.metacentrum.perun.dispatcher.exceptions.PerunHornetQServerException)1 HashMap (java.util.HashMap)1 JMSException (javax.jms.JMSException)1 TransportConfiguration (org.hornetq.api.core.TransportConfiguration)1 JMSFactoryType (org.hornetq.api.jms.JMSFactoryType)1 NettyConnectorFactory (org.hornetq.core.remoting.impl.netty.NettyConnectorFactory)1 ServiceName (org.jboss.msc.service.ServiceName)1