exhook.proto 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //------------------------------------------------------------------------------
  16. syntax = "proto3";
  17. option csharp_namespace = "Emqx.Exhook.V2";
  18. option go_package = "emqx.io/grpc/exhook";
  19. option java_multiple_files = true;
  20. option java_package = "io.emqx.exhook";
  21. option java_outer_classname = "EmqxExHookProto";
  22. // The exhook proto version should be fixed as `v2` in EMQX v5.x
  23. // to make sure the exhook proto version is compatible
  24. package emqx.exhook.v2;
  25. service HookProvider {
  26. rpc OnProviderLoaded(ProviderLoadedRequest) returns (LoadedResponse) {};
  27. rpc OnProviderUnloaded(ProviderUnloadedRequest) returns (EmptySuccess) {};
  28. rpc OnClientConnect(ClientConnectRequest) returns (EmptySuccess) {};
  29. rpc OnClientConnack(ClientConnackRequest) returns (EmptySuccess) {};
  30. rpc OnClientConnected(ClientConnectedRequest) returns (EmptySuccess) {};
  31. rpc OnClientDisconnected(ClientDisconnectedRequest) returns (EmptySuccess) {};
  32. rpc OnClientAuthenticate(ClientAuthenticateRequest) returns (ValuedResponse) {};
  33. rpc OnClientAuthorize(ClientAuthorizeRequest) returns (ValuedResponse) {};
  34. rpc OnClientSubscribe(ClientSubscribeRequest) returns (EmptySuccess) {};
  35. rpc OnClientUnsubscribe(ClientUnsubscribeRequest) returns (EmptySuccess) {};
  36. rpc OnSessionCreated(SessionCreatedRequest) returns (EmptySuccess) {};
  37. rpc OnSessionSubscribed(SessionSubscribedRequest) returns (EmptySuccess) {};
  38. rpc OnSessionUnsubscribed(SessionUnsubscribedRequest) returns (EmptySuccess) {};
  39. rpc OnSessionResumed(SessionResumedRequest) returns (EmptySuccess) {};
  40. rpc OnSessionDiscarded(SessionDiscardedRequest) returns (EmptySuccess) {};
  41. rpc OnSessionTakenover(SessionTakenoverRequest) returns (EmptySuccess) {};
  42. rpc OnSessionTerminated(SessionTerminatedRequest) returns (EmptySuccess) {};
  43. rpc OnMessagePublish(MessagePublishRequest) returns (ValuedResponse) {};
  44. rpc OnMessageDelivered(MessageDeliveredRequest) returns (EmptySuccess) {};
  45. rpc OnMessageDropped(MessageDroppedRequest) returns (EmptySuccess) {};
  46. rpc OnMessageAcked(MessageAckedRequest) returns (EmptySuccess) {};
  47. }
  48. //------------------------------------------------------------------------------
  49. // Request
  50. //------------------------------------------------------------------------------
  51. message ProviderLoadedRequest {
  52. BrokerInfo broker = 1;
  53. RequestMeta meta = 2;
  54. }
  55. message ProviderUnloadedRequest {
  56. RequestMeta meta = 1;
  57. }
  58. message ClientConnectRequest {
  59. ConnInfo conninfo = 1;
  60. // MQTT CONNECT packet's properties (MQTT v5.0)
  61. //
  62. // It should be empty on MQTT v3.1.1/v3.1 or others protocol
  63. repeated Property props = 2;
  64. RequestMeta meta = 3;
  65. }
  66. message ClientConnackRequest {
  67. ConnInfo conninfo = 1;
  68. string result_code = 2;
  69. repeated Property props = 3;
  70. RequestMeta meta = 4;
  71. }
  72. message ClientConnectedRequest {
  73. ClientInfo clientinfo = 1;
  74. RequestMeta meta = 2;
  75. }
  76. message ClientDisconnectedRequest {
  77. ClientInfo clientinfo = 1;
  78. string reason = 2;
  79. RequestMeta meta = 3;
  80. }
  81. message ClientAuthenticateRequest {
  82. ClientInfo clientinfo = 1;
  83. bool result = 2;
  84. RequestMeta meta = 3;
  85. }
  86. message ClientAuthorizeRequest {
  87. ClientInfo clientinfo = 1;
  88. enum AuthorizeReqType {
  89. PUBLISH = 0;
  90. SUBSCRIBE = 1;
  91. }
  92. AuthorizeReqType type = 2;
  93. // In ClientAuthorizeRequest.
  94. // Only "real-topic" will be serialized in gRPC request when shared-sub.
  95. // For example, when client subscribes to `$share/group/t/1`, the real topic is `t/1`.
  96. string topic = 3;
  97. bool result = 4;
  98. RequestMeta meta = 5;
  99. }
  100. message ClientSubscribeRequest {
  101. ClientInfo clientinfo = 1;
  102. repeated Property props = 2;
  103. repeated TopicFilter topic_filters = 3;
  104. RequestMeta meta = 4;
  105. }
  106. message ClientUnsubscribeRequest {
  107. ClientInfo clientinfo = 1;
  108. repeated Property props = 2;
  109. repeated TopicFilter topic_filters = 3;
  110. RequestMeta meta = 4;
  111. }
  112. message SessionCreatedRequest {
  113. ClientInfo clientinfo = 1;
  114. RequestMeta meta = 2;
  115. }
  116. message SessionSubscribedRequest {
  117. ClientInfo clientinfo = 1;
  118. string topic = 2;
  119. SubOpts subopts = 3;
  120. RequestMeta meta = 4;
  121. }
  122. message SessionUnsubscribedRequest {
  123. ClientInfo clientinfo = 1;
  124. string topic = 2;
  125. RequestMeta meta = 3;
  126. }
  127. message SessionResumedRequest {
  128. ClientInfo clientinfo = 1;
  129. RequestMeta meta = 2;
  130. }
  131. message SessionDiscardedRequest {
  132. ClientInfo clientinfo = 1;
  133. RequestMeta meta = 2;
  134. }
  135. message SessionTakenoverRequest {
  136. ClientInfo clientinfo = 1;
  137. RequestMeta meta = 2;
  138. }
  139. message SessionTerminatedRequest {
  140. ClientInfo clientinfo = 1;
  141. string reason = 2;
  142. RequestMeta meta = 3;
  143. }
  144. message MessagePublishRequest {
  145. Message message = 1;
  146. RequestMeta meta = 2;
  147. }
  148. message MessageDeliveredRequest {
  149. ClientInfo clientinfo = 1;
  150. Message message = 2;
  151. RequestMeta meta = 3;
  152. }
  153. message MessageDroppedRequest {
  154. Message message = 1;
  155. string reason = 2;
  156. RequestMeta meta = 3;
  157. }
  158. message MessageAckedRequest {
  159. ClientInfo clientinfo = 1;
  160. Message message = 2;
  161. RequestMeta meta = 3;
  162. }
  163. //------------------------------------------------------------------------------
  164. // Response
  165. //------------------------------------------------------------------------------
  166. // Responsed by `ProviderLoadedRequest`
  167. message LoadedResponse {
  168. repeated HookSpec hooks = 1;
  169. }
  170. // Responsed by `ClientAuthenticateRequest` `ClientAuthorizeRequest` `MessagePublishRequest`
  171. message ValuedResponse {
  172. // The responded value type
  173. // - contiune: Use the responded value and execute the next hook
  174. // - ignore: Ignore the responded value
  175. // - stop_and_return: Use the responded value and stop the chain executing
  176. enum ResponsedType {
  177. CONTINUE = 0;
  178. IGNORE = 1;
  179. STOP_AND_RETURN = 2;
  180. }
  181. ResponsedType type = 1;
  182. oneof value {
  183. // Boolean result, used on the 'client.authenticate', 'client.authorize' hooks
  184. bool bool_result = 3;
  185. // Message result, used on the 'message.*' hooks
  186. Message message = 4;
  187. }
  188. }
  189. // no Response by other Requests
  190. message EmptySuccess { }
  191. //------------------------------------------------------------------------------
  192. // Basic data types
  193. //------------------------------------------------------------------------------
  194. message BrokerInfo {
  195. string version = 1;
  196. string sysdescr = 2;
  197. int64 uptime = 3;
  198. string datetime = 4;
  199. }
  200. message HookSpec {
  201. // The registered hooks name
  202. //
  203. // Available value:
  204. // "client.connect", "client.connack"
  205. // "client.connected", "client.disconnected"
  206. // "client.authenticate", "client.authorize"
  207. // "client.subscribe", "client.unsubscribe"
  208. //
  209. // "session.created", "session.subscribed"
  210. // "session.unsubscribed", "session.resumed"
  211. // "session.discarded", "session.takenover"
  212. // "session.terminated"
  213. //
  214. // "message.publish", "message.delivered"
  215. // "message.acked", "message.dropped"
  216. string name = 1;
  217. // The topic filters for message hooks
  218. repeated string topics = 2;
  219. }
  220. message ConnInfo {
  221. string node = 1;
  222. string clientid = 2;
  223. string username = 3;
  224. string peerhost = 4;
  225. uint32 sockport = 5;
  226. string proto_name = 6;
  227. string proto_ver = 7;
  228. uint32 keepalive = 8;
  229. uint32 peerport = 9;
  230. }
  231. message ClientInfo {
  232. string node = 1;
  233. string clientid = 2;
  234. string username = 3;
  235. string password = 4;
  236. string peerhost = 5;
  237. uint32 sockport = 6;
  238. string protocol = 7;
  239. string mountpoint = 8;
  240. bool is_superuser = 9;
  241. bool anonymous = 10;
  242. // common name of client TLS cert
  243. string cn = 11;
  244. // subject of client TLS cert
  245. string dn = 12;
  246. uint32 peerport = 13;
  247. }
  248. message Message {
  249. string node = 1;
  250. string id = 2;
  251. uint32 qos = 3;
  252. string from = 4;
  253. string topic = 5;
  254. bytes payload = 6;
  255. uint64 timestamp = 7;
  256. // The key of header can be:
  257. // - username:
  258. // * Readonly
  259. // * The username of sender client
  260. // * Value type: utf8 string
  261. // - protocol:
  262. // * Readonly
  263. // * The protocol name of sender client
  264. // * Value type: string enum with "mqtt", "mqtt-sn", ...
  265. // - peerhost:
  266. // * Readonly
  267. // * The peerhost of sender client
  268. // * Value type: ip address string
  269. // - allow_publish:
  270. // * Writable
  271. // * Whether to allow the message to be published by emqx
  272. // * Value type: string enum with "true", "false", default is "true"
  273. //
  274. // Notes: All header may be missing, which means that the message does not
  275. // carry these headers. We can guarantee that clients coming from MQTT,
  276. // MQTT-SN, CoAP, LwM2M and other natively supported protocol clients will
  277. // carry these headers, but there is no guarantee that messages published
  278. // by other means will do, e.g. messages published by HTTP-API
  279. map<string, string> headers = 8;
  280. }
  281. message Property {
  282. string name = 1;
  283. string value = 2;
  284. }
  285. message TopicFilter {
  286. string name = 1;
  287. // Deprecated
  288. // Since EMQX 5.4.0, we have deprecated the 'qos' field in the `TopicFilter` structure.
  289. // A new field named 'subopts,' has been added to encompass all subscription options.
  290. // Please see the `SubOpts` structure for details.
  291. reserved 2;
  292. reserved "qos";
  293. SubOpts subopts = 3;
  294. }
  295. message SubOpts {
  296. // The QoS level
  297. uint32 qos = 1;
  298. // Deprecated
  299. reserved 2;
  300. reserved "share";
  301. // Since EMQX 5.4.0, we have deprecated the 'share' field in the `SubOpts` structure.
  302. // The group name of shared subscription will be serialized with topic.
  303. // hooks:
  304. // "client.subscribe":
  305. // ClientSubscribeRequest.TopicFilter.name = "$share/group/topic/1"
  306. // "client.unsubscribe":
  307. // ClientUnsubscribeRequest.TopicFilter.name = "$share/group/topic/1"
  308. // "session.subscribed":
  309. // SessionSubscribedRequest.topic = "$share/group/topic/1"
  310. // "session.unsubscribed":
  311. // SessionUnsubscribedRequest.topic = "$share/group/topic/1"
  312. // The Retain Handling option (MQTT v5.0)
  313. //
  314. // 0 = Send retained messages at the time of the subscribe
  315. // 1 = Send retained messages at subscribe only if the subscription does
  316. // not currently exist
  317. // 2 = Do not send retained messages at the time of the subscribe
  318. uint32 rh = 3;
  319. // The Retain as Published option (MQTT v5.0)
  320. //
  321. // If 1, Application Messages forwarded using this subscription keep the
  322. // RETAIN flag they were published with.
  323. // If 0, Application Messages forwarded using this subscription have the
  324. // RETAIN flag set to 0.
  325. // Retained messages sent when the subscription is established have the RETAIN flag set to 1.
  326. uint32 rap = 4;
  327. // The No Local option (MQTT v5.0)
  328. //
  329. // If the value is 1, Application Messages MUST NOT be forwarded to a
  330. // connection with a ClientID equal to the ClientID of the publishing
  331. uint32 nl = 5;
  332. }
  333. message RequestMeta {
  334. string node = 1;
  335. string version = 2;
  336. string sysdescr = 3;
  337. string cluster_name = 4;
  338. }