MqttProperties.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.ruoyi.common.config;
  2. import lombok.Data;
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4. import org.springframework.context.annotation.Configuration;
  5. /**
  6. * MQTT连接属性配置类
  7. *
  8. * <p>用于从application.yml或application.properties文件中加载MQTT相关的配置项,
  9. * 支持自定义MQTT服务器地址、客户端ID、用户名密码等各种连接参数。</p>
  10. *
  11. * @author andy
  12. * @version 1.0.0
  13. * @since 2025-06-17
  14. */
  15. @Data
  16. @Configuration
  17. @ConfigurationProperties(prefix = "mqtt")
  18. public class MqttProperties {
  19. /**
  20. * 服务器地址URI,例如: tcp://localhost:1883
  21. */
  22. private String serverUri;
  23. /**
  24. * 客户端ID
  25. */
  26. private String clientId;
  27. /**
  28. * 用户名
  29. */
  30. private String username;
  31. /**
  32. * 密码
  33. */
  34. private String password;
  35. /**
  36. * 超时时间,单位秒
  37. */
  38. private int timeout = 30;
  39. /**
  40. * 保活时间,单位秒
  41. */
  42. private int keepAlive = 60;
  43. /**
  44. * 是否自动重连
  45. */
  46. private boolean autoReconnect = true;
  47. /**
  48. * 是否清除会话
  49. */
  50. private boolean cleanSession = true;
  51. /**
  52. * 默认QoS级别
  53. */
  54. private int defaultQos = 1;
  55. /**
  56. * 默认主题
  57. */
  58. private String defaultTopic = "test/topic";
  59. /**
  60. * 消息发布/订阅超时,单位秒
  61. */
  62. private int commandTimeout = 10;
  63. }