MqttSettings.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Copyright (c) 2013, 2014 Paolo Patierno
  3. All rights reserved. This program and the accompanying materials
  4. are made available under the terms of the Eclipse Public License v1.0
  5. and Eclipse Distribution License v1.0 which accompany this distribution.
  6. The Eclipse Public License is available at
  7. http://www.eclipse.org/legal/epl-v10.html
  8. and the Eclipse Distribution License is available at
  9. http://www.eclipse.org/org/documents/edl-v10.php.
  10. Contributors:
  11. Paolo Patierno - initial API and implementation and/or initial documentation
  12. */
  13. namespace uPLibrary.Networking.M2Mqtt
  14. {
  15. /// <summary>
  16. /// Settings class for the MQTT broker
  17. /// </summary>
  18. public class MqttSettings
  19. {
  20. // default port for MQTT protocol
  21. public const int MQTT_BROKER_DEFAULT_PORT = 1883;
  22. public const int MQTT_BROKER_DEFAULT_SSL_PORT = 8883;
  23. // default timeout on receiving from client
  24. public const int MQTT_DEFAULT_TIMEOUT = 30000;
  25. // max publish, subscribe and unsubscribe retry for QoS Level 1 or 2
  26. public const int MQTT_ATTEMPTS_RETRY = 3;
  27. // delay for retry publish, subscribe and unsubscribe for QoS Level 1 or 2
  28. public const int MQTT_DELAY_RETRY = 10000;
  29. // broker need to receive the first message (CONNECT)
  30. // within a reasonable amount of time after TCP/IP connection
  31. public const int MQTT_CONNECT_TIMEOUT = 30000;
  32. // default inflight queue size
  33. public const int MQTT_MAX_INFLIGHT_QUEUE_SIZE = int.MaxValue;
  34. /// <summary>
  35. /// Listening connection port
  36. /// </summary>
  37. public int Port { get; internal set; }
  38. /// <summary>
  39. /// Listening connection SSL port
  40. /// </summary>
  41. public int SslPort { get; internal set; }
  42. /// <summary>
  43. /// Timeout on client connection (before receiving CONNECT message)
  44. /// </summary>
  45. public int TimeoutOnConnection { get; internal set; }
  46. /// <summary>
  47. /// Timeout on receiving
  48. /// </summary>
  49. public int TimeoutOnReceiving { get; internal set; }
  50. /// <summary>
  51. /// Attempts on retry
  52. /// </summary>
  53. public int AttemptsOnRetry { get; internal set; }
  54. /// <summary>
  55. /// Delay on retry
  56. /// </summary>
  57. public int DelayOnRetry { get; internal set; }
  58. /// <summary>
  59. /// Inflight queue size
  60. /// </summary>
  61. public int InflightQueueSize { get; set; }
  62. /// <summary>
  63. /// Singleton instance of settings
  64. /// </summary>
  65. public static MqttSettings Instance
  66. {
  67. get
  68. {
  69. if (instance == null)
  70. instance = new MqttSettings();
  71. return instance;
  72. }
  73. }
  74. // singleton instance
  75. private static MqttSettings instance;
  76. /// <summary>
  77. /// Constructor
  78. /// </summary>
  79. private MqttSettings()
  80. {
  81. this.Port = MQTT_BROKER_DEFAULT_PORT;
  82. this.SslPort = MQTT_BROKER_DEFAULT_SSL_PORT;
  83. this.TimeoutOnReceiving = MQTT_DEFAULT_TIMEOUT;
  84. this.AttemptsOnRetry = MQTT_ATTEMPTS_RETRY;
  85. this.DelayOnRetry = MQTT_DELAY_RETRY;
  86. this.TimeoutOnConnection = MQTT_CONNECT_TIMEOUT;
  87. this.InflightQueueSize = MQTT_MAX_INFLIGHT_QUEUE_SIZE;
  88. }
  89. }
  90. }