use of org.fusesource.mqtt.client.Topic in project activemq-artemis by apache.
the class MQTTTest method testAmbiguousRoutingWithMQTT.
@Test(timeout = 60 * 1000)
public void testAmbiguousRoutingWithMQTT() throws Exception {
String anycastAddress = "foo/bar";
EnumSet<RoutingType> routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet));
String clientId = "testMqtt";
Topic[] mqttSubscription = new Topic[] { new Topic(anycastAddress, QoS.AT_LEAST_ONCE) };
MQTT mqtt = createMQTTConnection();
mqtt.setClientId(clientId);
BlockingConnection connection1 = mqtt.blockingConnection();
connection1.connect();
connection1.subscribe(mqttSubscription);
MQTT mqtt2 = createMQTTConnection();
mqtt2.setClientId(clientId + "2");
BlockingConnection connection2 = mqtt2.blockingConnection();
connection2.connect();
connection2.subscribe(mqttSubscription);
String message1 = "TestMessage1";
String message2 = "TestMessage2";
connection1.publish(anycastAddress, message1.getBytes(), QoS.AT_LEAST_ONCE, false);
connection2.publish(anycastAddress, message2.getBytes(), QoS.AT_LEAST_ONCE, false);
assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
}
use of org.fusesource.mqtt.client.Topic in project activemq-artemis by apache.
the class MQTTTest method testCleanSession.
@Test(timeout = 60 * 1000)
public void testCleanSession() throws Exception {
final String CLIENTID = "cleansession";
final MQTT mqttNotClean = createMQTTConnection(CLIENTID, false);
BlockingConnection notClean = mqttNotClean.blockingConnection();
final String TOPIC = "TopicA";
notClean.connect();
notClean.subscribe(new Topic[] { new Topic(TOPIC, QoS.EXACTLY_ONCE) });
notClean.publish(TOPIC, TOPIC.getBytes(), QoS.EXACTLY_ONCE, false);
notClean.disconnect();
// MUST receive message from previous not clean session
notClean = mqttNotClean.blockingConnection();
notClean.connect();
Message msg = notClean.receive(10000, TimeUnit.MILLISECONDS);
assertNotNull(msg);
assertEquals(TOPIC, new String(msg.getPayload()));
msg.ack();
notClean.publish(TOPIC, TOPIC.getBytes(), QoS.EXACTLY_ONCE, false);
notClean.disconnect();
// MUST NOT receive message from previous not clean session
final MQTT mqttClean = createMQTTConnection(CLIENTID, true);
final BlockingConnection clean = mqttClean.blockingConnection();
clean.connect();
msg = clean.receive(10000, TimeUnit.MILLISECONDS);
assertNull(msg);
clean.subscribe(new Topic[] { new Topic(TOPIC, QoS.EXACTLY_ONCE) });
clean.publish(TOPIC, TOPIC.getBytes(), QoS.EXACTLY_ONCE, false);
clean.disconnect();
// MUST NOT receive message from previous clean session
notClean = mqttNotClean.blockingConnection();
notClean.connect();
msg = notClean.receive(1000, TimeUnit.MILLISECONDS);
assertNull(msg);
notClean.disconnect();
}
use of org.fusesource.mqtt.client.Topic in project activemq-artemis by apache.
the class MQTTTest method testRetainedMessagesAreCorrectlyFormedAfterRestart.
@Test
public void testRetainedMessagesAreCorrectlyFormedAfterRestart() throws Exception {
String clientId = "testMqtt";
String address = "testAddress";
String payload = "This is a test message";
// Create address
getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString(address), RoutingType.MULTICAST));
// Send MQTT Retain Message
Topic[] mqttTopic = new Topic[] { new Topic(address, QoS.AT_LEAST_ONCE) };
MQTT mqtt = createMQTTConnection();
mqtt.setClientId(clientId);
BlockingConnection connection1 = mqtt.blockingConnection();
connection1.connect();
connection1.publish(address, payload.getBytes(), QoS.AT_LEAST_ONCE, true);
getServer().fail(false);
getServer().start();
waitForServerToStart(getServer());
MQTT mqtt2 = createMQTTConnection();
mqtt2.setClientId(clientId + "2");
BlockingConnection connection2 = mqtt2.blockingConnection();
connection2.connect();
connection2.subscribe(mqttTopic);
Message message = connection2.receive(5000, TimeUnit.MILLISECONDS);
assertEquals(payload, new String(message.getPayload()));
}
use of org.fusesource.mqtt.client.Topic in project storm by apache.
the class MqttSpout method connectMqtt.
private void connectMqtt() throws Exception {
String clientId = this.topologyName + "-" + this.context.getThisComponentId() + "-" + this.context.getThisTaskId();
MQTT client = MqttUtils.configureClient(this.options, clientId, this.keyStoreLoader);
this.connection = client.callbackConnection();
this.connection.listener(this);
this.connection.connect(new ConnectCallback());
while (!this.mqttConnected && !this.mqttConnectFailed) {
LOG.info("Waiting for connection...");
Thread.sleep(500);
}
if (this.mqttConnected) {
List<String> topicList = this.options.getTopics();
Topic[] topics = new Topic[topicList.size()];
QoS qos = MqttUtils.qosFromInt(this.options.getQos());
for (int i = 0; i < topicList.size(); i++) {
topics[i] = new Topic(topicList.get(i), qos);
}
connection.subscribe(topics, new SubscribeCallback());
}
}
use of org.fusesource.mqtt.client.Topic in project quickstarts by jboss-switchyard.
the class CamelMQTTBindingTest method before.
@Before
public void before() {
MQTT mqtt = new MQTT();
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
BlockingConnection connection = mqtt.blockingConnection();
try {
connection.connect();
connection.subscribe(new Topic[] { outputTopic });
while (connection.receive(1000, TimeUnit.MILLISECONDS) != null) ;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations