├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS ├── Gemfile ├── LICENSE ├── NOTICE.TXT ├── README.md ├── Rakefile ├── ci ├── build.sh ├── run.sh └── setup.sh ├── docs └── index.asciidoc ├── examples └── sample.conf ├── lib └── logstash │ └── outputs │ └── rabbitmq.rb ├── logstash-output-rabbitmq.gemspec └── spec └── outputs └── rabbitmq_spec.rb /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Logstash 2 | 3 | All contributions are welcome: ideas, patches, documentation, bug reports, 4 | complaints, etc! 5 | 6 | Programming is not a required skill, and there are many ways to help out! 7 | It is more important to us that you are able to contribute. 8 | 9 | That said, some basic guidelines, which you are free to ignore :) 10 | 11 | ## Want to learn? 12 | 13 | Want to lurk about and see what others are doing with Logstash? 14 | 15 | * The irc channel (#logstash on irc.freenode.org) is a good place for this 16 | * The [forum](https://discuss.elastic.co/c/logstash) is also 17 | great for learning from others. 18 | 19 | ## Got Questions? 20 | 21 | Have a problem you want Logstash to solve for you? 22 | 23 | * You can ask a question in the [forum](https://discuss.elastic.co/c/logstash) 24 | * Alternately, you are welcome to join the IRC channel #logstash on 25 | irc.freenode.org and ask for help there! 26 | 27 | ## Have an Idea or Feature Request? 28 | 29 | * File a ticket on [GitHub](https://github.com/elastic/logstash/issues). Please remember that GitHub is used only for issues and feature requests. If you have a general question, the [forum](https://discuss.elastic.co/c/logstash) or IRC would be the best place to ask. 30 | 31 | ## Something Not Working? Found a Bug? 32 | 33 | If you think you found a bug, it probably is a bug. 34 | 35 | * If it is a general Logstash or a pipeline issue, file it in [Logstash GitHub](https://github.com/elasticsearch/logstash/issues) 36 | * If it is specific to a plugin, please file it in the respective repository under [logstash-plugins](https://github.com/logstash-plugins) 37 | * or ask the [forum](https://discuss.elastic.co/c/logstash). 38 | 39 | # Contributing Documentation and Code Changes 40 | 41 | If you have a bugfix or new feature that you would like to contribute to 42 | logstash, and you think it will take more than a few minutes to produce the fix 43 | (ie; write code), it is worth discussing the change with the Logstash users and developers first! You can reach us via [GitHub](https://github.com/elastic/logstash/issues), the [forum](https://discuss.elastic.co/c/logstash), or via IRC (#logstash on freenode irc) 44 | Please note that Pull Requests without tests will not be merged. If you would like to contribute but do not have experience with writing tests, please ping us on IRC/forum or create a PR and ask our help. 45 | 46 | ## Contributing to plugins 47 | 48 | Check our [documentation](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html) on how to contribute to plugins or write your own! It is super easy! 49 | 50 | ## Contribution Steps 51 | 52 | 1. Test your changes! [Run](https://github.com/elastic/logstash#testing) the test suite 53 | 2. Please make sure you have signed our [Contributor License 54 | Agreement](https://www.elastic.co/contributor-agreement/). We are not 55 | asking you to assign copyright to us, but to give us the right to distribute 56 | your code without restriction. We ask this of all contributors in order to 57 | assure our users of the origin and continuing existence of the code. You 58 | only need to sign the CLA once. 59 | 3. Send a pull request! Push your changes to your fork of the repository and 60 | [submit a pull 61 | request](https://help.github.com/articles/using-pull-requests). In the pull 62 | request, describe what your changes do and mention any bugs/issues related 63 | to the pull request. 64 | 65 | 66 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## RabbitMQ Output Plugin's Issue Tracker Has Moved 2 | 3 | This RabbitMQ Output Plugin is now a part of the [RabbitMQ Integration Plugin][integration-source]; 4 | this project remains open for backports of fixes from that project to the 5.x series where possible, but issues should first be filed on the [integration plugin][integration-issues]. 5 | 6 | Please post all product and debugging questions on our [forum][logstash-forum]. 7 | Your questions will reach our wider community members there, and if we confirm that there is a bug, then we can open a new issue on the appropriate project. 8 | 9 | [integration-source]: https://github.com/logstash-plugins/logstash-integration-rabbitmq 10 | [integration-issues]: https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/ 11 | [logstash-forum]: https://discuss.elastic.co/c/logstash -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## RabbitMQ Output Plugin's Source Has Moved 2 | 3 | This RabbitMQ Output Plugin is now a part of the [RabbitMQ Integration Plugin][integration-source]; 4 | this project remains open for backports of fixes from that project to the 6.x series where possible, but pull-requests should first be made on the [integration plugin][integration-pull-requests]. 5 | 6 | If you have already made commits on a clone of this stand-alone repository, it's ok! Go ahead and open the Pull Request here, and open an Issue linking to it on the [integration plugin][integration-issues] -- we'll work with you to sort it all out and to get the backport applied. 7 | 8 | ## Contributor Agreement 9 | 10 | Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/ 11 | 12 | [integration-source]: https://github.com/logstash-plugins/logstash-integration-rabbitmq 13 | [integration-issues]: https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/ 14 | [integration-pull-requests]: https://github.com/logstash-plugins/logstash-integration-rabbitmq/pulls 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .bundle 4 | vendor 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: false 3 | services: 4 | - rabbitmq 5 | language: ruby 6 | cache: bundler 7 | matrix: 8 | include: 9 | - rvm: jruby-9.1.13.0 10 | env: LOGSTASH_BRANCH=master 11 | - rvm: jruby-9.1.13.0 12 | env: LOGSTASH_BRANCH=7.0 13 | - rvm: jruby-9.1.13.0 14 | env: LOGSTASH_BRANCH=6.7 15 | - rvm: jruby-9.1.13.0 16 | env: LOGSTASH_BRANCH=6.6 17 | - rvm: jruby-1.7.27 18 | env: LOGSTASH_BRANCH=5.6 19 | fast_finish: true 20 | install: true 21 | script: ci/build.sh 22 | jdk: openjdk8 23 | before_install: gem install bundler -v '< 2' 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 5.1.1 2 | - Docs: Set the default_codec doc attribute. 3 | 4 | ## 5.1.0 5 | _ Use shared concurrency / multiple channels for performance 6 | 7 | ## 5.0.3 8 | - Update gemspec summary 9 | 10 | ## 5.0.2 11 | - Docs: Fix broken link 12 | 13 | ## 5.0.1 14 | - Fix some documentation issues 15 | 16 | ## 5.0.0 17 | - Require v5.0.0 of rabbitmq-connection_mixin which obsoletes some deprecated options 18 | 19 | ## 4.0.9 20 | - Support per-message properties 21 | 22 | ## 4.0.7 23 | - Require v4.3.0 of rabbitmq-connection_mixin which bumps the major version of the java rabbitmq lib 24 | 25 | ## 4.0.6 26 | - Bump rabbitmq connection to fix LongString type usage 27 | 28 | ## 4.0.5 29 | - Fix broken tests due to latest logstash-output-rabbitmq_connection 30 | 31 | ## 4.0.4 32 | - Depend on latest RMQ connection which retries on connection exception 33 | 34 | ## 4.0.3 35 | - Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99 36 | 37 | ## 4.0.2 38 | - Depend on latest RMQ connection with TLS improvements 39 | 40 | ## 4.0.1 41 | - Republish all the gems under jruby. 42 | ## 4.0.0 43 | - Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141 44 | # 3.0.9 45 | - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash 46 | # 3.0.8 47 | - New dependency requirements for logstash-core for the 5.0 release 48 | ## 3.0.7 49 | - Bump rabbitmq_connection version to use newer march hare gem and fix perms issues 50 | 51 | ## 3.0.6 52 | - Set codec to JSON if none specified to recreate old behavior 53 | 54 | ## 3.0.5 55 | - Fix broken registration of plugin 56 | 57 | ## 3.0.3 58 | - Bump dependency on logstash-mixin-rabbitmq_connection 59 | 60 | ## 3.0.0 61 | - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully, 62 | instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 63 | - Dependency on logstash-core update to 2.0 64 | 65 | * 2.0.0 66 | - Massive refactor 67 | - Implement Logstash 2.x stop behavior 68 | - Depend on rabbitmq_connection mixin for most connection functionality 69 | * 1.1.2 70 | - Bump march_hare to 2.12.0 to fix jar file permissions 71 | * 1.1.1 72 | - Fix nasty bug that caused connection duplication on conn recovery 73 | * 1.1.0 74 | - Many internal refactors 75 | - Bump march hare version to 2.11.0 76 | * 1.0.1 77 | - Fix connection leakage/failure to reconnect on disconnect 78 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | The following is a list of people who have contributed ideas, code, bug 2 | reports, or in general have helped logstash along its way. 3 | 4 | Contributors: 5 | * Colin Surprenant (colinsurprenant) 6 | * Jordan Sissel (jordansissel) 7 | * João Duarte (jsvd) 8 | * Kurt Hurtado (kurtado) 9 | * Marc Fournier (mfournier) 10 | * Mathieu MILLET (htam-net) 11 | * Michael Klishin (michaelklishin) 12 | * Michael Zaccari (mzaccari) 13 | * Pier-Hugues Pellerin (ph) 14 | * Richard Pijnenburg (electrical) 15 | * avleen 16 | * ssc- 17 | 18 | Note: If you've sent us patches, bug reports, or otherwise contributed to 19 | Logstash, and you aren't on the list above and want to be, please let us know 20 | and we'll make sure you're here. Contributions from folks like you are what make 21 | open source awesome. 22 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash" 6 | use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1" 7 | 8 | if Dir.exist?(logstash_path) && use_logstash_source 9 | gem 'logstash-core', :path => "#{logstash_path}/logstash-core" 10 | gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api" 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2020 Elastic and contributors 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE.TXT: -------------------------------------------------------------------------------- 1 | Elasticsearch 2 | Copyright 2012-2015 Elasticsearch 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About this plugin 2 | 3 | [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-output-rabbitmq.svg)](https://travis-ci.com/logstash-plugins/logstash-output-rabbitmq) 4 | 5 | This is a plugin for [Logstash](https://github.com/elastic/logstash). 6 | 7 | It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way. 8 | 9 | 10 | ## RabbitMQ Output Plugin Has Moved 11 | 12 | This RabbitMQ Output Plugin is now a part of the [RabbitMQ Integration Plugin][integration-source]; 13 | this project remains open for backports of fixes from that project to the 5.x series where possible, but issues should first be filed on the [integration plugin][integration-issues]. 14 | 15 | [integration-source]: https://github.com/logstash-plugins/logstash-integration-rabbitmq 16 | [integration-issues]: https://github.com/logstash-plugins/logstash-integration-rabbitmq/issues/ 17 | 18 | ## Documentation 19 | 20 | Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/). 21 | 22 | - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive 23 | - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide 24 | 25 | ## Need Help? 26 | 27 | Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum. 28 | 29 | ## Developing 30 | 31 | ### 1. Plugin Developement and Testing 32 | 33 | #### Code 34 | - To get started, you'll need JRuby with the Bundler gem installed. 35 | 36 | - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example). 37 | 38 | - Install dependencies 39 | ```sh 40 | bundle install 41 | ``` 42 | 43 | #### Test 44 | 45 | - Update your dependencies 46 | 47 | ```sh 48 | bundle install 49 | ``` 50 | 51 | - Run tests 52 | 53 | ```sh 54 | bundle exec rspec 55 | ``` 56 | 57 | ### 2. Running your unpublished Plugin in Logstash 58 | 59 | #### 2.1 Run in a local Logstash clone 60 | 61 | - Edit Logstash `Gemfile` and add the local plugin path, for example: 62 | ```ruby 63 | gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" 64 | ``` 65 | - Install plugin 66 | ```sh 67 | # Logstash 2.3 and higher 68 | bin/logstash-plugin install --no-verify 69 | 70 | # Prior to Logstash 2.3 71 | bin/plugin install --no-verify 72 | 73 | ``` 74 | - Run Logstash with your plugin 75 | ```sh 76 | bin/logstash -e 'filter {awesome {}}' 77 | ``` 78 | At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. 79 | 80 | #### 2.2 Run in an installed Logstash 81 | 82 | You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using: 83 | 84 | - Build your plugin gem 85 | ```sh 86 | gem build logstash-filter-awesome.gemspec 87 | ``` 88 | - Install the plugin from the Logstash home 89 | ```sh 90 | # Logstash 2.3 and higher 91 | bin/logstash-plugin install --no-verify 92 | 93 | # Prior to Logstash 2.3 94 | bin/plugin install --no-verify 95 | 96 | ``` 97 | - Start Logstash and proceed to test the plugin 98 | 99 | ## Contributing 100 | 101 | All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. 102 | 103 | Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here. 104 | 105 | It is more important to the community that you are able to contribute. 106 | 107 | For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. 108 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | @files=[] 2 | 3 | task :default do 4 | system("rake -T") 5 | end 6 | 7 | require "logstash/devutils/rake" 8 | -------------------------------------------------------------------------------- /ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # version: 1 3 | ######################################################## 4 | # 5 | # AUTOMATICALLY GENERATED! DO NOT EDIT 6 | # 7 | ######################################################## 8 | set -e 9 | 10 | echo "Starting build process in: `pwd`" 11 | source ./ci/setup.sh 12 | 13 | if [[ -f "ci/run.sh" ]]; then 14 | echo "Running custom build script in: `pwd`/ci/run.sh" 15 | source ./ci/run.sh 16 | else 17 | echo "Running default build scripts in: `pwd`/ci/build.sh" 18 | bundle install 19 | bundle exec rake vendor 20 | bundle exec rspec spec 21 | fi 22 | -------------------------------------------------------------------------------- /ci/run.sh: -------------------------------------------------------------------------------- 1 | bundle install 2 | bundle exec rspec spec && bundle exec rspec spec --tag integration 3 | -------------------------------------------------------------------------------- /ci/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # version: 1 3 | ######################################################## 4 | # 5 | # AUTOMATICALLY GENERATED! DO NOT EDIT 6 | # 7 | ######################################################## 8 | set -e 9 | if [ "$LOGSTASH_BRANCH" ]; then 10 | echo "Building plugin using Logstash source" 11 | BASE_DIR=`pwd` 12 | echo "Checking out branch: $LOGSTASH_BRANCH" 13 | git clone -b $LOGSTASH_BRANCH https://github.com/elastic/logstash.git ../../logstash --depth 1 14 | printf "Checked out Logstash revision: %s\n" "$(git -C ../../logstash rev-parse HEAD)" 15 | cd ../../logstash 16 | echo "Building plugins with Logstash version:" 17 | cat versions.yml 18 | echo "---" 19 | # We need to build the jars for that specific version 20 | echo "Running gradle assemble in: `pwd`" 21 | ./gradlew assemble 22 | cd $BASE_DIR 23 | export LOGSTASH_SOURCE=1 24 | else 25 | echo "Building plugin using released gems on rubygems" 26 | fi 27 | -------------------------------------------------------------------------------- /docs/index.asciidoc: -------------------------------------------------------------------------------- 1 | :plugin: rabbitmq 2 | :type: output 3 | :default_codec: json 4 | 5 | ///////////////////////////////////////////// 6 | // RabbitMQ Output Plugin Source Has Moved // 7 | // ---------------------------------------- // 8 | // The RabbitMQ Output Plugin is now a part // 9 | // of the RabbitMQ Integration. // 10 | // // 11 | // This stand-alone plugin project remains // 12 | // open for backports to the 5.x series. // 13 | ////////////////////////////////////////////// 14 | 15 | /////////////////////////////////////////// 16 | START - GENERATED VARIABLES, DO NOT EDIT! 17 | /////////////////////////////////////////// 18 | :version: %VERSION% 19 | :release_date: %RELEASE_DATE% 20 | :changelog_url: %CHANGELOG_URL% 21 | :include_path: ../../../../logstash/docs/include 22 | /////////////////////////////////////////// 23 | END - GENERATED VARIABLES, DO NOT EDIT! 24 | /////////////////////////////////////////// 25 | 26 | [id="plugins-{type}s-{plugin}"] 27 | 28 | === Rabbitmq output plugin 29 | 30 | include::{include_path}/plugin_header.asciidoc[] 31 | 32 | ==== Description 33 | 34 | Push events to a RabbitMQ exchange. Requires RabbitMQ 2.x 35 | or later version (3.x is recommended). 36 | 37 | Relevant links: 38 | 39 | * http://www.rabbitmq.com/[RabbitMQ] 40 | * http://rubymarchhare.info[March Hare] 41 | 42 | [id="plugins-{type}s-{plugin}-options"] 43 | ==== Rabbitmq Output Configuration Options 44 | 45 | This plugin supports the following configuration options plus the <> described later. 46 | 47 | [cols="<,<,<",options="header",] 48 | |======================================================================= 49 | |Setting |Input type|Required 50 | | <> |<>|No 51 | | <> |<>|No 52 | | <> |<>|No 53 | | <> |<>|No 54 | | <> |<>|No 55 | | <> |<>|Yes 56 | | <> |<>, one of `["fanout", "direct", "topic", "x-consistent-hash", "x-modulus-hash"]`|Yes 57 | | <> |<>|No 58 | | <> |<>|Yes 59 | | <> |<>|No 60 | | <> |<>|No 61 | | <> |<>|No 62 | | <> |<>|No 63 | | <> |<>|No 64 | | <> |<>|No 65 | | <> |<>|No 66 | | <> |<>|No 67 | | <> |a valid filesystem path|No 68 | | <> |<>|No 69 | | <> |<>|No 70 | | <> |<>|No 71 | |======================================================================= 72 | 73 | Also see <> for a list of options supported by all 74 | output plugins. 75 | 76 |   77 | 78 | [id="plugins-{type}s-{plugin}-arguments"] 79 | ===== `arguments` 80 | 81 | * Value type is <> 82 | * Default value is `{}` 83 | 84 | Extra queue arguments as an array. 85 | To make a RabbitMQ queue mirrored, use: `{"x-ha-policy" => "all"}` 86 | 87 | [id="plugins-{type}s-{plugin}-automatic_recovery"] 88 | ===== `automatic_recovery` 89 | 90 | * Value type is <> 91 | * Default value is `true` 92 | 93 | Set this to automatically recover from a broken connection. You almost certainly don't want to override this!!! 94 | 95 | [id="plugins-{type}s-{plugin}-connect_retry_interval"] 96 | ===== `connect_retry_interval` 97 | 98 | * Value type is <> 99 | * Default value is `1` 100 | 101 | Time in seconds to wait before retrying a connection 102 | 103 | [id="plugins-{type}s-{plugin}-connection_timeout"] 104 | ===== `connection_timeout` 105 | 106 | * Value type is <> 107 | * There is no default value for this setting. 108 | 109 | The default connection timeout in milliseconds. If not specified the timeout is infinite. 110 | 111 | [id="plugins-{type}s-{plugin}-durable"] 112 | ===== `durable` 113 | 114 | * Value type is <> 115 | * Default value is `true` 116 | 117 | Is this exchange durable? (aka; Should it survive a broker restart?) 118 | 119 | [id="plugins-{type}s-{plugin}-exchange"] 120 | ===== `exchange` 121 | 122 | * This is a required setting. 123 | * Value type is <> 124 | * There is no default value for this setting. 125 | 126 | The name of the exchange 127 | 128 | [id="plugins-{type}s-{plugin}-exchange_type"] 129 | ===== `exchange_type` 130 | 131 | * This is a required setting. 132 | * Value can be any of: `fanout`, `direct`, `topic`, `x-consistent-hash`, `x-modulus-hash` 133 | * There is no default value for this setting. 134 | 135 | The exchange type (fanout, topic, direct) 136 | 137 | [id="plugins-{type}s-{plugin}-heartbeat"] 138 | ===== `heartbeat` 139 | 140 | * Value type is <> 141 | * There is no default value for this setting. 142 | 143 | Heartbeat delay in seconds. If unspecified no heartbeats will be sent 144 | 145 | [id="plugins-{type}s-{plugin}-host"] 146 | ===== `host` 147 | 148 | * This is a required setting. 149 | * Value type is <> 150 | * There is no default value for this setting. 151 | 152 | Common functionality for the rabbitmq input/output 153 | RabbitMQ server address(es) 154 | host can either be a single host, or a list of hosts 155 | i.e. 156 | host => "localhost" 157 | or 158 | host => ["host01", "host02] 159 | 160 | if multiple hosts are provided on the initial connection and any subsequent 161 | recovery attempts of the hosts is chosen at random and connected to. 162 | Note that only one host connection is active at a time. 163 | 164 | [id="plugins-{type}s-{plugin}-key"] 165 | ===== `key` 166 | 167 | * Value type is <> 168 | * Default value is `"logstash"` 169 | 170 | The default codec for this plugin is JSON. You can override this to suit your particular needs however. 171 | Key to route to by default. Defaults to 'logstash' 172 | 173 | * Routing keys are ignored on fanout exchanges. 174 | 175 | [id="plugins-{type}s-{plugin}-message_properties"] 176 | ===== `message_properties` 177 | 178 | * Value type is <> 179 | * Default value is `{}` 180 | 181 | Add properties to be set per-message here, such as 'content_type', 'priority' 182 | 183 | Example: 184 | [source,ruby] 185 | message_properties => { 186 | "content_type" => "application/json" 187 | "priority" => 1 188 | } 189 | 190 | 191 | [id="plugins-{type}s-{plugin}-passive"] 192 | ===== `passive` 193 | 194 | * Value type is <> 195 | * Default value is `false` 196 | 197 | Passive queue creation? Useful for checking queue existance without modifying server state 198 | 199 | [id="plugins-{type}s-{plugin}-password"] 200 | ===== `password` 201 | 202 | * Value type is <> 203 | * Default value is `"guest"` 204 | 205 | RabbitMQ password 206 | 207 | [id="plugins-{type}s-{plugin}-persistent"] 208 | ===== `persistent` 209 | 210 | * Value type is <> 211 | * Default value is `true` 212 | 213 | Should RabbitMQ persist messages to disk? 214 | 215 | [id="plugins-{type}s-{plugin}-port"] 216 | ===== `port` 217 | 218 | * Value type is <> 219 | * Default value is `5672` 220 | 221 | RabbitMQ port to connect on 222 | 223 | [id="plugins-{type}s-{plugin}-ssl"] 224 | ===== `ssl` 225 | 226 | * Value type is <> 227 | * There is no default value for this setting. 228 | 229 | Enable or disable SSL. 230 | Note that by default remote certificate verification is off. 231 | Specify ssl_certificate_path and ssl_certificate_password if you need 232 | certificate verification 233 | 234 | [id="plugins-{type}s-{plugin}-ssl_certificate_password"] 235 | ===== `ssl_certificate_password` 236 | 237 | * Value type is <> 238 | * There is no default value for this setting. 239 | 240 | Password for the encrypted PKCS12 (.p12) certificate file specified in ssl_certificate_path 241 | 242 | [id="plugins-{type}s-{plugin}-ssl_certificate_path"] 243 | ===== `ssl_certificate_path` 244 | 245 | * Value type is <> 246 | * There is no default value for this setting. 247 | 248 | Path to an SSL certificate in PKCS12 (.p12) format used for verifying the remote host 249 | 250 | [id="plugins-{type}s-{plugin}-ssl_version"] 251 | ===== `ssl_version` 252 | 253 | * Value type is <> 254 | * Default value is `"TLSv1.2"` 255 | 256 | Version of the SSL protocol to use. 257 | 258 | [id="plugins-{type}s-{plugin}-user"] 259 | ===== `user` 260 | 261 | * Value type is <> 262 | * Default value is `"guest"` 263 | 264 | RabbitMQ username 265 | 266 | [id="plugins-{type}s-{plugin}-vhost"] 267 | ===== `vhost` 268 | 269 | * Value type is <> 270 | * Default value is `"/"` 271 | 272 | The vhost (virtual host) to use. If you don't know what this 273 | is, leave the default. With the exception of the default 274 | vhost ("/"), names of vhosts should not begin with a forward 275 | slash. 276 | 277 | 278 | 279 | [id="plugins-{type}s-{plugin}-common-options"] 280 | include::{include_path}/{type}.asciidoc[] 281 | 282 | :default_codec!: 283 | -------------------------------------------------------------------------------- /examples/sample.conf: -------------------------------------------------------------------------------- 1 | input { 2 | stdin {} 3 | } 4 | 5 | output { 6 | rabbitmq { 7 | host => "127.0.0.1" 8 | exchange => "foo" 9 | exchange_type => "topic" 10 | } 11 | } -------------------------------------------------------------------------------- /lib/logstash/outputs/rabbitmq.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require "logstash/pipeline" 3 | require "logstash/plugin_mixins/rabbitmq_connection" 4 | java_import java.util.concurrent.TimeoutException 5 | java_import com.rabbitmq.client.AlreadyClosedException 6 | 7 | # Push events to a RabbitMQ exchange. Requires RabbitMQ 2.x 8 | # or later version (3.x is recommended). 9 | # 10 | # Relevant links: 11 | # 12 | # * http://www.rabbitmq.com/[RabbitMQ] 13 | # * http://rubymarchhare.info[March Hare] 14 | module LogStash 15 | module Outputs 16 | class RabbitMQ < LogStash::Outputs::Base 17 | include LogStash::PluginMixins::RabbitMQConnection 18 | 19 | config_name "rabbitmq" 20 | 21 | concurrency :shared 22 | 23 | # The default codec for this plugin is JSON. You can override this to suit your particular needs however. 24 | default :codec, "json" 25 | 26 | # Key to route to by default. Defaults to 'logstash' 27 | # 28 | # * Routing keys are ignored on fanout exchanges. 29 | config :key, :validate => :string, :default => "logstash" 30 | 31 | # The name of the exchange 32 | config :exchange, :validate => :string, :required => true 33 | 34 | # The exchange type (fanout, topic, direct) 35 | config :exchange_type, :validate => EXCHANGE_TYPES, :required => true 36 | 37 | # Is this exchange durable? (aka; Should it survive a broker restart?) 38 | config :durable, :validate => :boolean, :default => true 39 | 40 | # Should RabbitMQ persist messages to disk? 41 | config :persistent, :validate => :boolean, :default => true 42 | 43 | # Properties to be passed along with the message 44 | config :message_properties, :validate => :hash, :default => {} 45 | 46 | def register 47 | connect! 48 | @hare_info.exchange = declare_exchange!(@hare_info.channel, @exchange, @exchange_type, @durable) 49 | # The connection close should close all channels, so it is safe to store thread locals here without closing them 50 | @thread_local_channel = java.lang.ThreadLocal.new 51 | @thread_local_exchange = java.lang.ThreadLocal.new 52 | end 53 | 54 | def symbolize(myhash) 55 | Hash[myhash.map{|(k,v)| [k.to_sym,v]}] 56 | end 57 | 58 | def multi_receive_encoded(events_and_data) 59 | events_and_data.each do |event, data| 60 | publish(event, data) 61 | end 62 | end 63 | 64 | def publish(event, message) 65 | raise ArgumentError, "No exchange set in HareInfo!!!" unless @hare_info.exchange 66 | local_exchange.publish(message, :routing_key => event.sprintf(@key), :properties => symbolize(@message_properties.merge(:persistent => @persistent))) 67 | rescue MarchHare::Exception, IOError, AlreadyClosedException, TimeoutException => e 68 | @logger.error("Error while publishing. Will retry.", 69 | :message => e.message, 70 | :exception => e.class, 71 | :backtrace => e.backtrace) 72 | 73 | sleep_for_retry 74 | retry 75 | end 76 | 77 | def local_exchange 78 | exchange = @thread_local_exchange.get 79 | if !exchange 80 | exchange = declare_exchange!(local_channel, @exchange, @exchange_type, @durable) 81 | @thread_local_exchange.set(exchange) 82 | end 83 | exchange 84 | end 85 | 86 | def local_channel 87 | channel = @thread_local_channel.get 88 | if !channel 89 | channel = @hare_info.connection.create_channel 90 | @thread_local_channel.set(channel) 91 | end 92 | channel 93 | end 94 | 95 | def close 96 | close_connection 97 | end 98 | end 99 | end 100 | end -------------------------------------------------------------------------------- /logstash-output-rabbitmq.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'logstash-output-rabbitmq' 3 | s.version = '5.1.1' 4 | s.licenses = ['Apache License (2.0)'] 5 | s.summary = "Pushes events to a RabbitMQ exchange" 6 | s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" 7 | s.authors = ["Elastic"] 8 | s.email = 'info@elastic.co' 9 | s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" 10 | s.require_paths = ["lib"] 11 | 12 | # Files 13 | s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"] 14 | 15 | # Tests 16 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 17 | 18 | # Special flag to let us know this is actually a logstash plugin 19 | s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" } 20 | 21 | # Gem dependencies 22 | s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" 23 | s.add_runtime_dependency "logstash-mixin-rabbitmq_connection", '>= 5.0.0', '< 6.0.0' 24 | 25 | s.platform = RUBY_PLATFORM 26 | 27 | s.add_development_dependency 'logstash-devutils' 28 | s.add_development_dependency 'logstash-input-generator' 29 | s.add_development_dependency 'logstash-codec-json' 30 | end 31 | 32 | -------------------------------------------------------------------------------- /spec/outputs/rabbitmq_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require "logstash/devutils/rspec/spec_helper" 3 | require "logstash/pipeline" 4 | require "logstash/outputs/rabbitmq" 5 | java_import java.util.concurrent.TimeoutException 6 | 7 | describe LogStash::Outputs::RabbitMQ do 8 | let(:klass) { LogStash::Outputs::RabbitMQ } 9 | let(:host) { "localhost" } 10 | let(:port) { 5672 } 11 | let(:exchange_type) { "topic" } 12 | let(:exchange) { "myexchange" } 13 | let(:key) { "mykey" } 14 | let(:persistent) { true } 15 | let(:rabbitmq_settings) { 16 | { 17 | "host" => host, 18 | "port" => port, 19 | "exchange_type" => exchange_type, 20 | "exchange" => exchange, 21 | "key" => key, 22 | "persistent" => persistent 23 | } 24 | } 25 | let(:instance) { klass.new(rabbitmq_settings) } 26 | let(:hare_info) { instance.instance_variable_get(:@hare_info) } 27 | 28 | shared_examples 'recovers from exception gracefully' do 29 | it 'should execute publish twice due to a retry' do 30 | expect(exchange).to have_received(:publish).twice 31 | end 32 | 33 | it 'should sleep for the retry' do 34 | expect(instance).to have_received(:sleep_for_retry).once 35 | end 36 | 37 | it 'should send the correct message (twice)' do 38 | expect(exchange).to have_received(:publish).with(encoded_event, anything).twice 39 | end 40 | 41 | it 'should send the correct metadata (twice)' do 42 | expected_metadata = {:routing_key => event.sprintf(key), :properties => {:persistent => persistent }} 43 | expect(exchange).to have_received(:publish).with(anything, expected_metadata).twice 44 | end 45 | end 46 | 47 | it "should register as an output plugin" do 48 | expect(LogStash::Plugin.lookup("output", "rabbitmq")).to eql(LogStash::Outputs::RabbitMQ) 49 | end 50 | 51 | context "when connected" do 52 | let(:connection) { double("MarchHare Connection") } 53 | let(:channel) { double("Channel") } 54 | let(:exchange) { double("Exchange") } 55 | 56 | before do 57 | allow(instance).to receive(:connect!).and_call_original 58 | allow(::MarchHare).to receive(:connect).and_return(connection) 59 | allow(connection).to receive(:create_channel).and_return(channel) 60 | allow(connection).to receive(:on_blocked) 61 | allow(connection).to receive(:on_unblocked) 62 | allow(connection).to receive(:on_shutdown) 63 | allow(channel).to receive(:exchange).and_return(exchange) 64 | 65 | instance.register 66 | end 67 | 68 | describe "#connect!" do 69 | subject { hare_info } 70 | 71 | it "should set the exchange correctly" do 72 | expect(subject.exchange).to eql(exchange) 73 | end 74 | end 75 | 76 | describe "#publish_encoded" do 77 | let(:event) { LogStash::Event.new("foo" => "bar") } 78 | let(:sprinted_key) { double("sprinted key") } 79 | let(:encoded_event) { LogStash::Json.dump(event) } 80 | 81 | describe "issuing the publish" do 82 | before do 83 | allow(exchange).to receive(:publish).with(any_args) 84 | allow(event).to receive(:sprintf).with(key).and_return(sprinted_key) 85 | instance.send(:publish, event, encoded_event) 86 | end 87 | 88 | it "should send the correct message" do 89 | expect(exchange).to have_received(:publish).with(encoded_event, anything) 90 | end 91 | 92 | it "should send the correct metadata" do 93 | expected_metadata = {:routing_key => sprinted_key, :properties => {:persistent => persistent }} 94 | 95 | expect(exchange).to have_received(:publish).with(anything, expected_metadata) 96 | end 97 | end 98 | 99 | context 'when an exception is encountered' do 100 | let(:exception) { nil } 101 | 102 | before do 103 | i = 0 104 | allow(instance).to receive(:connect!) 105 | allow(instance).to receive(:sleep_for_retry) 106 | allow(exchange).to receive(:publish).with(any_args) do 107 | i += 1 108 | raise exception if i == 1 109 | end 110 | 111 | instance.send(:publish, event, encoded_event) 112 | end 113 | 114 | context 'when it is a MarchHare exception' do 115 | let(:exception) { MarchHare::Exception } 116 | it_behaves_like 'recovers from exception gracefully' 117 | end 118 | 119 | context 'when it is a MarchHare::ChannelAlreadyClosed' do 120 | let(:exception) { MarchHare::ChannelAlreadyClosed } 121 | it_behaves_like 'recovers from exception gracefully' 122 | end 123 | 124 | context 'when it is a TimeoutException' do 125 | let(:exception) { TimeoutException.new } 126 | it_behaves_like 'recovers from exception gracefully' 127 | end 128 | end 129 | end 130 | end 131 | end 132 | 133 | 134 | describe "with a live server", :integration => true do 135 | let(:klass) { LogStash::Outputs::RabbitMQ } 136 | let(:exchange) { "myexchange" } 137 | let(:exchange_type) { "topic" } 138 | let(:priority) { 34 } 139 | let(:default_plugin_config) { 140 | { 141 | "host" => "127.0.0.1", 142 | "exchange" => exchange, 143 | "exchange_type" => exchange_type, 144 | "key" => "foo", 145 | "message_properties" => { 146 | "priority" => priority 147 | } 148 | } 149 | } 150 | let(:config) { default_plugin_config } 151 | let(:instance) { klass.new(config) } 152 | let(:hare_info) { instance.instance_variable_get(:@hare_info) } 153 | 154 | # Spawn a connection in the bg and wait up (n) seconds 155 | def spawn_and_wait(instance) 156 | instance.register 157 | 158 | 20.times do 159 | instance.connected? ? break : sleep(0.1) 160 | end 161 | 162 | # Extra time to make sure the output can attach 163 | sleep 1 164 | end 165 | let(:message) { LogStash::Event.new("message" => "Foo Message", "extra_field" => "Blah") } 166 | let(:encoded) { message.to_json } 167 | let(:test_connection) { MarchHare.connect(instance.send(:rabbitmq_settings)) } 168 | let(:test_channel) { test_connection.create_channel } 169 | let(:test_queue) { 170 | test_channel.queue("testq", :auto_delete => true).bind(exchange, :key => config["key"]) 171 | } 172 | 173 | before do 174 | # Materialize the instance in the current thread to prevent dupes 175 | # If you use multiple threads with lazy evaluation weird stuff happens 176 | instance 177 | spawn_and_wait(instance) 178 | 179 | test_channel # Start up the test client as well 180 | test_queue 181 | end 182 | 183 | after do 184 | instance.close() 185 | test_channel.close 186 | test_connection.close 187 | end 188 | 189 | context "using defaults" do 190 | it "should start, connect, and stop cleanly" do 191 | expect(instance.connected?).to be_truthy 192 | end 193 | 194 | it "should close cleanly" do 195 | instance.close 196 | expect(instance.connected?).to be_falsey 197 | end 198 | 199 | it 'applies per message settings' do 200 | instance.multi_receive_encoded([[message, encoded]]) 201 | sleep 1.0 202 | 203 | message, payload = test_queue.pop 204 | expect(message.properties.to_s).to include("priority=#{priority}") 205 | end 206 | end 207 | 208 | describe "sending a message with an exchange specified" do 209 | let(:message) { LogStash::Event.new("message" => "Foo Message", "extra_field" => "Blah") } 210 | 211 | before do 212 | @received = nil 213 | test_queue.subscribe do |metadata,payload| 214 | @received = payload 215 | end 216 | 217 | instance.multi_receive_encoded([[message, encoded]]) 218 | 219 | until @received 220 | sleep 1 221 | end 222 | 223 | @decoded = LogStash::Json.load(@received) 224 | end 225 | 226 | it "should process the message fully using the default (JSON) codec" do 227 | expect(@decoded).to eql(LogStash::Json.load(LogStash::Json.dump(message))) 228 | end 229 | end 230 | end 231 | --------------------------------------------------------------------------------