Search in sources :

Example 26 with DiscoveryGroupConfiguration

use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.

the class JGroupsDiscoveryGroupAdd method createDiscoveryGroupConfiguration.

public static DiscoveryGroupConfiguration createDiscoveryGroupConfiguration(final String name, final DiscoveryGroupConfiguration config, final BroadcastCommandDispatcherFactory commandDispatcherFactory, final String channelName) throws Exception {
    final long refreshTimeout = config.getRefreshTimeout();
    final long initialWaitTimeout = config.getDiscoveryInitialWaitTimeout();
    final BroadcastEndpointFactory endpointFactory = new CommandDispatcherBroadcastEndpointFactory(commandDispatcherFactory, channelName);
    return new DiscoveryGroupConfiguration().setName(name).setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialWaitTimeout).setBroadcastEndpointFactory(endpointFactory);
}
Also used : DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) CommandDispatcherBroadcastEndpointFactory(org.wildfly.extension.messaging.activemq.broadcast.CommandDispatcherBroadcastEndpointFactory) CommandDispatcherBroadcastEndpointFactory(org.wildfly.extension.messaging.activemq.broadcast.CommandDispatcherBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Example 27 with DiscoveryGroupConfiguration

use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.

the class JMSConnectionFactoryDefinitionInjectionSource method startedPooledConnectionFactory.

private void startedPooledConnectionFactory(ResolutionContext context, String name, ServiceBuilder<?> serviceBuilder, ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, Injector<ManagedReferenceFactory> injector, boolean external) throws DeploymentUnitProcessingException, OperationFailedException {
    Map<String, String> props = new HashMap<>(properties);
    List<String> connectors = getConnectors(props);
    clearUnknownProperties(properties);
    ModelNode model = new ModelNode();
    for (String connector : connectors) {
        model.get(CONNECTORS).add(connector);
    }
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        model.get(entry.getKey()).set(entry.getValue());
    }
    model.get(MIN_POOL_SIZE.getName()).set(minPoolSize);
    model.get(MAX_POOL_SIZE.getName()).set(maxPoolSize);
    if (user != null && !user.isEmpty()) {
        model.get(ConnectionFactoryAttributes.Pooled.USER.getName()).set(user);
    }
    if (password != null && !password.isEmpty()) {
        model.get(ConnectionFactoryAttributes.Pooled.PASSWORD.getName()).set(password);
    }
    if (clientId != null && !clientId.isEmpty()) {
        model.get(CommonAttributes.CLIENT_ID.getName()).set(clientId);
    }
    final String discoveryGroupName = properties.containsKey(DISCOVERY_GROUP.getName()) ? properties.get(DISCOVERY_GROUP.getName()) : null;
    if (discoveryGroupName != null) {
        model.get(DISCOVERY_GROUP.getName()).set(discoveryGroupName);
    }
    final String jgroupsChannelName = properties.containsKey(JGROUPS_CLUSTER.getName()) ? properties.get(JGROUPS_CLUSTER.getName()) : null;
    if (jgroupsChannelName != null) {
        model.get(JGROUPS_CLUSTER.getName()).set(jgroupsChannelName);
    }
    final String managedConnectionPoolClassName = properties.containsKey(MANAGED_CONNECTION_POOL.getName()) ? properties.get(MANAGED_CONNECTION_POOL.getName()) : null;
    if (managedConnectionPoolClassName != null) {
        model.get(MANAGED_CONNECTION_POOL.getName()).set(managedConnectionPoolClassName);
    }
    final Boolean enlistmentTrace = properties.containsKey(ENLISTMENT_TRACE.getName()) ? Boolean.valueOf(properties.get(ENLISTMENT_TRACE.getName())) : null;
    List<PooledConnectionFactoryConfigProperties> adapterParams = getAdapterParams(model);
    String txSupport = transactional ? XA_TX : NO_TX;
    final String serverName;
    final String pcfName = uniqueName(context, name);
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), name);
    if (external) {
        serverName = null;
        Set<String> connectorsSocketBindings = new HashSet<>();
        ExternalBrokerConfigurationService configuration = (ExternalBrokerConfigurationService) deploymentUnit.getServiceRegistry().getRequiredService(MessagingSubsystemRootResourceDefinition.CONFIGURATION_CAPABILITY.getCapabilityServiceName()).getService().getValue();
        TransportConfiguration[] tcs = new TransportConfiguration[connectors.size()];
        for (int i = 0; i < tcs.length; i++) {
            tcs[i] = configuration.getConnectors().get(connectors.get(i));
            if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
                connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
            }
        }
        DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
        if (discoveryGroupName != null) {
            discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(discoveryGroupName);
        }
        if (connectors.isEmpty() && discoveryGroupConfiguration == null) {
            tcs = getExternalPooledConnectionFactory(resourceAdapter, deploymentUnit.getServiceRegistry()).getConnectors();
            for (int i = 0; i < tcs.length; i++) {
                if (tcs[i].getParams().containsKey(ModelDescriptionConstants.SOCKET_BINDING)) {
                    connectorsSocketBindings.add(tcs[i].getParams().get(ModelDescriptionConstants.SOCKET_BINDING).toString());
                }
            }
        }
        ExternalPooledConnectionFactoryService.installService(serviceTarget, configuration, pcfName, tcs, discoveryGroupConfiguration, connectorsSocketBindings, null, jgroupsChannelName, adapterParams, bindInfo, Collections.emptyList(), txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, deploymentUnit.getAttachment(CAPABILITY_SERVICE_SUPPORT));
    } else {
        serverName = getActiveMQServerName(properties);
        PooledConnectionFactoryService.installService(serviceTarget, pcfName, serverName, connectors, discoveryGroupName, jgroupsChannelName, adapterParams, bindInfo, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, true);
    }
    final ServiceName referenceFactoryServiceName = ConnectionFactoryReferenceFactoryService.SERVICE_NAME_BASE.append(bindInfo.getBinderServiceName());
    serviceBuilder.addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, injector);
    // create the management registration
    String managementName = managementName(context, name);
    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final PathElement pcfPath = PathElement.pathElement(POOLED_CONNECTION_FACTORY, managementName);
    PathAddress registration;
    if (external) {
        deploymentResourceSupport.getDeploymentSubsystemModel(MessagingExtension.SUBSYSTEM_NAME);
        registration = PathAddress.pathAddress(pcfPath);
    } else {
        final PathElement serverElement = PathElement.pathElement(SERVER, serverName);
        deploymentResourceSupport.getDeploymentSubModel(MessagingExtension.SUBSYSTEM_NAME, serverElement);
        registration = PathAddress.pathAddress(serverElement, pcfPath);
    }
    MessagingXmlInstallDeploymentUnitProcessor.createDeploymentSubModel(registration, deploymentUnit);
    PooledConnectionFactoryConfigurationRuntimeHandler.INSTANCE.registerResource(serverName, managementName, model);
}
Also used : HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) PooledConnectionFactoryConfigProperties(org.wildfly.extension.messaging.activemq.jms.PooledConnectionFactoryConfigProperties) DeploymentResourceSupport(org.jboss.as.server.deployment.DeploymentResourceSupport) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ExternalBrokerConfigurationService(org.wildfly.extension.messaging.activemq.ExternalBrokerConfigurationService) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) HashMap(java.util.HashMap) ContextNames(org.jboss.as.naming.deployment.ContextNames) HashSet(java.util.HashSet)

