Search in sources :

Example 41 with DiscoveryGroupConfiguration

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

the class ConnectionFactoryURITest method testUDPURI.

@Test
public void testUDPURI() throws Exception {
    DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
    UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory();
    endpoint.setGroupPort(3333).setGroupAddress("wahey").setLocalBindPort(555).setLocalBindAddress("uhuh");
    discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpoint);
    ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
    URI tcp = parser.createSchema("udp", connectionFactoryWithHA);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(tcp.toString());
    DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
    Assert.assertNotNull(dgc);
    BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
    Assert.assertNotNull(befc);
    Assert.assertTrue(befc instanceof UDPBroadcastEndpointFactory);
    UDPBroadcastEndpointFactory ubgc = (UDPBroadcastEndpointFactory) befc;
    Assert.assertEquals("wahey", ubgc.getGroupAddress());
    Assert.assertEquals(3333, ubgc.getGroupPort());
    // these 2 are transient
    // These will take the System.properties used on the testsuite,
    // for that reason we take them as != instead of checking for null
    Assert.assertNotEquals("uhuh", ubgc.getLocalBindAddress());
    Assert.assertNotEquals(555, ubgc.getLocalBindPort());
    Assert.assertEquals("foo", dgc.getName());
    Assert.assertEquals(5678, dgc.getDiscoveryInitialWaitTimeout());
    Assert.assertEquals(12345, dgc.getRefreshTimeout());
    BeanUtilsBean bean = new BeanUtilsBean();
    checkEquals(bean, connectionFactoryWithHA, factory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) URI(java.net.URI) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 42 with DiscoveryGroupConfiguration

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

the class ConnectionFactoryURITest method testJGroupsFileURI.

@Test
public void testJGroupsFileURI() throws Exception {
    DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
    JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml");
    discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory);
    ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
    URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA);
    ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
    DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
    Assert.assertNotNull(dgc);
    BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
    Assert.assertNotNull(befc);
    Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory);
    Assert.assertEquals(dgc.getName(), "foo");
    Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678);
    Assert.assertEquals(dgc.getRefreshTimeout(), 12345);
    JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc;
    Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml");
    Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name");
    BeanUtilsBean bean = new BeanUtilsBean();
    checkEquals(bean, connectionFactoryWithHA, factory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) URI(java.net.URI) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) JGroupsPropertiesBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) BroadcastEndpointFactory(org.apache.activemq.artemis.api.core.BroadcastEndpointFactory) Test(org.junit.Test)

Example 43 with DiscoveryGroupConfiguration

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

the class ClusterConnectionControlTest method setUp.

// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Map<String, Object> acceptorParams = new HashMap<>();
    acceptorParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), acceptorParams, RandomUtil.randomString());
    TransportConfiguration connectorConfig = new TransportConfiguration(InVMConnectorFactory.class.getName(), acceptorParams, RandomUtil.randomString());
    CoreQueueConfiguration queueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false);
    List<String> connectors = new ArrayList<>();
    connectors.add(connectorConfig.getName());
    String discoveryGroupName = RandomUtil.randomString();
    DiscoveryGroupConfiguration discoveryGroupConfig = new DiscoveryGroupConfiguration().setName(discoveryGroupName).setRefreshTimeout(500).setDiscoveryInitialWaitTimeout(0).setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(getUDPDiscoveryAddress()).setGroupPort(getUDPDiscoveryPort()));
    Configuration conf_1 = createBasicConfig().addAcceptorConfiguration(acceptorConfig).addQueueConfiguration(queueConfig);
    clusterConnectionConfig1 = new ClusterConnectionConfiguration().setName(RandomUtil.randomString()).setAddress(queueConfig.getAddress()).setConnectorName(connectorConfig.getName()).setRetryInterval(RandomUtil.randomPositiveLong()).setDuplicateDetection(RandomUtil.randomBoolean()).setMessageLoadBalancingType(MessageLoadBalancingType.STRICT).setMaxHops(RandomUtil.randomPositiveInt()).setConfirmationWindowSize(RandomUtil.randomPositiveInt()).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(connectors);
    clusterConnectionConfig2 = new ClusterConnectionConfiguration().setName(RandomUtil.randomString()).setAddress(queueConfig.getAddress()).setConnectorName(connectorConfig.getName()).setRetryInterval(RandomUtil.randomPositiveLong()).setDuplicateDetection(RandomUtil.randomBoolean()).setMessageLoadBalancingType(MessageLoadBalancingType.OFF).setMaxHops(RandomUtil.randomPositiveInt()).setConfirmationWindowSize(RandomUtil.randomPositiveInt()).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setDiscoveryGroupName(discoveryGroupName);
    Configuration conf_0 = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName())).addConnectorConfiguration(connectorConfig.getName(), connectorConfig).addClusterConfiguration(clusterConnectionConfig1).addClusterConfiguration(clusterConnectionConfig2).addDiscoveryGroupConfiguration(discoveryGroupName, discoveryGroupConfig);
    mbeanServer_1 = MBeanServerFactory.createMBeanServer();
    server_1 = addServer(ActiveMQServers.newActiveMQServer(conf_1, mbeanServer_1, false));
    server_1.start();
    server_0 = addServer(ActiveMQServers.newActiveMQServer(conf_0, mbeanServer, false));
    server_0.start();
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) InVMAcceptorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory) Before(org.junit.Before)

Example 44 with DiscoveryGroupConfiguration

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

the class ClusterConnectionControl2Test method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String discoveryName = RandomUtil.randomString();
    String groupAddress = getUDPDiscoveryAddress();
    int groupPort = getUDPDiscoveryPort();
    Map<String, Object> acceptorParams_1 = new HashMap<>();
    acceptorParams_1.put(TransportConstants.PORT_PROP_NAME, port_1);
    TransportConfiguration acceptorConfig_0 = new TransportConfiguration(ActiveMQTestBase.NETTY_ACCEPTOR_FACTORY);
    TransportConfiguration acceptorConfig_1 = new TransportConfiguration(ActiveMQTestBase.NETTY_ACCEPTOR_FACTORY, acceptorParams_1);
    TransportConfiguration connectorConfig_1 = new TransportConfiguration(ActiveMQTestBase.NETTY_CONNECTOR_FACTORY, acceptorParams_1);
    TransportConfiguration connectorConfig_0 = new TransportConfiguration(ActiveMQTestBase.NETTY_CONNECTOR_FACTORY);
    CoreQueueConfiguration queueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false);
    List<String> connectorInfos = new ArrayList<>();
    connectorInfos.add("netty");
    BroadcastGroupConfiguration broadcastGroupConfig = new BroadcastGroupConfiguration().setName(discoveryName).setBroadcastPeriod(250).setConnectorInfos(connectorInfos).setEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort));
    DiscoveryGroupConfiguration discoveryGroupConfig = new DiscoveryGroupConfiguration().setName(discoveryName).setRefreshTimeout(0).setDiscoveryInitialWaitTimeout(0).setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort));
    clusterConnectionConfig_0 = new ClusterConnectionConfiguration().setName(clusterName).setAddress(queueConfig.getAddress()).setConnectorName("netty").setRetryInterval(1000).setDuplicateDetection(false).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setMaxHops(1).setConfirmationWindowSize(1024).setDiscoveryGroupName(discoveryName);
    Configuration conf_1 = createBasicConfig().addClusterConfiguration(clusterConnectionConfig_0).addAcceptorConfiguration(acceptorConfig_1).addConnectorConfiguration("netty", connectorConfig_1).addQueueConfiguration(queueConfig).addDiscoveryGroupConfiguration(discoveryName, discoveryGroupConfig).addBroadcastGroupConfiguration(broadcastGroupConfig);
    Configuration conf_0 = createBasicConfig(1).addClusterConfiguration(clusterConnectionConfig_0).addAcceptorConfiguration(acceptorConfig_0).addConnectorConfiguration("netty", connectorConfig_0).addDiscoveryGroupConfiguration(discoveryName, discoveryGroupConfig).addBroadcastGroupConfiguration(broadcastGroupConfig);
    mbeanServer_1 = MBeanServerFactory.createMBeanServer();
    server1 = addServer(ActiveMQServers.newActiveMQServer(conf_1, mbeanServer_1, false));
    server0 = addServer(ActiveMQServers.newActiveMQServer(conf_0, mbeanServer, false));
    server0.start();
    waitForServerToStart(server0);
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) BroadcastGroupConfiguration(org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) Before(org.junit.Before)

