Search in sources :

Example 11 with WildcardConfiguration

use of org.apache.activemq.artemis.core.config.WildcardConfiguration in project activemq-artemis by apache.

the class MqttClusterWildcardTest method loadBalanceRequests.

@Test
public void loadBalanceRequests() throws Exception {
    final String TOPIC = "test/+/some/#";
    WildcardConfiguration wildcardConfiguration = new WildcardConfiguration();
    wildcardConfiguration.setAnyWords('#');
    wildcardConfiguration.setDelimiter('/');
    wildcardConfiguration.setRoutingEnabled(true);
    wildcardConfiguration.setSingleWord('+');
    setupServer(0, false, isNetty());
    servers[0].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
    setupServer(1, false, isNetty());
    servers[1].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
    setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
    setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
    startServers(0, 1);
    BlockingConnection connection1 = null;
    BlockingConnection connection2 = null;
    try {
        connection1 = retrieveMQTTConnection("tcp://localhost:61616");
        connection2 = retrieveMQTTConnection("tcp://localhost:61617");
        // Subscribe to topics
        Topic[] topics = { new Topic(TOPIC, QoS.AT_MOST_ONCE) };
        connection1.subscribe(topics);
        connection2.subscribe(topics);
        waitForBindings(0, TOPIC, 1, 1, true);
        waitForBindings(1, TOPIC, 1, 1, true);
        waitForBindings(0, TOPIC, 1, 1, false);
        waitForBindings(1, TOPIC, 1, 1, false);
        // Publish Messages
        String payload1 = "This is message 1";
        String payload2 = "This is message 2";
        String payload3 = "This is message 3";
        connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);
        connection1.publish("test/1/some/la", payload2.getBytes(), QoS.AT_MOST_ONCE, false);
        connection1.publish("test/1/some/la", payload3.getBytes(), QoS.AT_MOST_ONCE, false);
        Message message1 = connection1.receive(5, TimeUnit.SECONDS);
        Message message2 = connection1.receive(5, TimeUnit.SECONDS);
        Message message3 = connection1.receive(5, TimeUnit.SECONDS);
        Message message4 = connection2.receive(5, TimeUnit.SECONDS);
        Message message5 = connection2.receive(5, TimeUnit.SECONDS);
        Message message6 = connection2.receive(5, TimeUnit.SECONDS);
        assertEquals(payload1, new String(message1.getPayload()));
        assertEquals(payload2, new String(message2.getPayload()));
        assertEquals(payload3, new String(message3.getPayload()));
        assertEquals(payload1, new String(message4.getPayload()));
        assertEquals(payload2, new String(message5.getPayload()));
        assertEquals(payload3, new String(message6.getPayload()));
    } finally {
        String[] topics = new String[] { TOPIC };
        if (connection1 != null) {
            connection1.unsubscribe(topics);
            connection1.disconnect();
        }
        if (connection2 != null) {
            connection2.unsubscribe(topics);
            connection2.disconnect();
        }
    }
}
Also used : Message(org.fusesource.mqtt.client.Message) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) BlockingConnection(org.fusesource.mqtt.client.BlockingConnection) Topic(org.fusesource.mqtt.client.Topic) Test(org.junit.Test)

Example 12 with WildcardConfiguration

use of org.apache.activemq.artemis.core.config.WildcardConfiguration in project activemq-artemis by apache.

the class MqttClusterWildcardTest method wildcardsWithBroker1Disconnected.

@Test
public void wildcardsWithBroker1Disconnected() throws Exception {
    BlockingConnection connection1 = null;
    BlockingConnection connection2 = null;
    BlockingConnection connection3 = null;
    final String TOPIC = "test/+/some/#";
    try {
        WildcardConfiguration wildcardConfiguration = new WildcardConfiguration();
        wildcardConfiguration.setAnyWords('#');
        wildcardConfiguration.setDelimiter('/');
        wildcardConfiguration.setRoutingEnabled(true);
        wildcardConfiguration.setSingleWord('+');
        setupServer(0, false, isNetty());
        servers[0].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
        setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
        startServers(0);
        connection1 = retrieveMQTTConnection("tcp://localhost:61616");
        // Subscribe to topics
        Topic[] topics = { new Topic(TOPIC, QoS.AT_MOST_ONCE) };
        connection1.subscribe(topics);
        waitForBindings(0, TOPIC, 1, 1, true);
        waitForBindings(0, TOPIC, 0, 0, false);
        // Publish Messages
        String payload1 = "This is message 1";
        String payload2 = "This is message 2";
        String payload3 = "This is message 3";
        connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);
        connection1.publish("test/1/some/la", payload2.getBytes(), QoS.AT_MOST_ONCE, false);
        connection1.publish("test/1/some/la", payload3.getBytes(), QoS.AT_MOST_ONCE, false);
        Message message1 = connection1.receive(5, TimeUnit.SECONDS);
        setupServer(1, false, isNetty());
        servers[1].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
        setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
        startServers(1);
        connection2 = retrieveMQTTConnection("tcp://localhost:61617");
        connection3 = retrieveMQTTConnection("tcp://localhost:61617");
        connection2.subscribe(topics);
        connection3.subscribe(new Topic[] { new Topic("teste/1/some/1", QoS.AT_MOST_ONCE) });
        waitForBindings(1, TOPIC, 1, 1, false);
        waitForBindings(1, TOPIC, 1, 1, true);
        waitForBindings(0, TOPIC, 1, 1, true);
        connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);
        connection1.publish("test/1/some/la", payload2.getBytes(), QoS.AT_MOST_ONCE, false);
        connection1.publish("test/1/some/la", payload3.getBytes(), QoS.AT_MOST_ONCE, false);
        Message message2 = connection1.receive(5, TimeUnit.SECONDS);
        Message message3 = connection1.receive(5, TimeUnit.SECONDS);
        Message message4 = connection2.receive(5, TimeUnit.SECONDS);
        Message message5 = connection2.receive(5, TimeUnit.SECONDS);
        Message message6 = connection2.receive(5, TimeUnit.SECONDS);
        assertEquals(payload1, new String(message1.getPayload()));
        assertEquals(payload2, new String(message2.getPayload()));
        assertEquals(payload3, new String(message3.getPayload()));
        assertEquals(payload1, new String(message4.getPayload()));
        assertEquals(payload2, new String(message5.getPayload()));
        assertEquals(payload3, new String(message6.getPayload()));
    } finally {
        String[] topics = new String[] { TOPIC };
        if (connection1 != null) {
            connection1.unsubscribe(topics);
            connection1.disconnect();
        }
        if (connection2 != null) {
            connection2.unsubscribe(topics);
            connection2.disconnect();
        }
        if (connection3 != null) {
            connection3.unsubscribe(new String[] { "teste/1/some/1" });
            connection3.disconnect();
        }
    }
}
Also used : Message(org.fusesource.mqtt.client.Message) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) BlockingConnection(org.fusesource.mqtt.client.BlockingConnection) Topic(org.fusesource.mqtt.client.Topic) Test(org.junit.Test)

Example 13 with WildcardConfiguration

use of org.apache.activemq.artemis.core.config.WildcardConfiguration in project activemq-artemis by apache.

the class MqttClusterRemoteSubscribeTest method createWildCardConfiguration.

private WildcardConfiguration createWildCardConfiguration() {
    WildcardConfiguration wildcardConfiguration = new WildcardConfiguration();
    wildcardConfiguration.setAnyWords('#');
    wildcardConfiguration.setDelimiter('/');
    wildcardConfiguration.setRoutingEnabled(true);
    wildcardConfiguration.setSingleWord('+');
    return wildcardConfiguration;
}
Also used : WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration)

Example 14 with WildcardConfiguration

use of org.apache.activemq.artemis.core.config.WildcardConfiguration in project activemq-artemis by apache.

the class MqttClusterRemoteSubscribeTest method setupServers.

private void setupServers(String TOPIC) throws Exception {
    WildcardConfiguration wildcardConfiguration = createWildCardConfiguration();
    CoreAddressConfiguration coreAddressConfiguration = createAddressConfiguration(TOPIC);
    AddressSettings addressSettings = createAddressSettings();
    setupServer(0, false, isNetty());
    servers[0].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
    servers[0].getConfiguration().addAddressConfiguration(coreAddressConfiguration);
    servers[0].getConfiguration().addAddressesSetting("#", addressSettings);
    setupServer(1, false, isNetty());
    servers[1].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
    servers[1].getConfiguration().addAddressConfiguration(coreAddressConfiguration);
    servers[1].getConfiguration().addAddressesSetting("#", addressSettings);
    setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
    setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration)

Aggregations

WildcardConfiguration (org.apache.activemq.artemis.core.config.WildcardConfiguration)14 Test (org.junit.Test)8 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 WildcardAddressManager (org.apache.activemq.artemis.core.postoffice.impl.WildcardAddressManager)2 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)2 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)2 BlockingConnection (org.fusesource.mqtt.client.BlockingConnection)2 Message (org.fusesource.mqtt.client.Message)2 Topic (org.fusesource.mqtt.client.Topic)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ActiveMQDefaultConfiguration (org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)1 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)1 HAPolicyConfiguration (org.apache.activemq.artemis.core.config.HAPolicyConfiguration)1 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)1 FileConfigurationParser (org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 Before (org.junit.Before)1