本文整理汇总了Java中org.fusesource.mqtt.client.QoS类的典型用法代码示例。如果您正苦于以下问题:Java QoS类的具体用法?Java QoS怎么用?Java QoS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QoS类属于org.fusesource.mqtt.client包,在下文中一共展示了QoS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Connecting to Broker1 using MQTT");
MQTT mqtt = new MQTT();
mqtt.setHost(BROKER_URL);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
System.out.println("Connected to Broker1");
// Subscribe to fidelityAds topic
Topic[] topics = { new Topic(FIDELITY_ADS_TOPIC, QoS.AT_LEAST_ONCE)};
connection.subscribe(topics);
// Publish Ads
String ads1 = "Discount on transfert fees up to -50% with coupon code JBOSSDOCTOR. www.beosbank.com";
long index=0;
while(true){
connection.publish(FIDELITY_ADS_TOPIC, (index+":"+ads1).getBytes(), QoS.AT_LEAST_ONCE, false);
System.out.println("Sent messages with index="+index);
Thread.sleep(10000);
index++;
}
}
示例2: main
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Connecting to Broker1 using MQTT");
MQTT mqtt = new MQTT();
mqtt.setHost(BROKER_URL);
BlockingConnection connection = mqtt.blockingConnection();
connection.connect();
System.out.println("Connected to Artemis");
// Subscribe to fidelityAds topic
Topic[] topics = {new Topic(FIDELITY_ADS_TOPIC, QoS.AT_LEAST_ONCE)};
connection.subscribe(topics);
// Get Ads Messages
while(true){
Message message = connection.receive(5, TimeUnit.SECONDS);
if(message!=null){
System.out.println("Received messages. "+new String(message.getPayload()));
}
}
}
示例3: testConsumeMultipleTopicsWithWildcards
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
@Test
public void testConsumeMultipleTopicsWithWildcards() throws Exception {
MQTT mqtt = new MQTT();
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();
}
示例4: validate
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public static boolean validate(String token) {
if (validationTokens.containsKey(token) && validationTokens.get(token).isValid()) {
ValidationToken vt = validationTokens.get(token);
validKeys.add(getKey(vt.getSystemId(), vt.getEmail()));
validationTokens.remove(token);
// TODO: Might need to do this in a different thread, this will trigger 48 hours of messages
// Get the planning we need // TODO: Duplicated
List<RealtimeMessage> times = QuayDataProvider.getDataForQuay(vt.getSubscription().getSubscribedQuayCodes(), true);
sendStatus(vt.getSystemId(), true, DisplayDirectMessage.SubscriptionResponse.Status.AUTHORISATION_VALIDATED);
if (times.size() > 0) {
LOGGER.debug("Got {} times to send", times.size());
transport.sendMessage(TopicFactory.travelInformation(vt.getSystemId()), DisplayDirectMessageFactory.fromRealTime(times, vt.getSubscription()), QoS.AT_LEAST_ONCE);
sendStatus(vt.getSystemId(), true, DisplayDirectMessage.SubscriptionResponse.Status.PLANNING_SENT);
} else {
sendStatus(vt.getSystemId(), true, DisplayDirectMessage.SubscriptionResponse.Status.NO_PLANNING);
}
SubscriptionStore.add(vt.getSubscription());
Log.send(LogCode.AUTHORISATION_VALIDATED, vt.getSystemId(), "Authorization processed");
Log.send(LogCode.SUBSCRIPTION_ADDED, vt.getSystemId(), "System subscribed succesfully, authorization processed");
return true;
}
return false;
}
示例5: handleMessage
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public static void handleMessage(String m) {
Map<String, List<RealtimeMessage>> realtime = RealtimeMessageMapper.toRealtimeMessage(Kv78Parser.parseMessage(m))
.stream()
.map(r -> factory.process(r))
.filter(Objects::nonNull)
.collect(Collectors.groupingBy(RealtimeMessage::getQuayCode));
realtime.forEach((key, value) -> {
SubscriptionStore.getForQuay(key).forEach(sub -> {
if (value.size() > 0) {
LOGGER.trace("Publishing on topic '/travel_information' to '{}'", sub.getId());
metrics.increaseBucketValue("kv78turbo.messages.sent", ChronoUnit.HOURS);
byte[] msg = DisplayDirectMessageFactory.fromRealTime(value, sub);
if (msg != null) {
transport.sendMessage(TopicFactory.travelInformation(sub.getId()), msg, QoS.AT_LEAST_ONCE);
} else {
LOGGER.debug("Got zero result for msg {}, translated to {} and sub {}", m, value, sub.getId());
}
}
});
});
}
示例6: publish
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public void publish(String queue, byte[] msg, QoS qos, Callback<Void> callback) {
if (qos == null) {
qos = QoS.AT_LEAST_ONCE;
}
if (callback == null) {
callback = new Callback<Void>() {
@Override
public void onSuccess(Void value) {
}
@Override
public void onFailure(Throwable value) {
LOGGER.info("Error sending message:", value);
}
};
}
connection.publish(queue, msg, qos, false, callback);
}
示例7: publish
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public void publish(PublishingInfo info) {
String topic;
if(info.getType() == Type.FREQUENCY) {
topic = FREQUENCY_TOPIC_PREFIX + info.getDeviceID();
} else if(info.getType() == Type.TEMPERATURE) {
topic = TEMPERATURE_TOPIC_PREFIX + info.getDeviceID();
} else {
throw new RuntimeException("PublishingInfo hasn't a Type specified.");
}
byte[] payload;
ObjectMapper mapper = new ObjectMapper(); // Jackson's JSON marshaller
try {
payload = mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(info);
logger.info("Publishing.. " + new String(payload));
} catch (IOException e) {
logger.error("publish()", e);
throw new RuntimeException("JSON transform failed.", e);
}
publish(topic, payload, QoS.AT_LEAST_ONCE, false);
logger.info("published.");
}
示例8: start
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
@Override
public boolean start() throws IOException {
LOG.debug("Starting MQTT reader ...");
Read spec = source.spec;
try {
client = spec.connectionConfiguration().createClient();
LOG.debug("Reader client ID is {}", client.getClientId());
checkpointMark.clientId = client.getClientId().toString();
connection = client.blockingConnection();
connection.connect();
connection.subscribe(new Topic[]{
new Topic(spec.connectionConfiguration().getTopic(), QoS.AT_LEAST_ONCE)});
return advance();
} catch (Exception e) {
throw new IOException(e);
}
}
示例9: publish
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void publish(final String channel, final KuraPayload payload) {
if (this.connection != null) {
final KuraPayloadEncoder encoder = new KuraPayloadEncoder(payload);
try {
this.connection.publish(channel, encoder.getBytes(), QoS.AT_MOST_ONCE, false, new Callback<Void>() {
@Override
public void onFailure(final Throwable throwable) {
System.out.println("Impossible to publish message to channel " + channel);
logTracker.log("Impossible to publish message to channel " + channel);
}
@Override
public void onSuccess(final Void aVoid) {
System.out.println("Successfully published");
logTracker.log("Successfully published");
}
});
} catch (final IOException e) {
System.out.println("I/O Exception Occurred: " + e.getMessage());
logTracker.log("I/O Exception Occurred: " + e.getMessage());
}
}
}
示例10: getQoS
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
static QoS getQoS(String qualityOfService) {
for (QoS q : QoS.values()) {
if (q.name().equalsIgnoreCase(qualityOfService)) {
return q;
}
}
if (qualityOfService.equalsIgnoreCase("ATMOSTONCE")) {
return QoS.AT_MOST_ONCE;
}
if (qualityOfService.equalsIgnoreCase("EXACTLYONCE")) {
return QoS.EXACTLY_ONCE;
}
if (qualityOfService.equalsIgnoreCase("ATLEASTONCE")) {
return QoS.AT_LEAST_ONCE;
}
throw new IllegalArgumentException("There is no QoS with name " + qualityOfService);
}
示例11: testConsumeMultipleTopics
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
@Test
public void testConsumeMultipleTopics() throws Exception {
MQTT mqtt = new MQTT();
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();
}
示例12: testConsume
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
@Test
public void testConsume() throws Exception {
MQTT mqtt = new MQTT();
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();
}
示例13: run
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
@Override
public void run()
{
try {
int i = 0;
Topic[] topics = new Topic[sendingData.size()];
for (String key : sendingData.keySet()) {
topics[i++] = new Topic(key, QoS.AT_MOST_ONCE);
}
connection.subscribe(topics);
while (receivedData.size() < sendingData.size()) {
Message msg = connection.receive();
receivedData.put(msg.getTopic(), new String(msg.getPayload()));
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例14: main
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
MQTT client = new MQTT();
client.setHost("tcp://raspberrypi.local:1883");
client.setClientId("fusesourcepublisher");
BlockingConnection connection = client.blockingConnection();
connection.connect();
connection.publish("testack", "Hello".getBytes(), QoS.AT_LEAST_ONCE, false);
while(true){
Thread.sleep(2000);
}
//connection.disconnect();
}
示例15: onSubscribe
import org.fusesource.mqtt.client.QoS; //导入依赖的package包/类
QoS onSubscribe(SUBSCRIBE command, Topic topic) throws MQTTProtocolException {
ActiveMQDestination destination = new ActiveMQTopic(convertMQTTToActiveMQ(topic.name().toString()));
ConsumerId id = new ConsumerId(sessionId, consumerIdGenerator.getNextSequenceId());
ConsumerInfo consumerInfo = new ConsumerInfo(id);
consumerInfo.setDestination(destination);
consumerInfo.setPrefetchSize(getActiveMQSubscriptionPrefetch());
consumerInfo.setDispatchAsync(true);
if (!connect.cleanSession() && (connect.clientId() != null)) {
//by default subscribers are persistent
consumerInfo.setSubscriptionName(
connect.clientId().toString() + topic.name().toString());
}
MQTTSubscription mqttSubscription = new MQTTSubscription(this, topic.qos(), consumerInfo);
subscriptionsByConsumerId.put(id, mqttSubscription);
mqttSubscriptionByTopic.put(topic.name(), mqttSubscription);
sendToActiveMQ(consumerInfo, null);
return topic.qos();
}