Example 45 with DiscoveryGroupConfiguration

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

the class ActiveMQResourceAdapter method createRecoveryActiveMQConnectionFactory.

public ActiveMQConnectionFactory createRecoveryActiveMQConnectionFactory(final ConnectionFactoryProperties overrideProperties) {
    ActiveMQConnectionFactory cf;
    List<String> connectorClassName = overrideProperties.getParsedConnectorClassNames() != null ? overrideProperties.getParsedConnectorClassNames() : raProperties.getParsedConnectorClassNames();
    if (connectorClassName == null) {
        BroadcastEndpointFactory endpointFactory = this.createBroadcastEndpointFactory(overrideProperties);
        if (endpointFactory == null) {
            throw new IllegalArgumentException("must provide either TransportType or DiscoveryGroupAddress and DiscoveryGroupPort for ResourceAdapter Connection Factory");
        }
        Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout() : raProperties.getDiscoveryRefreshTimeout();
        if (refreshTimeout == null) {
            refreshTimeout = ActiveMQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT;
        }
        Long initialTimeout = overrideProperties.getDiscoveryInitialWaitTimeout() != null ? overrideProperties.getDiscoveryInitialWaitTimeout() : raProperties.getDiscoveryInitialWaitTimeout();
        if (initialTimeout == null) {
            initialTimeout = ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT;
        }
        DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialTimeout).setBroadcastEndpointFactory(endpointFactory);
        groupConfiguration.setRefreshTimeout(refreshTimeout);
        if (ActiveMQRALogger.LOGGER.isDebugEnabled()) {
            ActiveMQRALogger.LOGGER.debug("Creating Recovery Connection Factory on the resource adapter for discovery=" + groupConfiguration);
        }
        cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.XA_CF);
    } else {
        TransportConfiguration[] transportConfigurations = new TransportConfiguration[connectorClassName.size()];
        List<Map<String, Object>> connectionParams;
        if (overrideProperties.getParsedConnectorClassNames() != null) {
            connectionParams = overrideProperties.getParsedConnectionParameters();
        } else {
            connectionParams = raProperties.getParsedConnectionParameters();
        }
        for (int i = 0; i < connectorClassName.size(); i++) {
            TransportConfiguration tc;
            if (connectionParams == null || i >= connectionParams.size()) {
                tc = new TransportConfiguration(connectorClassName.get(i));
                ActiveMQRALogger.LOGGER.debug("No connector params provided using default");
            } else {
                tc = new TransportConfiguration(connectorClassName.get(i), connectionParams.get(i));
            }
            transportConfigurations[i] = tc;
        }
        if (ActiveMQRALogger.LOGGER.isDebugEnabled()) {
            ActiveMQRALogger.LOGGER.debug("Creating Recovery Connection Factory on the resource adapter for transport=" + Arrays.toString(transportConfigurations));
        }
        cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, transportConfigurations);
    }
    setParams(cf, overrideProperties);
    // now make sure we are HA in any way
    cf.setReconnectAttempts(0);
    cf.setInitialConnectAttempts(0);
    return cf;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) JGroupsFileBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory) 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