use of org.fusesource.mqtt.client.BlockingConnection in project camel by apache.
the class MQTTConsumerMultipleTopicsTest method testConsumeMultipleTopics.
@Test
public void testConsumeMultipleTopics() throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(MQTTTestSupport.getHostForMQTTEndpoint());
BlockingConnection publisherConnection = mqtt.blockingConnection();
Topic topic1 = new Topic(TEST_TOPIC, QoS.AT_MOST_ONCE);
Topic topic2 = new Topic(TEST_TOPIC_2, QoS.AT_MOST_ONCE);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(numberOfMessages * 2);
publisherConnection.connect();
String payload;
for (int i = 0; i < numberOfMessages; i++) {
payload = "Topic 1, Message " + i;
publisherConnection.publish(topic1.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
payload = "Topic 2, Message " + i;
publisherConnection.publish(topic2.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
}
mock.await(5, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
use of org.fusesource.mqtt.client.BlockingConnection in project camel by apache.
the class MQTTConsumerTest method testConsume.
@Test
public void testConsume() throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(MQTTTestSupport.getHostForMQTTEndpoint());
BlockingConnection publisherConnection = mqtt.blockingConnection();
Topic topic = new Topic(TEST_TOPIC, QoS.AT_MOST_ONCE);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(numberOfMessages);
publisherConnection.connect();
for (int i = 0; i < numberOfMessages; i++) {
String payload = "Message " + i;
publisherConnection.publish(topic.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
}
mock.await(5, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
use of org.fusesource.mqtt.client.BlockingConnection in project camel by apache.
the class MQTTConsumerWildcardTopicsTest method testConsumeMultipleTopicsWithWildcards.
@Test
public void testConsumeMultipleTopicsWithWildcards() throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(MQTTTestSupport.getHostForMQTTEndpoint());
BlockingConnection publisherConnection = mqtt.blockingConnection();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(numberOfMessages * (PUBLISH_TOPICS.length - 1));
publisherConnection.connect();
String payload;
for (String topic : PUBLISH_TOPICS) {
for (int i = 0; i < numberOfMessages; i++) {
payload = "Topic " + topic + ", Message " + i;
publisherConnection.publish(topic, payload.getBytes(), QoS.AT_LEAST_ONCE, false);
}
}
mock.await(5, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
use of org.fusesource.mqtt.client.BlockingConnection in project wildfly-camel by wildfly-extras.
the class MQTTIntegrationTest method testMQTTConsumer.
@Test
public void testMQTTConsumer() throws Exception {
String conUrl = TestUtils.getResourceValue(getClass(), "/tcp-connection");
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("mqtt:bar?subscribeTopicName=" + BrokerSetup.TEST_TOPIC + "&host=" + conUrl).transform(body().prepend("Hello ")).to("seda:end");
}
});
camelctx.start();
PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
consumer.start();
try {
MQTT mqtt = new MQTT();
mqtt.setHost(conUrl);
BlockingConnection connection = mqtt.blockingConnection();
Topic topic = new Topic(BrokerSetup.TEST_TOPIC, QoS.AT_MOST_ONCE);
connection.connect();
try {
connection.publish(topic.name().toString(), "Kermit".getBytes(), QoS.AT_LEAST_ONCE, false);
} finally {
connection.disconnect();
}
String result = consumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
camelctx.stop();
}
}
use of org.fusesource.mqtt.client.BlockingConnection in project activemq-artemis by apache.
the class ClusteredQueueMQTTExample method retrieveMQTTConnection.
private static BlockingConnection retrieveMQTTConnection(String host) throws Exception {
MQTT mqtt = new MQTT();
mqtt.setHost(host);
mqtt.setUserName("admin");
mqtt.setPassword("admin");
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
return connection;
}
Aggregations