Example 28 with DiscoveryGroupConfiguration

use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.

the class ExternalPooledConnectionFactoryAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();
    PathAddress address = context.getCurrentAddress();
    final String name = context.getCurrentAddressValue();
    final ModelNode resolvedModel = model.clone();
    for (final AttributeDefinition attribute : attributes) {
        resolvedModel.get(attribute.getName()).set(attribute.resolveModelAttribute(context, resolvedModel));
    }
    // We validated that jndiName part of the model in populateModel
    final List<String> jndiNames = new ArrayList<>();
    for (ModelNode node : resolvedModel.get(Common.ENTRIES.getName()).asList()) {
        jndiNames.add(node.asString());
    }
    final BindInfo bindInfo = ContextNames.bindInfoFor(jndiNames.get(0));
    List<String> jndiAliases;
    if (jndiNames.size() > 1) {
        jndiAliases = new ArrayList<>(jndiNames.subList(1, jndiNames.size()));
    } else {
        jndiAliases = Collections.emptyList();
    }
    String managedConnectionPoolClassName = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MANAGED_CONNECTION_POOL.getName()).asStringOrNull();
    final int minPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MIN_POOL_SIZE.getName()).asInt();
    final int maxPoolSize = resolvedModel.get(ConnectionFactoryAttributes.Pooled.MAX_POOL_SIZE.getName()).asInt();
    Boolean enlistmentTrace = resolvedModel.get(ConnectionFactoryAttributes.Pooled.ENLISTMENT_TRACE.getName()).asBooleanOrNull();
    String txSupport = getTxSupport(resolvedModel);
    List<String> connectors = Common.CONNECTORS.unwrap(context, model);
    String discoveryGroupName = getDiscoveryGroup(resolvedModel);
    String jgroupClusterName = null;
    String jgroupsChannelName = null;
    final PathAddress serverAddress = MessagingServices.getActiveMQServerPathAddress(address);
    if (discoveryGroupName != null) {
        Resource dgResource;
        if (isSubsystemResource(context)) {
            PathAddress dgAddress = address.getParent().append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName);
            try {
                dgResource = context.readResourceFromRoot(dgAddress, false);
            } catch (Resource.NoSuchResourceException ex) {
                dgAddress = address.getParent().append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName);
                dgResource = context.readResourceFromRoot(dgAddress, false);
            }
        } else {
            PathAddress dgAddress = serverAddress.append(CommonAttributes.SOCKET_DISCOVERY_GROUP, discoveryGroupName);
            try {
                dgResource = context.readResourceFromRoot(dgAddress, false);
            } catch (Resource.NoSuchResourceException ex) {
                dgAddress = address.getParent().append(CommonAttributes.JGROUPS_DISCOVERY_GROUP, discoveryGroupName);
                dgResource = context.readResourceFromRoot(dgAddress, false);
            }
        }
        ModelNode dgModel = dgResource.getModel();
        ModelNode jgroupCluster = JGROUPS_CLUSTER.resolveModelAttribute(context, dgModel);
        if (jgroupCluster.isDefined()) {
            jgroupClusterName = jgroupCluster.asString();
            ModelNode channel = DiscoveryGroupDefinition.JGROUPS_CHANNEL.resolveModelAttribute(context, dgModel);
            if (channel.isDefined()) {
                jgroupsChannelName = channel.asString();
            }
        }
    }
    List<PooledConnectionFactoryConfigProperties> adapterParams = PooledConnectionFactoryAdd.getAdapterParams(resolvedModel, context, ExternalPooledConnectionFactoryDefinition.ATTRIBUTES);
    DiscoveryGroupConfiguration discoveryGroupConfiguration = null;
    if (discoveryGroupName != null) {
        discoveryGroupConfiguration = ExternalConnectionFactoryAdd.getDiscoveryGroup(context, discoveryGroupName);
    }
    Set<String> connectorsSocketBindings = new HashSet<>();
    TransportConfiguration[] transportConfigurations = TransportConfigOperationHandlers.processConnectors(context, connectors, connectorsSocketBindings);
    ExternalPooledConnectionFactoryService.installService(context, name, transportConfigurations, discoveryGroupConfiguration, connectorsSocketBindings, jgroupClusterName, jgroupsChannelName, adapterParams, bindInfo, jndiAliases, txSupport, minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace, model);
    boolean statsEnabled = ConnectionFactoryAttributes.Pooled.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (statsEnabled) {
        // Add the stats resource. This is kind of a hack as we are modifying the resource
        // in runtime, but oh well. We don't use readResourceForUpdate for this reason.
        // This only runs in this add op anyway, and because it's an add we know readResource
        // is going to be returning the current write snapshot of the model, i.e. the one we want
        PooledConnectionFactoryStatisticsService.registerStatisticsResources(resource);
        installStatistics(context, name);
    }
}
Also used : ArrayList(java.util.ArrayList) MessagingServices.isSubsystemResource(org.wildfly.extension.messaging.activemq.MessagingServices.isSubsystemResource) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) BindInfo(org.jboss.as.naming.deployment.ContextNames.BindInfo) HashSet(java.util.HashSet)

Example 29 with DiscoveryGroupConfiguration

use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.

the class ExternalConnectionFactoryService method start.

@Override
public void start(StartContext context) throws StartException {
    try {
        if (connectors != null && connectors.length > 0) {
            TransportConfigOperationHandlers.processConnectorBindings(Arrays.asList(connectors), socketBindings, outboundSocketBindings);
            if (ha) {
                factory = ActiveMQJMSClient.createConnectionFactoryWithHA(type, connectors);
            } else {
                factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(type, connectors);
            }
        } else {
            final String name = groupConfiguration.getName();
            final String key = "discovery" + name;
            final DiscoveryGroupConfiguration config;
            if (commandDispatcherFactories.containsKey(key)) {
                BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
                String clusterName = clusterNames.get(key);
                config = JGroupsDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, groupConfiguration, commandDispatcherFactory, clusterName);
            } else {
                final SocketBinding binding = groupBindings.get(key).get();
                if (binding == null) {
                    throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
                }
                config = SocketDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, groupConfiguration, binding);
                binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
            }
            if (ha) {
                factory = ActiveMQJMSClient.createConnectionFactoryWithHA(config, type);
            } else {
                factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(config, type);
            }
        }
        if (config != null) {
            factory.setAutoGroup(config.isAutoGroup());
            factory.setBlockOnAcknowledge(config.isBlockOnAcknowledge());
            factory.setBlockOnDurableSend(config.isBlockOnDurableSend());
            factory.setBlockOnNonDurableSend(config.isBlockOnNonDurableSend());
            factory.setCacheLargeMessagesClient(config.isCacheLargeMessagesClient());
            factory.setCallFailoverTimeout(config.getCallFailoverTimeout());
            factory.setCallTimeout(config.getCallTimeout());
            factory.setClientID(config.getClientID());
            factory.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
            factory.setCompressLargeMessage(config.isCompressLargeMessages());
            factory.setConfirmationWindowSize(config.getConfirmationWindowSize());
            factory.setConnectionTTL(config.getConnectionTTL());
            factory.setConsumerMaxRate(config.getConsumerMaxRate());
            factory.setConsumerWindowSize(config.getConsumerWindowSize());
            factory.setDeserializationBlackList(config.getDeserializationBlackList());
            factory.setDeserializationWhiteList(config.getDeserializationWhiteList());
            factory.setDupsOKBatchSize(config.getDupsOKBatchSize());
            factory.setEnableSharedClientID(config.isEnableSharedClientID());
            factory.setFailoverOnInitialConnection(config.isFailoverOnInitialConnection());
            factory.setGroupID(config.getGroupID());
            factory.setInitialMessagePacketSize(config.getInitialMessagePacketSize());
            factory.setMaxRetryInterval(config.getMaxRetryInterval());
            factory.setMinLargeMessageSize(config.getMinLargeMessageSize());
            factory.setPreAcknowledge(config.isPreAcknowledge());
            factory.setProducerMaxRate(config.getProducerMaxRate());
            factory.setProducerWindowSize(config.getProducerWindowSize());
            factory.setProtocolManagerFactoryStr(config.getProtocolManagerFactoryStr());
            factory.setConnectionLoadBalancingPolicyClassName(config.getLoadBalancingPolicyClassName());
            factory.setReconnectAttempts(config.getReconnectAttempts());
            factory.setRetryInterval(config.getRetryInterval());
            factory.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
            factory.setScheduledThreadPoolMaxSize(config.getScheduledThreadPoolMaxSize());
            factory.setThreadPoolMaxSize(config.getThreadPoolMaxSize());
            factory.setTransactionBatchSize(config.getTransactionBatchSize());
            factory.setUseGlobalPools(config.isUseGlobalPools());
            factory.setUseTopologyForLoadBalancing(config.getUseTopologyForLoadBalancing());
        }
        factory.setEnable1xPrefixes(enable1Prefixes);
    } catch (Throwable e) {
        throw MessagingLogger.ROOT_LOGGER.failedToCreate(e, "connection-factory");
    }
}
Also used : OutboundSocketBinding(org.jboss.as.network.OutboundSocketBinding) SocketBinding(org.jboss.as.network.SocketBinding) BroadcastCommandDispatcherFactory(org.wildfly.extension.messaging.activemq.broadcast.BroadcastCommandDispatcherFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)

Example 30 with DiscoveryGroupConfiguration

use of org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration in project wildfly by wildfly.

the class DiscoveryGroupAdd method createDiscoveryGroupConfiguration.

static DiscoveryGroupConfiguration createDiscoveryGroupConfiguration(final String name, final DiscoveryGroupConfiguration config, final SocketBinding socketBinding) throws Exception {
    final String localAddress = socketBinding.getAddress().getHostAddress();
    final String groupAddress = socketBinding.getMulticastAddress().getHostAddress();
    final int groupPort = socketBinding.getMulticastPort();
    final long refreshTimeout = config.getRefreshTimeout();
    final long initialWaitTimeout = config.getDiscoveryInitialWaitTimeout();
    final BroadcastEndpointFactory endpointFactory = new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort).setLocalBindAddress(localAddress).setLocalBindPort(-1);
    return new DiscoveryGroupConfiguration().setName(name).setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialWaitTimeout).setBroadcastEndpointFactory(endpointFactory);
}
Also used : DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) ChannelBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)

Aggregations

DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)61 UDPBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory)32 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)19 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)19 BroadcastEndpointFactory (org.apache.activemq.artemis.api.core.BroadcastEndpointFactory)18 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 JGroupsFileBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory)12 JGroupsPropertiesBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory)10 HashMap (java.util.HashMap)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 URI (java.net.URI)7 BroadcastGroupConfiguration (org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration)7 Map (java.util.Map)6 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)5 ClusterConnectionConfiguration (org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration)5 HashSet (java.util.HashSet)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 Before (org.junit.Before)4 Hashtable (java.util.Hashtable)3