• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MqttTopic类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.MqttTopic的典型用法代码示例。如果您正苦于以下问题:Java MqttTopic类的具体用法?Java MqttTopic怎么用?Java MqttTopic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MqttTopic类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了MqttTopic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onViewClicked

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@OnClick(R.id.btn_subscribe)
public void onViewClicked() {
    String topic = mTopic.getText().toString().trim();
    try {
        MqttTopic.validate(topic, true/*allow wildcards*/);
    } catch (IllegalArgumentException e) {
        TipUtil.showSnackbar(mLinearLayout, e.getMessage());
        return;
    }

    int qos = mQoSLayout.getQoS();

    Subscription subscription = new Subscription(topic, qos);

    Intent intent = new Intent();
    intent.putExtra(Constant.ExtraConstant.EXTRA_SUBSCRIPTION, subscription);
    setResult(RESULT_OK, intent);
    finish();

}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:21,代码来源:SubscriptionActivity.java


示例2: onViewClicked

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@OnClick(R.id.btn_publish)
public void onViewClicked() {
    String topic = mTopic.getText().toString().trim();

    try{
        MqttTopic.validate(topic, false/*wildcards NOT allowed*/);
    }catch (IllegalArgumentException e){
        TipUtil.showSnackbar(mLinearLayout, e.getMessage());
        return;
    }
    int qos = mQoSChooseLayout.getQoS();
    String payload = mPayload.getText().toString().trim();
    boolean isRetained = mRetainedSwitch.isChecked();

    Publication publication = new Publication(topic, payload, qos, isRetained);

    Intent intent = new Intent();
    intent.putExtra(Constant.ExtraConstant.EXTRA_PUBLICATION, publication);
    setResult(RESULT_OK, intent);
    finish();
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:22,代码来源:PublicationActivity.java


示例3: testValidTopicFilterWildcards

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Test
public void testValidTopicFilterWildcards() throws Exception {
  String methodName = Utility.getMethodName();
  LoggingUtilities.banner(log, cclass, methodName);
  String[] topics = new String[] { 
          "+", "+/+", "+/foo", 
          "+/tennis/#",
          "foo/+", "foo/+/bar", 
          "/+", "/+/sport/+/player1",
          "#", "/#",
          "sport/#",
          "sport/tennis/#"
   };
  
  for(String topic:topics){
      MqttTopic.validate(topic, true);
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:19,代码来源:MqttTopicTest.java


示例4: repeatedlyPub

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
void repeatedlyPub() {
  String methodName = Utility.getMethodName();

  int i = 0;
  while (mqttClient.isConnected()) {
    try {
      if (i > 999999) {
        i = 0;
      }
      byte[] payload = ("Message payload " + getClass().getName() + ".publish" + (i++)).getBytes();
      MqttTopic mqttTopic = mqttClient.getTopic(FirstSubTopicString);
      log.info("Publishing to..." + FirstSubTopicString);
      mqttTopic.publish(payload, 1, false);

    }
    catch (Exception exception) {
      log.fine("Caught exception:" + exception);
      // Don't fail - we are going to get an exception as we disconnected during takeOver
      // Its likely the publish rate is too high i.e. inflight window is full
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:23,代码来源:LiveTakeOverTest.java


示例5: onAddSubscription

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
public void onAddSubscription(Subscription subscription) {
    try {
        MqttTopic.validate(subscription.getTopic(),true);
    }catch (IllegalArgumentException e){
        TipUtil.showSnackbar(mCoordinatorLayout,e.getMessage());
        return;
    }
    subscription.setConnectionId(mConnection.getId());
    mSubscription = subscription;
    RealmHelper.getInstance().addSubscription(mSubscription);
    subscribe(subscription);
}
 
开发者ID:emqtt,项目名称:EMQ-Android-Toolkit,代码行数:14,代码来源:DashboardActivity.java


示例6: pubMsg

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public static void pubMsg(String tcpUrl, String clientId, String topicName,
			String message) throws MqttException, UnsupportedEncodingException {
		MqttClient client = new MqttClient(tcpUrl, clientId);
		MqttConnectOptions mqcConf = new MqttConnectOptions();
		mqcConf.setConnectionTimeout(300);
		mqcConf.setKeepAliveInterval(1200);
		client.connect(mqcConf);

		MqttTopic topic = client.getTopic(topicName);
		topic.publish(message.getBytes("utf8"), 1, false);

//		client.close();
	}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:14,代码来源:PubWebMessage.java


示例7: pubMsg

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public static void pubMsg(String tcpUrl, String clientId, String topicName)
    throws MqttException, UnsupportedEncodingException {
  MqttClient client = new MqttClient(tcpUrl, clientId);
  MqttConnectOptions mqcConf = new MqttConnectOptions();
  mqcConf.setConnectionTimeout(300);
  mqcConf.setKeepAliveInterval(1200);
  client.connect(mqcConf);

  MqttTopic topic = client.getTopic(topicName);
  for (int i = 0; i < 10; i++) {
    String message = "{\"id\":" + (i+1) + ",\"temp\":12}";
    topic.publish(message.getBytes("utf8"), 1, false);
  }
  client.disconnect();
}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:16,代码来源:PubMessage.java


示例8: publish

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public void publish(String topicName, int qos, byte[] payload)
		throws MqttException {
	final MqttTopic topic = client.getTopic(topicName);

	final MqttMessage message = new MqttMessage(payload);
	topic.publish(message);

	System.out.println("Published data. Topic: " + topic.getName()
			+ "  Message: " + payload);
}
 
开发者ID:chauhansaurabhb,项目名称:EndUserInteractioion_RequestResponse_Command,代码行数:11,代码来源:MQTTPublisher.java


示例9: publish

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
public void publish() {
	if(mqttClient == null || !mqttClient.isConnected()) {
		log.debug("MQTT client unavailable");
		stateService.setRabbitDown();
		return;
	}

	Date now = new Date();
	String messageId = getMessageId();
	String messagePayload = getMessageBody(messageId, now);
	
	try {

		MqttTopic topic = mqttClient.getTopic(rabbitQueueName);
		MqttMessage mqttMessage = new MqttMessage(messagePayload.getBytes());
		mqttMessage.setQos(mqttQos);
		MqttDeliveryToken token = topic.publish(mqttMessage);
		if(mqttQos > 0) {
			token.waitForCompletion();
		}
		
		log.info("{} [{}] {}", instanceName, 
				messageId, messagePayload);
		
		stateService.setRabbitUp();
		
	}
	catch(MqttException ex) {
		log.warn("({}) Publish of MQTT message [{}] to RabbitMQ has failed",
				utils.getPublishedKey(consistencyChecker.getIndex()), messageId);
		
		if( ex.getReasonCode() == 32109 ) {
			log.warn("Connection lost (unsupported QoS mode?)");
		}
		
		stateService.setRabbitDown();
	}
	
}
 
开发者ID:sshcherbakov,项目名称:cf-service-tester,代码行数:41,代码来源:MqttTestMessagePublisher.java


示例10: sendMessageToSensor

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public void sendMessageToSensor(String data) {

        if(!isConnected()){
            System.out.println("Not connected, aborting");
            return;
        }

        // setup topic
        MqttTopic topic = mClient.getTopic(sharedPref.getString("pref_sensor", ""));

        int pubQoS = 2;
        MqttMessage message = new MqttMessage(data.getBytes());
        message.setQos(pubQoS);
        message.setRetained(false);

        // Publish the message
        System.out.println("Publishing to topic \"" + topic + "\" qos " + pubQoS + " with message " + message.toString());
        MqttDeliveryToken token = null;
        try {
            // publish message to broker
            token = topic.publish(message);
            // Wait until the message has been delivered to the broker
            token.waitForCompletion();
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
开发者ID:tchapi,项目名称:NodeMCU-Energy-Monitor,代码行数:30,代码来源:MQTTClient.java


示例11: publish

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public void publish(String topicName, int qos, byte[] payload)
		throws MqttException {
	final MqttTopic topic = client.getTopic(topicName);

	final MqttMessage message = new MqttMessage(payload);
	topic.publish(message);

	System.out.println("Published data. Topic: "
			+ topic.getName() + "  Message: " + payload);
}
 
开发者ID:pankeshlinux,项目名称:IoTSuite,代码行数:11,代码来源:MQTTPublisher.java


示例12: messageArrived

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
/**
 * Received Message from broker
 */
@Override
public void messageArrived(MqttTopic topic, MqttMessage message)
throws Exception {
        Log.i(DEBUG_TAG,"  Topic:\t" + topic.getName() +
              "  Message:\t" + new String(message.getPayload()) +
              "  QoS:\t" + message.getQos());
}
 
开发者ID:JesseFarebro,项目名称:android-mqtt,代码行数:11,代码来源:MqttService.java


示例13: startProducer

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
/**
 * Start a registered producer, so that it can start sending messages.
 * 
 * @param publisher
 *            to start.
 */
private void startProducer(MqttMessageProducer publisher) {

    logger.trace("Starting message producer for broker '{}'", name);

    publisher.setSenderChannel(new MqttSenderChannel() {

        @Override
        public void publish(String topic, byte[] payload) throws Exception {

            if (!started) {
                logger.warn("Broker connection not started. Cannot publish message to topic '{}'", topic);
                return;
            }

            // Create and configure a message
            MqttMessage message = new MqttMessage(payload);
            message.setQos(qos);
            message.setRetained(retain);

            // publish message asynchronously
            MqttTopic mqttTopic = client.getTopic(topic);
            MqttDeliveryToken deliveryToken = mqttTopic.publish(message);

            logger.debug("Publishing message {} to topic '{}'", deliveryToken.getMessageId(), topic);
            if (!async) {
                // wait for publish confirmation
                deliveryToken.waitForCompletion(10000);
                if (!deliveryToken.isComplete()) {
                    logger.error(
                            "Did not receive completion message within timeout limit whilst publishing to topic '{}'",
                            topic);
                }
            }

        }
    });

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:45,代码来源:MqttBrokerConnection.java


示例14: messageArrived

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
public void messageArrived(MqttTopic topic, MqttMessage message) throws Exception {
    
	System.out.println("Message arrived. Topic: " + topic.getName() + "  Message: " + message.toString());

	if(field != null)
		field.setValue(new String(message.getPayload()));
}
 
开发者ID:carlos-salinas,项目名称:vaadin.m2m,代码行数:9,代码来源:SubscribeCallback.java


示例15: messageArrived

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
public void messageArrived(MqttTopic topic, MqttMessage message)
		throws Exception {

	pubsub.receiveEvent(topic.toString(), message);
}
 
开发者ID:chauhansaurabhb,项目名称:EndUserInteractioion_RequestResponse_Command,代码行数:7,代码来源:PushCallback.java


示例16: startProducer

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
/**
 * Start a registered producer, so that it can start sending messages.
 * 
 * @param publisher
 *            to start.
 */
private void startProducer(MqttMessageProducer publisher) {

	logger.trace("Starting message producer for broker '{}'", name);

	publisher.setSenderChannel(new MqttSenderChannel() {

		@Override
		public void publish(String topic, byte[] payload) throws Exception {

			if (!started) {
				logger.warn(
						"Broker connection not started. Cannot publish message to topic '{}'",
						topic);
				return;
			}

			// Create and configure a message
			MqttMessage message = new MqttMessage(payload);
			message.setQos(qos);
			message.setRetained(retain);

			// publish message asynchronously
			MqttTopic mqttTopic = client.getTopic(topic);
			MqttDeliveryToken deliveryToken = mqttTopic.publish(message);

			logger.debug("Publishing message {} to topic '{}'",
					deliveryToken.getMessageId(), topic);
			if (!async) {
				// wait for publish confirmation
				deliveryToken.waitForCompletion(10000);
				if (!deliveryToken.isComplete()) {
					logger.error(
							"Did not receive completion message within timeout limit whilst publishing to topic '{}'",
							topic);
				}
			}

		}
	});

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:48,代码来源:MqttBrokerConnection.java


示例17: messageArrived

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
  public void messageArrived(MqttTopic topic, MqttMessage message) throws Exception {

pubsub.receiveEvent(topic.toString(), message);
  }
 
开发者ID:pankeshlinux,项目名称:IoTSuite,代码行数:6,代码来源:PushCallback.java


示例18: messageArrived

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
@Override
public void messageArrived(MqttTopic arg0, MqttMessage arg1)
        throws Exception {
    //Log.i("GRAPH", "Got value " + arg1.toString());
    updateText(arg1.toString());
}
 
开发者ID:zadata,项目名称:mqtt-client-android-graphdemo,代码行数:7,代码来源:ZADataGraphDemoActivity.java


示例19: Status

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
public Status(MqttTopic topic, TVSerialInterface serialInterface, TVState state) {
	this.topic = topic;
	this.serialInterface = serialInterface;
	this.state = state;
}
 
开发者ID:hardillb,项目名称:LGTV2MQTT,代码行数:6,代码来源:Status.java


示例20: testPubSub

import org.eclipse.paho.client.mqttv3.MqttTopic; //导入依赖的package包/类
/**
 * @throws Exception 
 */
@Test
public void testPubSub() throws Exception {
  String methodName = Utility.getMethodName();
  LoggingUtilities.banner(log, cclass, methodName);

  IMqttClient client = null;
  try {
    String topicStr = "topic" + "_02";
    String clientId = methodName;
    client = clientFactory.createMqttClient(serverURI, clientId);

    log.info("Assigning callback...");
    MessageListener listener = new MessageListener();
    client.setCallback(listener);

    log.info("Connecting...(serverURI:" + serverURI + ", ClientId:" + clientId);
    client.connect();

    log.info("Subscribing to..." + topicStr);
    client.subscribe(topicStr);

    log.info("Publishing to..." + topicStr);
    MqttTopic topic = client.getTopic(topicStr);
    MqttMessage message = new MqttMessage("foo".getBytes());
    topic.publish(message);

    log.info("Checking msg");
    MqttMessage msg = listener.getNextMessage();
    Assert.assertNotNull(msg);
    Assert.assertEquals("foo", msg.toString());

    log.info("getTopic name");
    String topicName = topic.getName();
    log.info("topicName = " + topicName);
    Assert.assertEquals(topicName, topicStr);

    log.info("Disconnecting...");
    client.disconnect();
  }
  finally {
    if (client != null) {
      log.info("Close...");
      client.close();
    }
  }
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:50,代码来源:BasicTest.java



注:本文中的org.eclipse.paho.client.mqttv3.MqttTopic类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TIntFloatHashMap类代码示例发布时间:2022-05-21
下一篇:
Java StateMachine类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap