├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-MPL-RabbitMQ ├── Makefile ├── README.md ├── erlang.mk ├── erlang_ls.config ├── include └── rabbit_message_timestamp.hrl ├── rabbitmq-components.mk ├── src └── rabbit_timestamp_interceptor.erl └── test └── rabbit_message_timestamp_SUITE.erl /.gitignore: -------------------------------------------------------------------------------- 1 | .sw? 2 | .*.sw? 3 | *.beam 4 | /.erlang.mk/ 5 | /cover/ 6 | /debug/ 7 | /deps/ 8 | /doc/ 9 | /ebin/ 10 | /escript/ 11 | /escript.lock 12 | /logs/ 13 | /plugins/ 14 | /plugins.lock 15 | /sbin/ 16 | /sbin.lock 17 | 18 | /rabbitmq_message_timestamp.d 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open 4 | and welcoming community, we pledge to respect all people who contribute through reporting 5 | issues, posting feature requests, updating documentation, submitting pull requests or 6 | patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free experience for 9 | everyone, regardless of level of experience, gender, gender identity and expression, 10 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 11 | religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic addresses, 20 | without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 24 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 25 | Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors 26 | that they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and 29 | consistently applying these principles to every aspect of managing this project. Project 30 | maintainers who do not follow or enforce the Code of Conduct may be permanently removed 31 | from the project team. 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an 34 | individual is representing the project or its community. 35 | 36 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 37 | contacting a project maintainer at [info@rabbitmq.com](mailto:info@rabbitmq.com). All complaints will 38 | be reviewed and investigated and will result in a response that is deemed necessary and 39 | appropriate to the circumstances. Maintainers are obligated to maintain confidentiality 40 | with regard to the reporter of an incident. 41 | 42 | This Code of Conduct is adapted from the 43 | [Contributor Covenant](https://contributor-covenant.org), version 1.3.0, available at 44 | [contributor-covenant.org/version/1/3/0/](https://contributor-covenant.org/version/1/3/0/) 45 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | RabbitMQ projects use pull requests to discuss, collaborate on and accept code contributions. 4 | Pull requests is the primary place of discussing code changes. 5 | 6 | ## How to Contribute 7 | 8 | The process is fairly standard: 9 | 10 | * Fork the repository or repositories you plan on contributing to 11 | * Clone [RabbitMQ umbrella repository](https://github.com/rabbitmq/rabbitmq-public-umbrella) 12 | * `cd umbrella`, `make co` 13 | * Create a branch with a descriptive name in the relevant repositories 14 | * Make your changes, run tests, commit with a [descriptive message](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), push to your fork 15 | * Submit pull requests with an explanation what has been changed and **why** 16 | * Submit a filled out and signed [Contributor Agreement](https://cla.pivotal.io) if needed (see below) 17 | * Be patient. We will get to your pull request eventually 18 | 19 | If what you are going to work on is a substantial change, please first ask the core team 20 | of their opinion on [RabbitMQ mailing list](https://groups.google.com/forum/#!forum/rabbitmq-users). 21 | 22 | 23 | ## Code of Conduct 24 | 25 | See [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md). 26 | 27 | 28 | ## Contributor Agreement 29 | 30 | If you want to contribute a non-trivial change, please submit a signed copy of our 31 | [Contributor Agreement](https://cla.pivotal.io/) around the time 32 | you submit your pull request. This will make it much easier (in some cases, possible) 33 | for the RabbitMQ team at Pivotal to merge your contribution. 34 | 35 | 36 | ## Where to Ask Questions 37 | 38 | If something isn't clear, feel free to ask on our [mailing list](https://groups.google.com/forum/#!forum/rabbitmq-users). 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This package is licensed under the MPL 2.0. For the MPL 2.0, please see LICENSE-MPL-RabbitMQ. 2 | 3 | If you have any questions regarding licensing, please contact us at 4 | info@rabbitmq.com. 5 | -------------------------------------------------------------------------------- /LICENSE-MPL-RabbitMQ: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT = rabbitmq_message_timestamp 2 | PROJECT_DESCRIPTION = RabbitMQ Message Timestamp 3 | RABBITMQ_VERSION ?= v3.11.x 4 | 5 | define PROJECT_APP_EXTRA_KEYS 6 | {broker_version_requirements, ["3.11.0"]} 7 | endef 8 | 9 | DEPS = rabbit_common rabbit 10 | TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client 11 | 12 | DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk 13 | DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk 14 | 15 | # FIXME: Use erlang.mk patched for RabbitMQ, while waiting for PRs to be 16 | # reviewed and merged. 17 | 18 | ERLANG_MK_REPO = https://github.com/rabbitmq/erlang.mk.git 19 | ERLANG_MK_COMMIT = rabbitmq-tmp 20 | 21 | include rabbitmq-components.mk 22 | 23 | dep_amqp_client = git_rmq-subfolder rabbitmq-erlang-client $(RABBITMQ_VERSION) 24 | dep_rabbit_common = git_rmq-subfolder rabbitmq-common $(RABBITMQ_VERSION) 25 | dep_rabbit = git_rmq-subfolder rabbitmq-server $(RABBITMQ_VERSION) 26 | dep_rabbitmq_ct_client_helpers = git_rmq-subfolder rabbitmq-ct-client-helpers $(RABBITMQ_VERSION) 27 | dep_rabbitmq_ct_helpers = git_rmq-subfolder rabbitmq-ct-helpers $(RABBITMQ_VERSION) 28 | include erlang.mk 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RabbitMQ Message Timestamp Plugin # 2 | 3 | This plugin fills the `timestamp` property and `timestamp_in_ms` header of a message as it enters 4 | RabbitMQ with the current (server node) timestamp value. 5 | 6 | ## Supported RabbitMQ Versions ## 7 | 8 | This plugin targets RabbitMQ 3.6.0 until 3.11. 9 | 10 | :warning: Starting in RabbitMQ 3.12, this plugin is **deprecated** :warning: 11 | 12 | In RabbitMQ 3.12 and later versions, instead of using this plugin, use the following `rabbitmq.conf` snippet: 13 | ```ini 14 | message_interceptors.incoming.set_header_timestamp.overwrite = false 15 | ``` 16 | To allow timestamps being [overwritten](#always-overwrite-timestamps) use: 17 | ```ini 18 | message_interceptors.incoming.set_header_timestamp.overwrite = true 19 | ``` 20 | 21 | ## Limitations 22 | 23 | This plugin cannot be used together with [rabbitmq-routing-node-stamp](https://github.com/rabbitmq/rabbitmq-routing-node-stamp) 24 | as they override the same extension point. 25 | 26 | ## Installation 27 | 28 | Binary builds of this plugin can be obtained from 29 | the [Community Plugins page](https://www.rabbitmq.com/community-plugins.html). 30 | 31 | See [Plugin Installation](https://www.rabbitmq.com/installing-plugins.html) for details 32 | about how to install plugins that do not ship with RabbitMQ. 33 | 34 | ## Building from Source 35 | 36 | You can build and install it like any other plugin (see 37 | [the plugin development guide](https://www.rabbitmq.com/plugin-development.html)). 38 | 39 | ## Usage ## 40 | 41 | Just enable the plugin with the following command: 42 | 43 | ```bash 44 | rabbitmq-plugins enable rabbitmq_message_timestamp 45 | ``` 46 | 47 | The plugin will then hook into the `basic.publish` process in order to 48 | add the current timestamp as seen by the broker. 49 | 50 | ## Always overwrite timestamps ## 51 | 52 | This plugin will not overwrite an existing timestamp on a message. To always 53 | overwrite, create an `advanced.config` file for RabbitMQ with the following 54 | content, or add the `rabbitmq_message_timestamp` term to your existing file: 55 | 56 | ``` 57 | [ 58 | {rabbitmq_message_timestamp, [ 59 | {overwrite_timestamps, true} 60 | ]} 61 | ]. 62 | ``` 63 | 64 | ## Limitations ## 65 | 66 | The plugin hooks into the `basic.publish` path, so expect a small 67 | throughput reduction when using this plugin, since it has to modify 68 | every message that crosses RabbitMQ. 69 | 70 | This plugin should not be enabled at the same time as any other 71 | interceptors that hook into the `basic.publish` process, such as 72 | the `rabbitmq-routing-node-stamp` plugin. Enabling more than one 73 | interceptor that is registered to the `basic.publish` process will 74 | cause all AMQP 0-9-1 connections to fail when creating a new channel. 75 | 76 | If there's enough demand, we could add in the future a way for only 77 | time-stamping messages that crosses certain exchanges, say by applying 78 | policies. 79 | 80 | ## LICENSE ## 81 | 82 | See the LICENSE file 83 | -------------------------------------------------------------------------------- /erlang_ls.config: -------------------------------------------------------------------------------- 1 | # vim: ft=yaml 2 | # https://erlang-ls.github.io/configuration/ 3 | # otp_path: "/path/to/otp/lib/erlang" 4 | deps_dirs: 5 | - "deps/*" 6 | - "deps/*/apps/*" 7 | - "extra_deps/*" 8 | diagnostics: 9 | disabled: 10 | - bound_var_in_pattern 11 | enabled: 12 | - crossref 13 | - dialyzer 14 | # - elvis 15 | - compiler 16 | # - elvis 17 | include_dirs: 18 | - "deps" 19 | - "deps/*/include" 20 | - "extra_deps/*/include" 21 | - "include" 22 | lenses: 23 | enabled: 24 | - ct-run-test 25 | - show-behaviour-usages 26 | - suggest-spec 27 | - function-references 28 | disabled: [] 29 | # macros: 30 | # - name: DEFINED_WITH_VALUE 31 | # value: 42 32 | # code_reload: 33 | # node: rabbit@localhost 34 | plt_path: .rabbitmq_server_release.plt 35 | -------------------------------------------------------------------------------- /include/rabbit_message_timestamp.hrl: -------------------------------------------------------------------------------- 1 | %% This Source Code Form is subject to the terms of the Mozilla Public 2 | %% License, v. 2.0. If a copy of the MPL was not distributed with this 3 | %% file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | %% 5 | %% Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. 6 | %% 7 | 8 | -define(TIMESTAMP_IN_MS, <<"timestamp_in_ms">>). 9 | -------------------------------------------------------------------------------- /rabbitmq-components.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(.DEFAULT_GOAL),) 2 | # Define default goal to `all` because this file defines some targets 3 | # before the inclusion of erlang.mk leading to the wrong target becoming 4 | # the default. 5 | .DEFAULT_GOAL = all 6 | endif 7 | 8 | # PROJECT_VERSION defaults to: 9 | # 1. the version exported by rabbitmq-server-release; 10 | # 2. the version stored in `git-revisions.txt`, if it exists; 11 | # 3. a version based on git-describe(1), if it is a Git clone; 12 | # 4. 0.0.0 13 | 14 | PROJECT_VERSION := $(RABBITMQ_VERSION) 15 | 16 | ifeq ($(PROJECT_VERSION),) 17 | PROJECT_VERSION := $(shell \ 18 | if test -f git-revisions.txt; then \ 19 | head -n1 git-revisions.txt | \ 20 | awk '{print $$$(words $(PROJECT_DESCRIPTION) version);}'; \ 21 | else \ 22 | (git describe --dirty --abbrev=7 --tags --always --first-parent \ 23 | 2>/dev/null || echo rabbitmq_v0_0_0) | \ 24 | sed -e 's/^rabbitmq_v//' -e 's/^v//' -e 's/_/./g' -e 's/-/+/' \ 25 | -e 's/-/./g'; \ 26 | fi) 27 | endif 28 | 29 | # -------------------------------------------------------------------- 30 | # RabbitMQ components. 31 | # -------------------------------------------------------------------- 32 | 33 | # For RabbitMQ repositories, we want to checkout branches which match 34 | # the parent project. For instance, if the parent project is on a 35 | # release tag, dependencies must be on the same release tag. If the 36 | # parent project is on a topic branch, dependencies must be on the same 37 | # topic branch or fallback to `stable` or `main` whichever was the 38 | # base of the topic branch. 39 | 40 | dep_amqp_client = git_rmq-subfolder rabbitmq-erlang-client $(current_rmq_ref) $(base_rmq_ref) main 41 | dep_amqp10_client = git_rmq-subfolder rabbitmq-amqp1.0-client $(current_rmq_ref) $(base_rmq_ref) main 42 | dep_amqp10_common = git_rmq-subfolder rabbitmq-amqp1.0-common $(current_rmq_ref) $(base_rmq_ref) main 43 | dep_rabbit = git_rmq-subfolder rabbitmq-server $(current_rmq_ref) $(base_rmq_ref) main 44 | dep_rabbit_common = git_rmq-subfolder rabbitmq-common $(current_rmq_ref) $(base_rmq_ref) main 45 | dep_rabbitmq_amqp1_0 = git_rmq-subfolder rabbitmq-amqp1.0 $(current_rmq_ref) $(base_rmq_ref) main 46 | dep_rabbitmq_auth_backend_amqp = git_rmq rabbitmq-auth-backend-amqp $(current_rmq_ref) $(base_rmq_ref) main 47 | dep_rabbitmq_auth_backend_cache = git_rmq-subfolder rabbitmq-auth-backend-cache $(current_rmq_ref) $(base_rmq_ref) main 48 | dep_rabbitmq_auth_backend_http = git_rmq-subfolder rabbitmq-auth-backend-http $(current_rmq_ref) $(base_rmq_ref) main 49 | dep_rabbitmq_auth_backend_ldap = git_rmq-subfolder rabbitmq-auth-backend-ldap $(current_rmq_ref) $(base_rmq_ref) main 50 | dep_rabbitmq_auth_backend_oauth2 = git_rmq-subfolder rabbitmq-auth-backend-oauth2 $(current_rmq_ref) $(base_rmq_ref) main 51 | dep_rabbitmq_auth_mechanism_ssl = git_rmq-subfolder rabbitmq-auth-mechanism-ssl $(current_rmq_ref) $(base_rmq_ref) main 52 | dep_rabbitmq_aws = git_rmq-subfolder rabbitmq-aws $(current_rmq_ref) $(base_rmq_ref) main 53 | dep_rabbitmq_boot_steps_visualiser = git_rmq rabbitmq-boot-steps-visualiser $(current_rmq_ref) $(base_rmq_ref) main 54 | dep_rabbitmq_cli = git_rmq-subfolder rabbitmq-cli $(current_rmq_ref) $(base_rmq_ref) main 55 | dep_rabbitmq_codegen = git_rmq-subfolder rabbitmq-codegen $(current_rmq_ref) $(base_rmq_ref) main 56 | dep_rabbitmq_consistent_hash_exchange = git_rmq-subfolder rabbitmq-consistent-hash-exchange $(current_rmq_ref) $(base_rmq_ref) main 57 | dep_rabbitmq_ct_client_helpers = git_rmq-subfolder rabbitmq-ct-client-helpers $(current_rmq_ref) $(base_rmq_ref) main 58 | dep_rabbitmq_ct_helpers = git_rmq-subfolder rabbitmq-ct-helpers $(current_rmq_ref) $(base_rmq_ref) main 59 | dep_rabbitmq_delayed_message_exchange = git_rmq rabbitmq-delayed-message-exchange $(current_rmq_ref) $(base_rmq_ref) main 60 | dep_rabbitmq_dotnet_client = git_rmq rabbitmq-dotnet-client $(current_rmq_ref) $(base_rmq_ref) main 61 | dep_rabbitmq_event_exchange = git_rmq-subfolder rabbitmq-event-exchange $(current_rmq_ref) $(base_rmq_ref) main 62 | dep_rabbitmq_federation = git_rmq-subfolder rabbitmq-federation $(current_rmq_ref) $(base_rmq_ref) main 63 | dep_rabbitmq_federation_management = git_rmq-subfolder rabbitmq-federation-management $(current_rmq_ref) $(base_rmq_ref) main 64 | dep_rabbitmq_java_client = git_rmq rabbitmq-java-client $(current_rmq_ref) $(base_rmq_ref) main 65 | dep_rabbitmq_jms_client = git_rmq rabbitmq-jms-client $(current_rmq_ref) $(base_rmq_ref) main 66 | dep_rabbitmq_jms_cts = git_rmq rabbitmq-jms-cts $(current_rmq_ref) $(base_rmq_ref) main 67 | dep_rabbitmq_jms_topic_exchange = git_rmq-subfolder rabbitmq-jms-topic-exchange $(current_rmq_ref) $(base_rmq_ref) main 68 | dep_rabbitmq_lvc_exchange = git_rmq rabbitmq-lvc-exchange $(current_rmq_ref) $(base_rmq_ref) main 69 | dep_rabbitmq_management = git_rmq-subfolder rabbitmq-management $(current_rmq_ref) $(base_rmq_ref) main 70 | dep_rabbitmq_management_agent = git_rmq-subfolder rabbitmq-management-agent $(current_rmq_ref) $(base_rmq_ref) main 71 | dep_rabbitmq_management_exchange = git_rmq rabbitmq-management-exchange $(current_rmq_ref) $(base_rmq_ref) main 72 | dep_rabbitmq_management_themes = git_rmq rabbitmq-management-themes $(current_rmq_ref) $(base_rmq_ref) main 73 | dep_rabbitmq_message_timestamp = git_rmq rabbitmq-message-timestamp $(current_rmq_ref) $(base_rmq_ref) main 74 | dep_rabbitmq_metronome = git_rmq rabbitmq-metronome $(current_rmq_ref) $(base_rmq_ref) main 75 | dep_rabbitmq_mqtt = git_rmq-subfolder rabbitmq-mqtt $(current_rmq_ref) $(base_rmq_ref) main 76 | dep_rabbitmq_objc_client = git_rmq rabbitmq-objc-client $(current_rmq_ref) $(base_rmq_ref) main 77 | dep_rabbitmq_peer_discovery_aws = git_rmq-subfolder rabbitmq-peer-discovery-aws $(current_rmq_ref) $(base_rmq_ref) main 78 | dep_rabbitmq_peer_discovery_common = git_rmq-subfolder rabbitmq-peer-discovery-common $(current_rmq_ref) $(base_rmq_ref) main 79 | dep_rabbitmq_peer_discovery_consul = git_rmq-subfolder rabbitmq-peer-discovery-consul $(current_rmq_ref) $(base_rmq_ref) main 80 | dep_rabbitmq_peer_discovery_etcd = git_rmq-subfolder rabbitmq-peer-discovery-etcd $(current_rmq_ref) $(base_rmq_ref) main 81 | dep_rabbitmq_peer_discovery_k8s = git_rmq-subfolder rabbitmq-peer-discovery-k8s $(current_rmq_ref) $(base_rmq_ref) main 82 | dep_rabbitmq_prometheus = git_rmq-subfolder rabbitmq-prometheus $(current_rmq_ref) $(base_rmq_ref) main 83 | dep_rabbitmq_random_exchange = git_rmq-subfolder rabbitmq-random-exchange $(current_rmq_ref) $(base_rmq_ref) main 84 | dep_rabbitmq_recent_history_exchange = git_rmq-subfolder rabbitmq-recent-history-exchange $(current_rmq_ref) $(base_rmq_ref) main 85 | dep_rabbitmq_routing_node_stamp = git_rmq rabbitmq-routing-node-stamp $(current_rmq_ref) $(base_rmq_ref) main 86 | dep_rabbitmq_rtopic_exchange = git_rmq rabbitmq-rtopic-exchange $(current_rmq_ref) $(base_rmq_ref) main 87 | dep_rabbitmq_sharding = git_rmq-subfolder rabbitmq-sharding $(current_rmq_ref) $(base_rmq_ref) main 88 | dep_rabbitmq_shovel = git_rmq-subfolder rabbitmq-shovel $(current_rmq_ref) $(base_rmq_ref) main 89 | dep_rabbitmq_shovel_management = git_rmq-subfolder rabbitmq-shovel-management $(current_rmq_ref) $(base_rmq_ref) main 90 | dep_rabbitmq_stomp = git_rmq-subfolder rabbitmq-stomp $(current_rmq_ref) $(base_rmq_ref) main 91 | dep_rabbitmq_stream = git_rmq-subfolder rabbitmq-stream $(current_rmq_ref) $(base_rmq_ref) main 92 | dep_rabbitmq_stream_common = git_rmq-subfolder rabbitmq-stream-common $(current_rmq_ref) $(base_rmq_ref) main 93 | dep_rabbitmq_stream_management = git_rmq-subfolder rabbitmq-stream-management $(current_rmq_ref) $(base_rmq_ref) main 94 | dep_rabbitmq_toke = git_rmq rabbitmq-toke $(current_rmq_ref) $(base_rmq_ref) main 95 | dep_rabbitmq_top = git_rmq-subfolder rabbitmq-top $(current_rmq_ref) $(base_rmq_ref) main 96 | dep_rabbitmq_tracing = git_rmq-subfolder rabbitmq-tracing $(current_rmq_ref) $(base_rmq_ref) main 97 | dep_rabbitmq_trust_store = git_rmq-subfolder rabbitmq-trust-store $(current_rmq_ref) $(base_rmq_ref) main 98 | dep_rabbitmq_test = git_rmq rabbitmq-test $(current_rmq_ref) $(base_rmq_ref) main 99 | dep_rabbitmq_web_dispatch = git_rmq-subfolder rabbitmq-web-dispatch $(current_rmq_ref) $(base_rmq_ref) main 100 | dep_rabbitmq_web_stomp = git_rmq-subfolder rabbitmq-web-stomp $(current_rmq_ref) $(base_rmq_ref) main 101 | dep_rabbitmq_web_stomp_examples = git_rmq-subfolder rabbitmq-web-stomp-examples $(current_rmq_ref) $(base_rmq_ref) main 102 | dep_rabbitmq_web_mqtt = git_rmq-subfolder rabbitmq-web-mqtt $(current_rmq_ref) $(base_rmq_ref) main 103 | dep_rabbitmq_web_mqtt_examples = git_rmq-subfolder rabbitmq-web-mqtt-examples $(current_rmq_ref) $(base_rmq_ref) main 104 | dep_rabbitmq_website = git_rmq rabbitmq-website $(current_rmq_ref) $(base_rmq_ref) live main 105 | dep_toke = git_rmq toke $(current_rmq_ref) $(base_rmq_ref) master 106 | 107 | # Third-party dependencies version pinning. 108 | # 109 | # We do that in this file, which is copied in all projects, to ensure 110 | # all projects use the same versions. It avoids conflicts and makes it 111 | # possible to work with rabbitmq-public-umbrella. 112 | 113 | dep_accept = hex 0.3.5 114 | dep_cowboy = hex 2.8.0 115 | dep_cowlib = hex 2.9.1 116 | dep_looking_glass = git https://github.com/rabbitmq/looking_glass.git master 117 | dep_prometheus = hex 4.10.0 118 | dep_ra = hex 2.4.6 119 | dep_ranch = hex 2.1.0 120 | dep_recon = hex 2.5.3 121 | dep_redbug = hex 2.0.7 122 | dep_thoas = hex 0.4.0 123 | dep_observer_cli = hex 1.7.3 124 | dep_stdout_formatter = hex 0.2.4 125 | dep_sysmon_handler = hex 1.3.0 126 | 127 | RABBITMQ_COMPONENTS = amqp_client \ 128 | amqp10_common \ 129 | amqp10_client \ 130 | rabbit \ 131 | rabbit_common \ 132 | rabbitmq_amqp1_0 \ 133 | rabbitmq_auth_backend_amqp \ 134 | rabbitmq_auth_backend_cache \ 135 | rabbitmq_auth_backend_http \ 136 | rabbitmq_auth_backend_ldap \ 137 | rabbitmq_auth_backend_oauth2 \ 138 | rabbitmq_auth_mechanism_ssl \ 139 | rabbitmq_aws \ 140 | rabbitmq_boot_steps_visualiser \ 141 | rabbitmq_cli \ 142 | rabbitmq_codegen \ 143 | rabbitmq_consistent_hash_exchange \ 144 | rabbitmq_ct_client_helpers \ 145 | rabbitmq_ct_helpers \ 146 | rabbitmq_delayed_message_exchange \ 147 | rabbitmq_dotnet_client \ 148 | rabbitmq_event_exchange \ 149 | rabbitmq_federation \ 150 | rabbitmq_federation_management \ 151 | rabbitmq_java_client \ 152 | rabbitmq_jms_client \ 153 | rabbitmq_jms_cts \ 154 | rabbitmq_jms_topic_exchange \ 155 | rabbitmq_lvc_exchange \ 156 | rabbitmq_management \ 157 | rabbitmq_management_agent \ 158 | rabbitmq_management_exchange \ 159 | rabbitmq_management_themes \ 160 | rabbitmq_message_timestamp \ 161 | rabbitmq_metronome \ 162 | rabbitmq_mqtt \ 163 | rabbitmq_objc_client \ 164 | rabbitmq_peer_discovery_aws \ 165 | rabbitmq_peer_discovery_common \ 166 | rabbitmq_peer_discovery_consul \ 167 | rabbitmq_peer_discovery_etcd \ 168 | rabbitmq_peer_discovery_k8s \ 169 | rabbitmq_prometheus \ 170 | rabbitmq_random_exchange \ 171 | rabbitmq_recent_history_exchange \ 172 | rabbitmq_routing_node_stamp \ 173 | rabbitmq_rtopic_exchange \ 174 | rabbitmq_server_release \ 175 | rabbitmq_sharding \ 176 | rabbitmq_shovel \ 177 | rabbitmq_shovel_management \ 178 | rabbitmq_stomp \ 179 | rabbitmq_stream \ 180 | rabbitmq_stream_common \ 181 | rabbitmq_stream_management \ 182 | rabbitmq_toke \ 183 | rabbitmq_top \ 184 | rabbitmq_tracing \ 185 | rabbitmq_trust_store \ 186 | rabbitmq_web_dispatch \ 187 | rabbitmq_web_mqtt \ 188 | rabbitmq_web_mqtt_examples \ 189 | rabbitmq_web_stomp \ 190 | rabbitmq_web_stomp_examples \ 191 | rabbitmq_website 192 | 193 | # Erlang.mk does not rebuild dependencies by default, once they were 194 | # compiled once, except for those listed in the `$(FORCE_REBUILD)` 195 | # variable. 196 | # 197 | # We want all RabbitMQ components to always be rebuilt: this eases 198 | # the work on several components at the same time. 199 | 200 | FORCE_REBUILD = $(RABBITMQ_COMPONENTS) 201 | 202 | # Several components have a custom erlang.mk/build.config, mainly 203 | # to disable eunit. Therefore, we can't use the top-level project's 204 | # erlang.mk copy. 205 | NO_AUTOPATCH += $(RABBITMQ_COMPONENTS) 206 | 207 | ifeq ($(origin current_rmq_ref),undefined) 208 | ifneq ($(wildcard .git),) 209 | current_rmq_ref := $(shell (\ 210 | ref=$$(LANG=C git branch --list | awk '/^\* \(.*detached / {ref=$$0; sub(/.*detached [^ ]+ /, "", ref); sub(/\)$$/, "", ref); print ref; exit;} /^\* / {ref=$$0; sub(/^\* /, "", ref); print ref; exit}');\ 211 | if test "$$(git rev-parse --short HEAD)" != "$$ref"; then echo "$$ref"; fi)) 212 | else 213 | current_rmq_ref := main 214 | endif 215 | endif 216 | export current_rmq_ref 217 | 218 | ifeq ($(origin base_rmq_ref),undefined) 219 | ifneq ($(wildcard .git),) 220 | possible_base_rmq_ref := main 221 | ifeq ($(possible_base_rmq_ref),$(current_rmq_ref)) 222 | base_rmq_ref := $(current_rmq_ref) 223 | else 224 | base_rmq_ref := $(shell \ 225 | (git rev-parse --verify -q main >/dev/null && \ 226 | git rev-parse --verify -q $(possible_base_rmq_ref) >/dev/null && \ 227 | git merge-base --is-ancestor $$(git merge-base main HEAD) $(possible_base_rmq_ref) && \ 228 | echo $(possible_base_rmq_ref)) || \ 229 | echo main) 230 | endif 231 | else 232 | base_rmq_ref := main 233 | endif 234 | endif 235 | export base_rmq_ref 236 | 237 | # Repository URL selection. 238 | # 239 | # First, we infer other components' location from the current project 240 | # repository URL, if it's a Git repository: 241 | # - We take the "origin" remote URL as the base 242 | # - The current project name and repository name is replaced by the 243 | # target's properties: 244 | # eg. rabbitmq-common is replaced by rabbitmq-codegen 245 | # eg. rabbit_common is replaced by rabbitmq_codegen 246 | # 247 | # If cloning from this computed location fails, we fallback to RabbitMQ 248 | # upstream which is GitHub. 249 | 250 | # Macro to transform eg. "rabbit_common" to "rabbitmq-common". 251 | rmq_cmp_repo_name = $(word 2,$(dep_$(1))) 252 | 253 | # Upstream URL for the current project. 254 | RABBITMQ_COMPONENT_REPO_NAME := $(call rmq_cmp_repo_name,$(PROJECT)) 255 | RABBITMQ_UPSTREAM_FETCH_URL ?= https://github.com/rabbitmq/$(RABBITMQ_COMPONENT_REPO_NAME).git 256 | RABBITMQ_UPSTREAM_PUSH_URL ?= git@github.com:rabbitmq/$(RABBITMQ_COMPONENT_REPO_NAME).git 257 | 258 | # Current URL for the current project. If this is not a Git clone, 259 | # default to the upstream Git repository. 260 | ifneq ($(wildcard .git),) 261 | git_origin_fetch_url := $(shell git config remote.origin.url) 262 | git_origin_push_url := $(shell git config remote.origin.pushurl || git config remote.origin.url) 263 | RABBITMQ_CURRENT_FETCH_URL ?= $(git_origin_fetch_url) 264 | RABBITMQ_CURRENT_PUSH_URL ?= $(git_origin_push_url) 265 | else 266 | RABBITMQ_CURRENT_FETCH_URL ?= $(RABBITMQ_UPSTREAM_FETCH_URL) 267 | RABBITMQ_CURRENT_PUSH_URL ?= $(RABBITMQ_UPSTREAM_PUSH_URL) 268 | endif 269 | 270 | # Macro to replace the following pattern: 271 | # 1. /foo.git -> /bar.git 272 | # 2. /foo -> /bar 273 | # 3. /foo/ -> /bar/ 274 | subst_repo_name = $(patsubst %/$(1)/%,%/$(2)/%,$(patsubst %/$(1),%/$(2),$(patsubst %/$(1).git,%/$(2).git,$(3)))) 275 | 276 | # Macro to replace both the project's name (eg. "rabbit_common") and 277 | # repository name (eg. "rabbitmq-common") by the target's equivalent. 278 | # 279 | # This macro is kept on one line because we don't want whitespaces in 280 | # the returned value, as it's used in $(dep_fetch_git_rmq) in a shell 281 | # single-quoted string. 282 | dep_rmq_repo = $(if $(dep_$(2)),$(call subst_repo_name,$(PROJECT),$(2),$(call subst_repo_name,$(RABBITMQ_COMPONENT_REPO_NAME),$(call rmq_cmp_repo_name,$(2)),$(1))),$(pkg_$(1)_repo)) 283 | 284 | dep_rmq_commits = $(if $(dep_$(1)), \ 285 | $(wordlist 3,$(words $(dep_$(1))),$(dep_$(1))), \ 286 | $(pkg_$(1)_commit)) 287 | 288 | define dep_fetch_git_rmq 289 | fetch_url1='$(call dep_rmq_repo,$(RABBITMQ_CURRENT_FETCH_URL),$(1))'; \ 290 | fetch_url2='$(call dep_rmq_repo,$(RABBITMQ_UPSTREAM_FETCH_URL),$(1))'; \ 291 | if test "$$$$fetch_url1" != '$(RABBITMQ_CURRENT_FETCH_URL)' && \ 292 | git clone -q -n -- "$$$$fetch_url1" $(DEPS_DIR)/$(call dep_name,$(1)); then \ 293 | fetch_url="$$$$fetch_url1"; \ 294 | push_url='$(call dep_rmq_repo,$(RABBITMQ_CURRENT_PUSH_URL),$(1))'; \ 295 | elif git clone -q -n -- "$$$$fetch_url2" $(DEPS_DIR)/$(call dep_name,$(1)); then \ 296 | fetch_url="$$$$fetch_url2"; \ 297 | push_url='$(call dep_rmq_repo,$(RABBITMQ_UPSTREAM_PUSH_URL),$(1))'; \ 298 | fi; \ 299 | cd $(DEPS_DIR)/$(call dep_name,$(1)) && ( \ 300 | $(foreach ref,$(call dep_rmq_commits,$(1)), \ 301 | git checkout -q $(ref) >/dev/null 2>&1 || \ 302 | ) \ 303 | (echo "error: no valid pathspec among: $(call dep_rmq_commits,$(1))" \ 304 | 1>&2 && false) ) && \ 305 | (test "$$$$fetch_url" = "$$$$push_url" || \ 306 | git remote set-url --push origin "$$$$push_url") 307 | endef 308 | 309 | define dep_fetch_git_rmq-subfolder 310 | fetch_url1='https://github.com/rabbitmq/rabbitmq-server.git'; \ 311 | fetch_url2='git@github.com:rabbitmq/rabbitmq-server.git'; \ 312 | if [ ! -d $(ERLANG_MK_TMP)/rabbitmq-server ]; then \ 313 | if test "$$$$fetch_url1" != '$(RABBITMQ_CURRENT_FETCH_URL)' && \ 314 | git clone -q -n -- "$$$$fetch_url1" $(ERLANG_MK_TMP)/rabbitmq-server; then \ 315 | fetch_url="$$$$fetch_url1"; \ 316 | push_url='$(call dep_rmq_repo,$(RABBITMQ_CURRENT_PUSH_URL),rabbitmq-server)'; \ 317 | elif git clone -q -n -- "$$$$fetch_url2" $(ERLANG_MK_TMP)/rabbitmq-server; then \ 318 | fetch_url="$$$$fetch_url2"; \ 319 | push_url='$(call dep_rmq_repo,$(RABBITMQ_UPSTREAM_PUSH_URL),rabbitmq-server)'; \ 320 | fi; \ 321 | fi; \ 322 | cd $(ERLANG_MK_TMP)/rabbitmq-server && ( \ 323 | $(foreach ref,$(call dep_rmq_commits,$(1)), \ 324 | git checkout -q $(ref) >/dev/null 2>&1 || \ 325 | ) \ 326 | (echo "error: no valid pathspec among: $(call dep_rmq_commits,$(1))" \ 327 | 1>&2 && false) ) && \ 328 | (test "$$$$fetch_url" = "$$$$push_url" || \ 329 | git remote set-url --push origin "$$$$push_url") 330 | ln -s $(ERLANG_MK_TMP)/rabbitmq-server/deps/$(call dep_name,$(1)) \ 331 | $(DEPS_DIR)/$(call dep_name,$(1)); 332 | endef 333 | 334 | # -------------------------------------------------------------------- 335 | # Component distribution. 336 | # -------------------------------------------------------------------- 337 | 338 | list-dist-deps:: 339 | @: 340 | 341 | prepare-dist:: 342 | @: 343 | 344 | # -------------------------------------------------------------------- 345 | # Umbrella-specific settings. 346 | # -------------------------------------------------------------------- 347 | 348 | # If the top-level project is a RabbitMQ component, we override 349 | # $(DEPS_DIR) for this project to point to the top-level's one. 350 | # 351 | # We also verify that the guessed DEPS_DIR is actually named `deps`, 352 | # to rule out any situation where it is a coincidence that we found a 353 | # `rabbitmq-components.mk` up upper directories. 354 | 355 | possible_deps_dir_1 = $(abspath ..) 356 | possible_deps_dir_2 = $(abspath ../../..) 357 | 358 | ifeq ($(notdir $(possible_deps_dir_1)),deps) 359 | ifneq ($(wildcard $(possible_deps_dir_1)/../rabbitmq-components.mk),) 360 | deps_dir_overriden = 1 361 | DEPS_DIR ?= $(possible_deps_dir_1) 362 | DISABLE_DISTCLEAN = 1 363 | endif 364 | endif 365 | 366 | ifeq ($(deps_dir_overriden),) 367 | ifeq ($(notdir $(possible_deps_dir_2)),deps) 368 | ifneq ($(wildcard $(possible_deps_dir_2)/../rabbitmq-components.mk),) 369 | deps_dir_overriden = 1 370 | DEPS_DIR ?= $(possible_deps_dir_2) 371 | DISABLE_DISTCLEAN = 1 372 | endif 373 | endif 374 | endif 375 | 376 | ifneq ($(wildcard UMBRELLA.md),) 377 | DISABLE_DISTCLEAN = 1 378 | endif 379 | 380 | # We disable `make distclean` so $(DEPS_DIR) is not accidentally removed. 381 | 382 | ifeq ($(DISABLE_DISTCLEAN),1) 383 | ifneq ($(filter distclean distclean-deps,$(MAKECMDGOALS)),) 384 | SKIP_DEPS = 1 385 | endif 386 | endif 387 | -------------------------------------------------------------------------------- /src/rabbit_timestamp_interceptor.erl: -------------------------------------------------------------------------------- 1 | %% This Source Code Form is subject to the terms of the Mozilla Public 2 | %% License, v. 2.0. If a copy of the MPL was not distributed with this 3 | %% file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | %% 5 | %% Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. 6 | %% 7 | 8 | -module(rabbit_timestamp_interceptor). 9 | 10 | -include_lib("rabbit_common/include/rabbit.hrl"). 11 | -include_lib("rabbit_common/include/rabbit_framing.hrl"). 12 | -include_lib("rabbit_message_timestamp.hrl"). 13 | 14 | -import(rabbit_basic, [header/2]). 15 | 16 | -behaviour(rabbit_channel_interceptor). 17 | 18 | -export([description/0, intercept/3, applies_to/0, init/1]). 19 | 20 | -rabbit_boot_step({?MODULE, 21 | [{description, "timestamp interceptor"}, 22 | {mfa, {rabbit_registry, register, 23 | [channel_interceptor, 24 | <<"timestamp interceptor">>, ?MODULE]}}, 25 | {cleanup, {rabbit_registry, unregister, 26 | [channel_interceptor, 27 | <<"timestamp interceptor">>]}}, 28 | {requires, rabbit_registry}, 29 | {enables, recovery}]}). 30 | 31 | init(_Ch) -> 32 | undefined. 33 | 34 | description() -> 35 | [{description, 36 | <<"Adds current timestamp to messages as they enter RabbitMQ">>}]. 37 | 38 | intercept(#'basic.publish'{} = Method, Content, _IState) -> 39 | OverwriteTimestamps = application:get_env(rabbitmq_message_timestamp, overwrite_timestamps, false), 40 | DecodedContent = rabbit_binary_parser:ensure_content_decoded(Content), 41 | Timestamp = os:system_time(seconds), 42 | TimestampMs = os:system_time(milli_seconds), 43 | Content2 = set_content_timestamp(DecodedContent, Timestamp, OverwriteTimestamps), 44 | Content3 = set_content_timestamp_millis(Content2, TimestampMs, OverwriteTimestamps), 45 | {Method, Content3}; 46 | 47 | intercept(Method, Content, _VHost) -> 48 | {Method, Content}. 49 | 50 | applies_to() -> 51 | ['basic.publish']. 52 | 53 | %%---------------------------------------------------------------------------- 54 | % OverwriteTimestamps = false, do not overwrite an existing timestamp 55 | set_content_timestamp(#content{properties = Props} = Content, _, false) 56 | when is_integer(Props#'P_basic'.timestamp) -> 57 | Content; 58 | % OverwriteTimestamps = true, overwrite an existing timestamp 59 | set_content_timestamp(#content{properties = Props0} = Content, Timestamp, true) 60 | when is_integer(Props0#'P_basic'.timestamp) -> 61 | set_content_timestamp(Content, Timestamp); 62 | set_content_timestamp(#content{properties = Props} = Content, Timestamp, _) 63 | when Props#'P_basic'.timestamp == undefined -> 64 | set_content_timestamp(Content, Timestamp). 65 | 66 | set_content_timestamp_millis(#content{properties = #'P_basic'{headers = Headers}} = Content, TimestampMs, OverwriteTimestamps) -> 67 | case {OverwriteTimestamps, header(?TIMESTAMP_IN_MS, Headers)} of 68 | {true, _} -> 69 | %% Overwrite or set a timestamp_in_ms header 70 | set_content_timestamp_header(Content, TimestampMs); 71 | {_, undefined} -> 72 | %% No timestamp_in_ms header, so add one 73 | set_content_timestamp_header(Content, TimestampMs); 74 | _ -> 75 | %% Do not overwrite an existing timestamp_in_ms header 76 | Content 77 | end. 78 | 79 | add_header(undefined, Header) -> [Header]; 80 | add_header(Headers, Header) -> 81 | lists:keystore(element(1, Header), 1, Headers, Header). 82 | 83 | set_content_timestamp(#content{properties = Props0} = Content, Timestamp) -> 84 | %% we need to reset properties_bin = none so the new properties 85 | %% get serialized when delivering the message. 86 | Props1 = Props0#'P_basic'{timestamp = Timestamp}, 87 | Content#content{properties = Props1, properties_bin = none}. 88 | 89 | set_content_timestamp_header(#content{properties = #'P_basic'{headers = Headers0} = Props0} = Content, TimestampMs) -> 90 | Headers1 = add_header(Headers0, {?TIMESTAMP_IN_MS, long, TimestampMs}), 91 | Props1 = Props0#'P_basic'{headers = Headers1}, 92 | Content#content{properties = Props1, properties_bin = none}. 93 | -------------------------------------------------------------------------------- /test/rabbit_message_timestamp_SUITE.erl: -------------------------------------------------------------------------------- 1 | %% This Source Code Form is subject to the terms of the Mozilla Public 2 | %% License, v. 2.0. If a copy of the MPL was not distributed with this 3 | %% file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 | %% 5 | %% Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. 6 | %% 7 | 8 | -module(rabbit_message_timestamp_SUITE). 9 | 10 | -compile(export_all). 11 | 12 | -include_lib("common_test/include/ct.hrl"). 13 | -include_lib("eunit/include/eunit.hrl"). 14 | -include_lib("amqp_client/include/amqp_client.hrl"). 15 | -include_lib("rabbit_message_timestamp.hrl"). 16 | 17 | -define(SEND_DELAY, 1000). 18 | 19 | all() -> 20 | [ 21 | {group, non_parallel_tests} 22 | ]. 23 | 24 | groups() -> 25 | [ 26 | {non_parallel_tests, [], [ 27 | timestamp_test, 28 | existing_timestamp_test 29 | ]} 30 | ]. 31 | 32 | %% ------------------------------------------------------------------- 33 | %% Testsuite setup/teardown. 34 | %% ------------------------------------------------------------------- 35 | 36 | init_per_suite(Config) -> 37 | rabbit_ct_helpers:log_environment(), 38 | Config1 = rabbit_ct_helpers:set_config(Config, [ 39 | {rmq_nodename_suffix, ?MODULE} 40 | ]), 41 | rabbit_ct_helpers:run_setup_steps(Config1, 42 | rabbit_ct_broker_helpers:setup_steps() ++ 43 | rabbit_ct_client_helpers:setup_steps()). 44 | 45 | end_per_suite(Config) -> 46 | rabbit_ct_helpers:run_teardown_steps(Config, 47 | rabbit_ct_client_helpers:teardown_steps() ++ 48 | rabbit_ct_broker_helpers:teardown_steps()). 49 | 50 | init_per_group(_, Config) -> 51 | Config. 52 | 53 | end_per_group(_, Config) -> 54 | Config. 55 | 56 | init_per_testcase(Testcase, Config) -> 57 | rabbit_ct_helpers:testcase_started(Config, Testcase). 58 | 59 | end_per_testcase(Testcase, Config) -> 60 | rabbit_ct_helpers:testcase_finished(Config, Testcase). 61 | 62 | %% ------------------------------------------------------------------- 63 | %% Testcases. 64 | %% ------------------------------------------------------------------- 65 | 66 | timestamp_test(Config) -> 67 | Chan = rabbit_ct_client_helpers:open_channel(Config, 0), 68 | 69 | Ex = <<"e1">>, 70 | Q = <<"q">>, 71 | 72 | setup_fabric(Chan, make_exchange(Ex, <<"direct">>), make_queue(Q)), 73 | 74 | Msgs = [1, 2, 3, 4, 5], 75 | 76 | amqp_channel:call(Chan, #'confirm.select'{}), 77 | 78 | publish_messages(Chan, Ex, Msgs), 79 | 80 | amqp_channel:wait_for_confirms_or_die(Chan), 81 | 82 | {ok, Result} = consume(Chan, Q, Msgs, 5000), 83 | 84 | [begin 85 | ?assertNotEqual(get_timestamp(Msg), undefined), 86 | ?assert(is_integer(get_timestamp(Msg))), 87 | ?assert(get_timestamp(Msg) > 0), 88 | ?assertNotEqual(get_single_header(?TIMESTAMP_IN_MS, Msg), false), 89 | ?assert(get_single_header(?TIMESTAMP_IN_MS, Msg) > 0) 90 | end|| Msg <- Result], 91 | 92 | amqp_channel:call(Chan, delete_queue(Q)), 93 | amqp_channel:call(Chan, delete_exchange(Ex)), 94 | 95 | rabbit_ct_client_helpers:close_channel(Chan), 96 | passed. 97 | 98 | existing_timestamp_test(Config) -> 99 | Chan = rabbit_ct_client_helpers:open_channel(Config, 0), 100 | 101 | Ex = <<"e1">>, 102 | Q = <<"q">>, 103 | 104 | setup_fabric(Chan, make_exchange(Ex, <<"direct">>), make_queue(Q)), 105 | 106 | Msgs = [1, 2, 3, 4, 5], 107 | Now = os:system_time(seconds), 108 | Timestamps = lists:duplicate(length(Msgs), Now), 109 | 110 | % Timestamps are in seconds, so we wait a short period before sending 111 | % the message to ensure that the timestamps above will be different 112 | % from the ones the interceptor tries to set. 113 | timer:sleep(?SEND_DELAY), 114 | 115 | amqp_channel:call(Chan, #'confirm.select'{}), 116 | 117 | publish_timestamped_messages(Chan, Ex, Msgs, Timestamps), 118 | 119 | amqp_channel:wait_for_confirms_or_die(Chan), 120 | 121 | {ok, Result} = consume(Chan, Q, Msgs, 5000), 122 | 123 | [begin 124 | ?assertNotEqual(get_timestamp(Msg), undefined), 125 | ?assert(is_integer(get_timestamp(Msg))), 126 | ?assert(get_timestamp(Msg) =:= Now) 127 | end|| Msg <- Result], 128 | 129 | amqp_channel:call(Chan, delete_queue(Q)), 130 | amqp_channel:call(Chan, delete_exchange(Ex)), 131 | 132 | rabbit_ct_client_helpers:close_channel(Chan), 133 | passed. 134 | 135 | 136 | %% ------------------------------------------------------------------- 137 | %% Implementation. 138 | %% ------------------------------------------------------------------- 139 | 140 | get_payload(#amqp_msg{payload = P}) -> 141 | binary_to_term(P). 142 | 143 | get_timestamp(#amqp_msg{props = #'P_basic'{timestamp = T}}) -> 144 | T. 145 | 146 | get_single_header(Target, 147 | #amqp_msg{props = #'P_basic'{headers = Headers}}) -> 148 | lists:keyfind(Target, 1, Headers). 149 | 150 | setup_fabric(Chan, ExDeclare, QueueDeclare) -> 151 | setup_fabric(Chan, ExDeclare, QueueDeclare, <<>>). 152 | 153 | setup_fabric(Chan, 154 | ExDeclare = #'exchange.declare'{exchange = Ex}, 155 | QueueDeclare, 156 | RK) -> 157 | declare_exchange(Chan, ExDeclare), 158 | 159 | #'queue.declare_ok'{queue = Q} = 160 | amqp_channel:call(Chan, QueueDeclare), 161 | 162 | #'queue.bind_ok'{} = 163 | amqp_channel:call(Chan, #'queue.bind' { 164 | queue = Q, 165 | exchange = Ex, 166 | routing_key = RK 167 | }). 168 | 169 | declare_exchange(Chan, ExDeclare) -> 170 | #'exchange.declare_ok'{} = 171 | amqp_channel:call(Chan, ExDeclare). 172 | 173 | publish_messages(Chan, Ex, Msgs) -> 174 | publish_messages(Chan, Ex, <<>>, Msgs). 175 | 176 | publish_messages(Chan, Ex, RK, Msgs) -> 177 | [amqp_channel:call(Chan, 178 | #'basic.publish'{exchange = Ex, 179 | routing_key = RK}, 180 | make_msg(V)) || V <- Msgs]. 181 | 182 | publish_timestamped_messages(Chan, Ex, Msgs, Timestamps) -> 183 | publish_timestamped_messages(Chan, Ex, <<>>, Msgs, Timestamps). 184 | 185 | publish_timestamped_messages(Chan, Ex, RK, Msgs, Timestamps) -> 186 | [amqp_channel:call(Chan, 187 | #'basic.publish'{exchange = Ex, 188 | routing_key = RK}, 189 | make_timestamped_msg(V,T)) || 190 | {V,T} <- lists:zip(Msgs, Timestamps)]. 191 | 192 | consume(Chan, Q, Msgs, Timeout) -> 193 | #'basic.consume_ok'{} = 194 | amqp_channel:subscribe(Chan, #'basic.consume'{queue = Q, 195 | no_ack = true}, self()), 196 | collect(length(Msgs), Timeout). 197 | 198 | 199 | collect(N, Timeout) -> 200 | collect(0, N, Timeout, []). 201 | 202 | collect(N, N, _Timeout, Acc) -> 203 | {ok, lists:reverse(Acc)}; 204 | collect(Curr, N, Timeout, Acc) -> 205 | receive {#'basic.deliver'{}, 206 | Msg = #amqp_msg{}} -> 207 | collect(Curr+1, N, Timeout, [Msg | Acc]) 208 | after Timeout -> 209 | {error, {timeout, Acc}} 210 | end. 211 | 212 | delete_exchange(Ex) -> 213 | #'exchange.delete' { 214 | exchange = Ex 215 | }. 216 | 217 | delete_queue(Q) -> 218 | #'queue.delete' { 219 | queue = Q 220 | }. 221 | 222 | make_queue(Q) -> 223 | #'queue.declare' { 224 | queue = Q 225 | }. 226 | 227 | make_exchange(Ex, Type) -> 228 | #'exchange.declare'{ 229 | exchange = Ex, 230 | type = Type 231 | }. 232 | 233 | make_msg(V) -> 234 | #amqp_msg{payload = term_to_binary(V)}. 235 | 236 | make_timestamped_msg(V,T) -> 237 | #amqp_msg{ 238 | props = #'P_basic'{timestamp = T}, 239 | payload = term_to_binary(V) 240 | }. 241 | --------------------------------------------------------------------------------