├── .devcontainer ├── Dockerfile ├── devcontainer.json └── library-scripts │ └── node-debian.sh ├── .github └── dependabot.yml ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── README.md ├── bin └── travisci │ └── before_install.sh ├── clojure ├── .gitignore ├── README.md ├── project.clj └── src │ └── rabbitmq │ └── tutorials │ ├── emit_log.clj │ ├── emit_log_direct.clj │ ├── emit_log_topic.clj │ ├── new_task.clj │ ├── receive.clj │ ├── receive_logs.clj │ ├── receive_logs_direct.clj │ ├── receive_logs_topic.clj │ ├── rpc_client.clj │ ├── rpc_server.clj │ ├── send.clj │ └── worker.clj ├── common-lisp ├── README.md ├── emit-log-direct.lisp ├── emit-log-topic.lisp ├── emit-log.lisp ├── new-task.lisp ├── receive-logs-direct.lisp ├── receive-logs-topic.lisp ├── receive-logs.lisp ├── receive.lisp ├── rpc-client.lisp ├── rpc-server.lisp ├── send.lisp └── worker.lisp ├── cpp ├── CMakeLists.txt ├── README.md ├── emit_log.cpp ├── emit_log_direct.cpp ├── emit_log_topic.cpp ├── new_task.cpp ├── publisher_confirms.cpp ├── receive.cpp ├── receive_logs.cpp ├── receive_logs_direct.cpp ├── receive_logs_topic.cpp ├── rpc_client.cpp ├── rpc_server.cpp ├── send.cpp └── worker.cpp ├── dart ├── README.md ├── emit_log.dart ├── emit_log_direct.dart ├── emit_log_topic.dart ├── new_task.dart ├── pubspec.lock ├── pubspec.yaml ├── receive.dart ├── receive_logs.dart ├── receive_logs_direct.dart ├── receive_logs_topic.dart ├── rpc_client.dart ├── rpc_server.dart ├── send.dart └── worker.dart ├── dotnet-stream ├── .gitignore ├── OffsetTrackingReceive │ ├── OffsetTrackingReceive.cs │ └── OffsetTrackingReceive.csproj ├── OffsetTrackingSend │ ├── OffsetTrackingSend.cs │ └── OffsetTrackingSend.csproj ├── README.md ├── Receive │ ├── Receive.cs │ └── Receive.csproj ├── Send │ ├── Send.cs │ └── Send.csproj └── dotnet-stream.sln ├── dotnet ├── .gitattributes ├── .gitignore ├── EmitLog │ ├── EmitLog.cs │ └── EmitLog.csproj ├── EmitLogDirect │ ├── EmitLogDirect.cs │ └── EmitLogDirect.csproj ├── EmitLogTopic │ ├── EmitLogTopic.cs │ └── EmitLogTopic.csproj ├── NewTask │ ├── NewTask.cs │ └── NewTask.csproj ├── PublisherConfirms │ ├── PublisherConfirms.cs │ └── PublisherConfirms.csproj ├── README.md ├── RPCClient │ ├── RPCClient.cs │ └── RPCClient.csproj ├── RPCServer │ ├── RPCServer.cs │ └── RPCServer.csproj ├── Receive │ ├── Receive.cs │ └── Receive.csproj ├── ReceiveLogs │ ├── ReceiveLogs.cs │ └── ReceiveLogs.csproj ├── ReceiveLogsDirect │ ├── ReceiveLogsDirect.cs │ └── ReceiveLogsDirect.csproj ├── ReceiveLogsTopic │ ├── ReceiveLogsTopic.cs │ └── ReceiveLogsTopic.csproj ├── Send │ ├── Send.cs │ └── Send.csproj ├── Worker │ ├── Worker.cs │ └── Worker.csproj └── dotnet.sln ├── elixir-stream ├── README.md ├── consume.exs └── publish.exs ├── elixir ├── .gitignore ├── README.md ├── config │ └── config.exs ├── emit_log.exs ├── emit_log_direct.exs ├── emit_log_topic.exs ├── mix.exs ├── new_task.exs ├── receive.exs ├── receive_logs.exs ├── receive_logs_direct.exs ├── receive_logs_topic.exs ├── rpc_client.exs ├── rpc_server.exs ├── send.exs └── worker.exs ├── erlang ├── .gitignore ├── README.md ├── rebar.config ├── rebar.lock └── src │ ├── emit_log.erl │ ├── emit_log_direct.erl │ ├── emit_log_topic.erl │ ├── erlang.app.src │ ├── new_task.erl │ ├── receive_logs.erl │ ├── receive_logs_direct.erl │ ├── receive_logs_topic.erl │ ├── recv.erl │ ├── rpc_client.erl │ ├── rpc_server.erl │ ├── send.erl │ └── worker.erl ├── go-stream ├── README.md ├── go.mod ├── go.sum ├── offset_tracking_receive.go ├── offset_tracking_send.go ├── receive.go └── send.go ├── go ├── .gitignore ├── README.md ├── emit_log.go ├── emit_log_direct.go ├── emit_log_topic.go ├── go.mod ├── go.sum ├── new_task.go ├── publisher_confirms.go ├── receive.go ├── receive_logs.go ├── receive_logs_direct.go ├── receive_logs_topic.go ├── rpc_client.go ├── rpc_server.go ├── send.go └── worker.go ├── haskell ├── README.md ├── emitLog.hs ├── emitLogDirect.hs ├── emitLogTopic.hs ├── newTask.hs ├── receive.hs ├── receiveLogs.hs ├── receiveLogsDirect.hs ├── receiveLogsTopic.hs ├── rpcClient.hs ├── rpcServer.hs ├── send.hs └── worker.hs ├── java-gradle ├── .gitignore ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pull-source-files.bat ├── settings.gradle └── src │ └── main │ └── java │ ├── EmitLog.java │ ├── EmitLogDirect.java │ ├── EmitLogHeader.java │ ├── EmitLogTopic.java │ ├── NewTask.java │ ├── PublisherConfirms.java │ ├── RPCClient.java │ ├── RPCServer.java │ ├── ReceiveLogHeader.java │ ├── ReceiveLogs.java │ ├── ReceiveLogsDirect.java │ ├── ReceiveLogsTopic.java │ ├── Recv.java │ ├── Send.java │ └── Worker.java ├── java-mvn ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── pull-source-files.bat └── src │ ├── main │ └── java │ │ ├── EmitLog.java │ │ ├── EmitLogDirect.java │ │ ├── EmitLogHeader.java │ │ ├── EmitLogTopic.java │ │ ├── NewTask.java │ │ ├── PublisherConfirms.java │ │ ├── RPCClient.java │ │ ├── RPCServer.java │ │ ├── ReceiveLogHeader.java │ │ ├── ReceiveLogs.java │ │ ├── ReceiveLogsDirect.java │ │ ├── ReceiveLogsTopic.java │ │ ├── Recv.java │ │ ├── Send.java │ │ └── Worker.java │ └── test │ └── java │ └── PublisherConfirmsTest.java ├── java-stream-mvn ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ └── main │ │ ├── java │ │ ├── OffsetTrackingReceive.java │ │ ├── OffsetTrackingSend.java │ │ ├── Receive.java │ │ └── Send.java │ │ └── resources │ │ └── logback.xml └── start-broker.sh ├── java ├── EmitLog.java ├── EmitLogDirect.java ├── EmitLogHeader.java ├── EmitLogTopic.java ├── NewTask.java ├── PublisherConfirms.java ├── README.md ├── RPCClient.java ├── RPCServer.java ├── ReceiveLogHeader.java ├── ReceiveLogs.java ├── ReceiveLogsDirect.java ├── ReceiveLogsTopic.java ├── Recv.java ├── Send.java ├── Worker.java └── recompile.sh ├── javascript-nodejs-stream ├── .gitignore ├── README.md ├── offset_tracking_receive.js ├── offset_tracking_send.js ├── package-lock.json ├── package.json ├── receive.js └── send.js ├── javascript-nodejs ├── README.md ├── package-lock.json ├── package.json └── src │ ├── emit_log.js │ ├── emit_log_direct.js │ ├── emit_log_topic.js │ ├── new_task.js │ ├── receive.js │ ├── receive_logs.js │ ├── receive_logs_direct.js │ ├── receive_logs_topic.js │ ├── rpc_client.js │ ├── rpc_server.js │ ├── send.js │ └── worker.js ├── julia ├── README.md ├── emit_log.jl ├── emit_log_direct.jl ├── emit_log_topic.jl ├── new_task.jl ├── receive.jl ├── receive_logs.jl ├── receive_logs_direct.jl ├── receive_logs_topic.jl ├── rpc_client.jl ├── rpc_server.jl ├── send.jl └── worker.jl ├── kotlin ├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ └── main │ └── kotlin │ ├── EmitLog.kt │ ├── EmitLogDirect.kt │ ├── EmitLogHeader.kt │ ├── EmitLogTopic.kt │ ├── NewTask.kt │ ├── RPCClient.kt │ ├── RPCServer.kt │ ├── ReceiveLogHeader.kt │ ├── ReceiveLogs.kt │ ├── ReceiveLogsDirect.kt │ ├── ReceiveLogsTopic.kt │ ├── Recv.kt │ ├── Send.kt │ └── Worker.kt ├── objective-c ├── .gitignore ├── README.md ├── bump_dependencies.sh ├── tutorial1 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial1.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── tutorial1 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── tutorial2 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial2.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── tutorial2 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── tutorial3 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial3.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── tutorial3 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── tutorial4 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial4.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── tutorial4 │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m └── tutorial5 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial5.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── tutorial5 │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── perl ├── README.md ├── emit_log.pl ├── emit_log_direct.pl ├── emit_log_topic.pl ├── new_task.pl ├── receive.pl ├── receive_logs.pl ├── receive_logs_direct.pl ├── receive_logs_topic.pl ├── rpc_client.pl ├── rpc_server.pl ├── send.pl └── worker.pl ├── php-amqp ├── .gitkeep ├── README.md ├── emit_log.php ├── emit_log_direct.php ├── emit_log_topic.php ├── new_task.php ├── receive.php ├── receive_log_topic.php ├── receive_logs.php ├── receive_logs_direct.php ├── receive_logs_topic.php ├── rpc_client.php ├── rpc_server.php ├── send.php └── worker.php ├── php-interop ├── README.md ├── emit_log.php ├── emit_log_direct.php ├── emit_log_topic.php ├── new_task.php ├── receive.php ├── receive_logs.php ├── receive_logs_direct.php ├── receive_logs_topic.php ├── rpc_client.php ├── rpc_server.php ├── send.php └── worker.php ├── php ├── .gitignore ├── README.md ├── composer.json ├── emit_log.php ├── emit_log_direct.php ├── emit_log_topic.php ├── new_task.php ├── receive.php ├── receive_logs.php ├── receive_logs_direct.php ├── receive_logs_topic.php ├── rpc_client.php ├── rpc_server.php ├── send.php └── worker.php ├── python-stream ├── README.md ├── offset_tracking_receive.py ├── offset_tracking_send.py ├── receive.py ├── requirements.txt └── send.py ├── python ├── README.md ├── emit_log.py ├── emit_log_direct.py ├── emit_log_topic.py ├── new_task.py ├── receive.py ├── receive_logs.py ├── receive_logs_direct.py ├── receive_logs_topic.py ├── rpc_client.py ├── rpc_server.py ├── send.py └── worker.py ├── ruby ├── Gemfile ├── Gemfile.lock ├── README.md ├── emit_log.rb ├── emit_log_direct.rb ├── emit_log_topic.rb ├── new_task.rb ├── receive.rb ├── receive_logs.rb ├── receive_logs_direct.rb ├── receive_logs_topic.rb ├── rpc_client.rb ├── rpc_server.rb ├── send.rb └── worker.rb ├── rust-amqprs ├── Cargo.lock ├── Cargo.toml ├── README.md └── src │ └── bin │ ├── emit_log.rs │ ├── emit_log_direct.rs │ ├── emit_log_topic.rs │ ├── new_task.rs │ ├── receive.rs │ ├── receive_logs.rs │ ├── receive_logs_direct.rs │ ├── receive_logs_topic.rs │ ├── send.rs │ └── worker.rs ├── rust-lapin ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md └── src │ └── bin │ ├── emit_log.rs │ ├── emit_log_direct.rs │ ├── emit_log_topic.rs │ ├── new_task.rs │ ├── receive.rs │ ├── receive_logs.rs │ ├── receive_logs_direct.rs │ ├── receive_logs_topic.rs │ ├── rpc_client.rs │ ├── rpc_server.rs │ ├── send.rs │ └── worker.rs ├── rust-stream ├── Cargo.lock ├── Cargo.toml ├── README.md └── src │ └── bin │ ├── receive.rs │ ├── receive_offset_tracking.rs │ ├── send.rs │ └── send_offset_tracking.rs ├── scala ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ └── scala │ ├── EmitLog.scala │ ├── EmitLogDirect.scala │ ├── EmitLogHeader.scala │ ├── EmitLogTopic.scala │ ├── NewTask.scala │ ├── RPCClient.scala │ ├── RPCServer.scala │ ├── ReceiveLogHeader.scala │ ├── ReceiveLogs.scala │ ├── ReceiveLogsDirect.scala │ ├── ReceiveLogsTopic.scala │ ├── Recv.scala │ ├── Send.scala │ └── Worker.scala ├── soapui ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── RabbitMQ-tutorials-soapui-project.xml ├── mvnw ├── mvnw.cmd └── pom.xml ├── spring-amqp-stream ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── springframework │ │ └── amqp │ │ └── tutorials │ │ ├── RabbitAmqpTutorialsApplication.java │ │ ├── RabbitAmqpTutorialsRunner.java │ │ └── tut1 │ │ ├── Tut1Config.java │ │ ├── Tut1Receiver.java │ │ └── Tut1Sender.java │ └── resources │ ├── application-remote.yml │ ├── application.yml │ └── banner.txt ├── spring-amqp ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── springframework │ │ └── amqp │ │ └── tutorials │ │ ├── RabbitAmqpTutorialsApplication.java │ │ ├── RabbitAmqpTutorialsRunner.java │ │ ├── tut1 │ │ ├── Tut1Config.java │ │ ├── Tut1Receiver.java │ │ └── Tut1Sender.java │ │ ├── tut2 │ │ ├── Tut2Config.java │ │ ├── Tut2Receiver.java │ │ └── Tut2Sender.java │ │ ├── tut3 │ │ ├── Tut3Config.java │ │ ├── Tut3Receiver.java │ │ └── Tut3Sender.java │ │ ├── tut4 │ │ ├── Tut4Config.java │ │ ├── Tut4Receiver.java │ │ └── Tut4Sender.java │ │ ├── tut5 │ │ ├── Tut5Config.java │ │ ├── Tut5Receiver.java │ │ └── Tut5Sender.java │ │ └── tut6 │ │ ├── Tut6Client.java │ │ ├── Tut6Config.java │ │ └── Tut6Server.java │ └── resources │ ├── application-pcfdev.yml │ ├── application-remote.yml │ ├── application.yml │ └── banner.txt ├── swift ├── .gitignore ├── README.md ├── bump_dependencies.sh ├── tutorial1 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial1.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── tutorial1 │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── ViewController.swift ├── tutorial2 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial2.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── tutorial2 │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── ViewController.swift ├── tutorial3 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial3.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── tutorial3 │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── ViewController.swift ├── tutorial4 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial4.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── tutorial4 │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── ViewController.swift └── tutorial5 │ ├── Cartfile │ ├── Cartfile.resolved │ ├── tutorial5.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── tutorial5 │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── test.py └── travisci.py /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rabbitmq:3.7-management 2 | 3 | ENV NVM_DIR="/usr/local/share/nvm" 4 | ENV NVM_SYMLINK_CURRENT=true \ 5 | PATH=${NVM_DIR}/current/bin:${PATH} 6 | COPY library-scripts/node-debian.sh /tmp/library-scripts/ 7 | RUN apt-get update && bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RabbitMQ Tutorials", 3 | "dockerFile": "Dockerfile", 4 | "forwardPorts": [ 4369, 5671, 5672, 15691, 15692, 25672 ], 5 | 6 | // Set *default* container specific settings.json values on container create. 7 | "settings": { 8 | "terminal.integrated.shell.linux": "/bin/bash" 9 | }, 10 | 11 | // Add the IDs of extensions you want installed when the container is created. 12 | "extensions": [], 13 | 14 | // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. 15 | // "remoteUser": "vscode" 16 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Please see the documentation for all configuration options: 2 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 3 | version: 2 4 | updates: 5 | - package-ecosystem: "maven" 6 | directory: "/java-mvn" 7 | schedule: 8 | interval: "daily" 9 | open-pull-requests-limit: 20 10 | target-branch: "main" 11 | - package-ecosystem: "maven" 12 | directory: "/java-stream-mvn" 13 | schedule: 14 | interval: "daily" 15 | open-pull-requests-limit: 20 16 | target-branch: "main" 17 | - package-ecosystem: "maven" 18 | directory: "/spring-amqp" 19 | schedule: 20 | interval: "daily" 21 | open-pull-requests-limit: 20 22 | target-branch: "main" 23 | - package-ecosystem: "maven" 24 | directory: "/spring-amqp-stream" 25 | schedule: 26 | interval: "daily" 27 | open-pull-requests-limit: 20 28 | target-branch: "main" 29 | - package-ecosystem: "gradle" 30 | directory: "/java-gradle" 31 | schedule: 32 | interval: "daily" 33 | open-pull-requests-limit: 20 34 | target-branch: "main" 35 | 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */.ok 2 | */distribute-*.tar.gz 3 | *.zip 4 | erlang/amqp_client* 5 | erlang/rabbit_common* 6 | erlang/recon* 7 | python/venv 8 | dotnet/*.exe 9 | dotnet/*/bin/* 10 | dotnet/lib 11 | java/*.class 12 | java/*.jar 13 | java/rabbitmq-java-client-bin* 14 | javascript-nodejs/node_modules 15 | php/lib/ 16 | python-puka/venv 17 | ruby*/gems/ 18 | venv/* 19 | ruby*/rubygems* 20 | 21 | elixir-stream/deps 22 | elixir-stream/_build 23 | elixir-stream/.elixir_ls 24 | 25 | java*/.idea/workspace.xml 26 | java*/.idea/encodings.xml 27 | *~ 28 | 29 | .vscode/ 30 | obj/ 31 | bin/* 32 | !src/bin/* 33 | target/ 34 | .DS_Store 35 | *.iml 36 | .idea/ 37 | .vs/ 38 | 39 | *.log 40 | .packages 41 | .python-version 42 | 43 | .classpath 44 | .project 45 | .settings 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: "2.2" 3 | before_install: ./bin/travisci/before_install.sh 4 | script: make test-travisci 5 | services: 6 | - rabbitmq 7 | branches: 8 | only: 9 | - master 10 | env: 11 | - RUBY=ruby GEM=gem SLOWNESS=6 12 | 13 | cache: 14 | directories: 15 | - $HOME/.m2 16 | -------------------------------------------------------------------------------- /bin/travisci/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt-get update 4 | 5 | sudo apt-get install -y mercurial make xsltproc zip unzip ant ed curl 6 | 7 | # Mono 8 | sudo apt-get install -y mono-gmcs mono-xbuild mono-devel mono-runtime 9 | 10 | # Python 11 | sudo apt-get install -y python-virtualenv 12 | 13 | # PHP 14 | sudo apt-get install -y php5-cli 15 | -------------------------------------------------------------------------------- /clojure/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /lib 3 | /classes 4 | /checkouts 5 | pom.xml 6 | pom.xml.asc 7 | *.jar 8 | *.class 9 | .lein-* 10 | bin/* 11 | -------------------------------------------------------------------------------- /clojure/project.clj: -------------------------------------------------------------------------------- 1 | (defproject com.rabbitmq/tutorials "1.0.0-SNAPSHOT" 2 | :description "RabbitMQ tutorials using Langohr" 3 | :url "https://github.com/rabbitmq/rabbitmq-tutorials" 4 | :license {:name "Eclipse Public License" 5 | :url "https://www.eclipse.org/legal/epl-v10.html"} 6 | :dependencies [[org.clojure/clojure "1.6.0"] 7 | [com.novemberain/langohr "3.3.0"]]) 8 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/emit_log.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.emit-log 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.basic :as lb] 6 | [clojure.string :as s])) 7 | 8 | (def ^{:const true} x "logs") 9 | 10 | (defn -main 11 | [& args] 12 | (with-open [conn (lc/connect)] 13 | (let [ch (lch/open conn) 14 | payload (if (empty? args) 15 | "Hello, world!" 16 | (s/join " " args))] 17 | (le/fanout ch x {:durable false :auto-delete false}) 18 | (lb/publish ch x "" payload) 19 | (println (format " [x] Sent %s" payload))))) 20 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/emit_log_direct.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.emit-log-direct 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.basic :as lb] 6 | [clojure.string :as s])) 7 | 8 | (def ^{:const true} x "direct_logs") 9 | 10 | (defn -main 11 | [severity & args] 12 | (with-open [conn (lc/connect)] 13 | (let [ch (lch/open conn) 14 | severity (or severity "info") 15 | payload (if (empty? args) 16 | "Hello, world!" 17 | (s/join " " args))] 18 | (le/direct ch x {:durable false :auto-delete false}) 19 | (lb/publish ch x severity payload) 20 | (println (format " [x] Sent %s" payload))))) 21 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/emit_log_topic.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.emit-log-topic 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.basic :as lb] 6 | [clojure.string :as s])) 7 | 8 | (def ^{:const true} x "topic_logs") 9 | 10 | (defn -main 11 | [severity & args] 12 | (with-open [conn (lc/connect)] 13 | (let [ch (lch/open conn) 14 | severity (or severity "anonymous.info") 15 | payload (if (empty? args) 16 | "Hello, world!" 17 | (s/join " " args))] 18 | (le/topic ch x {:durable false :auto-delete false}) 19 | (lb/publish ch x severity payload) 20 | (println (format " [x] Sent %s" payload))))) 21 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/new_task.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.new-task 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.queue :as lq] 5 | [langohr.basic :as lb] 6 | [clojure.string :as s])) 7 | 8 | (defn -main 9 | [& args] 10 | (with-open [conn (lc/connect)] 11 | (let [ch (lch/open conn) 12 | payload (if (empty? args) 13 | "Hello, world!" 14 | (s/join " " args))] 15 | (lq/declare ch "task_queue" {:durable true :auto-delete false}) 16 | (lb/publish ch "" "task_queue" payload {:persistent true}) 17 | (println (format " [x] Sent %s" payload))))) 18 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/receive.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.receive 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.queue :as lq] 5 | [langohr.consumers :as lcons])) 6 | 7 | (defn handle-delivery 8 | "Handles message delivery" 9 | [ch metadata payload] 10 | (println (format " [x] Received %s" (String. payload "UTF-8")))) 11 | 12 | (defn -main 13 | [& args] 14 | (with-open [conn (lc/connect)] 15 | (let [ch (lch/open conn)] 16 | (lq/declare ch "hello" {:durable false :auto-delete false}) 17 | (println " [*] Waiting for messages. To exit press CTRL+C") 18 | (lcons/blocking-subscribe ch "hello" handle-delivery {:auto-ack true})))) 19 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/receive_logs.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.receive-logs 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.queue :as lq] 6 | [langohr.basic :as lb] 7 | [langohr.consumers :as lcons])) 8 | 9 | (def ^{:const true} x "logs") 10 | 11 | (defn handle-delivery 12 | "Handles message delivery" 13 | [ch metadata payload] 14 | (println (format " [x] %s" (String. payload "UTF-8")))) 15 | 16 | 17 | (defn -main 18 | [& args] 19 | (with-open [conn (lc/connect)] 20 | (let [ch (lch/open conn) 21 | {:keys [queue]} (lq/declare ch "" {:durable true :auto-delete false})] 22 | (le/fanout ch x {:durable false :auto-delete false}) 23 | (lq/bind ch queue x) 24 | (println " [*] Waiting for logs. To exit press CTRL+C") 25 | (lcons/blocking-subscribe ch queue handle-delivery)))) 26 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/receive_logs_direct.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.receive-logs-direct 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.queue :as lq] 6 | [langohr.basic :as lb] 7 | [langohr.consumers :as lcons])) 8 | 9 | (def ^{:const true} x "direct_logs") 10 | 11 | (defn handle-delivery 12 | "Handles message delivery" 13 | [ch {:keys [routing-key]} payload] 14 | (println (format " [x] %s:%s" routing-key (String. payload "UTF-8")))) 15 | 16 | 17 | (defn -main 18 | [& args] 19 | (with-open [conn (lc/connect)] 20 | (let [ch (lch/open conn) 21 | {:keys [queue]} (lq/declare ch "" {:durable false :auto-delete false})] 22 | (le/direct ch x {:durable false :auto-delete false}) 23 | (doseq [severity args] 24 | (lq/bind ch queue x {:routing-key severity})) 25 | (println " [*] Waiting for logs. To exit press CTRL+C") 26 | (lcons/blocking-subscribe ch queue handle-delivery)))) 27 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/receive_logs_topic.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.receive-logs-topic 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.exchange :as le] 5 | [langohr.queue :as lq] 6 | [langohr.basic :as lb] 7 | [langohr.consumers :as lcons])) 8 | 9 | (def ^{:const true} x "topic_logs") 10 | 11 | (defn handle-delivery 12 | "Handles message delivery" 13 | [ch {:keys [routing-key]} payload] 14 | (println (format " [x] %s:%s" routing-key (String. payload "UTF-8")))) 15 | 16 | 17 | (defn -main 18 | [& args] 19 | (with-open [conn (lc/connect)] 20 | (let [ch (lch/open conn) 21 | {:keys [queue]} (lq/declare ch "" {:durable false :auto-delete false})] 22 | (le/topic ch x {:durable false :auto-delete false}) 23 | (doseq [severity args] 24 | (lq/bind ch queue x {:routing-key severity})) 25 | (println " [*] Waiting for logs. To exit press CTRL+C") 26 | (lcons/blocking-subscribe ch queue handle-delivery)))) 27 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/rpc_server.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.rpc-server 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.queue :as lq] 5 | [langohr.basic :as lb] 6 | [langohr.consumers :as lcons])) 7 | 8 | (def ^{:const true} q "rpc_queue") 9 | 10 | (defn fib 11 | [n] 12 | (if (zero? n) 13 | 0 14 | (if (= n 1) 15 | 1 16 | (+ (fib (- n 1)) 17 | (fib (- n 2)))))) 18 | 19 | (defn handle-delivery 20 | "Handles message delivery" 21 | [ch {:keys [delivery-tag reply-to correlation-id]} payload] 22 | (let [n (read-string (String. payload "UTF-8"))] 23 | (println (format " [.] fib(%s)" n)) 24 | (let [response (fib n)] 25 | (lb/publish ch "" reply-to (str response) {:correlation-id correlation-id}) 26 | (lb/ack ch delivery-tag)))) 27 | 28 | (defn -main 29 | [& args] 30 | (with-open [conn (lc/connect)] 31 | (let [ch (lch/open conn)] 32 | (lq/declare ch q {:auto-delete false}) 33 | (lb/qos ch 1) 34 | (println " [x] Awaiting RPC requests") 35 | (lcons/blocking-subscribe ch "rpc_queue" handle-delivery)))) 36 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/send.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.send 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.queue :as lq] 5 | [langohr.basic :as lb])) 6 | 7 | 8 | (defn -main 9 | [& args] 10 | (with-open [conn (lc/connect)] 11 | (let [ch (lch/open conn)] 12 | (lq/declare ch "hello" {:durable false :auto-delete false}) 13 | (lb/publish ch "" "hello" (.getBytes "Hello World!" "UTF-8")) 14 | (println " [x] Sent 'Hello World!'")))) 15 | -------------------------------------------------------------------------------- /clojure/src/rabbitmq/tutorials/worker.clj: -------------------------------------------------------------------------------- 1 | (ns rabbitmq.tutorials.worker 2 | (:require [langohr.core :as lc] 3 | [langohr.channel :as lch] 4 | [langohr.queue :as lq] 5 | [langohr.basic :as lb] 6 | [langohr.consumers :as lcons] 7 | [clojure.string :as s])) 8 | 9 | (def ^{:const true} q "task_queue") 10 | 11 | (defn ^:private occurences-of 12 | [^String s ^Character c] 13 | (let [chars (map identity s)] 14 | (count (filter (fn [x] (= x c)) chars)))) 15 | 16 | (defn handle-delivery 17 | "Handles message delivery" 18 | [ch {:keys [delivery-tag]} payload] 19 | (let [s (String. payload "UTF-8") 20 | n (occurences-of s \.)] 21 | (println (format " [x] Received %s" s)) 22 | (Thread/sleep ^double (* 1000 n)) 23 | (println " [x] Done") 24 | (lb/ack ch delivery-tag))) 25 | 26 | 27 | (defn -main 28 | [& args] 29 | (with-open [conn (lc/connect)] 30 | (let [ch (lch/open conn)] 31 | (lq/declare ch q {:durable true :auto-delete false}) 32 | (lb/qos ch 1) 33 | (println " [*] Waiting for messages. To exit press CTRL+C") 34 | (lcons/blocking-subscribe ch q handle-delivery)))) 35 | -------------------------------------------------------------------------------- /common-lisp/README.md: -------------------------------------------------------------------------------- 1 | # Common Lisp code for RabbitMQ tutorials 2 | 3 | Here you can find Common Lisp code examples from 4 | [RabbitMQ tutorials](https://cl-rabbit.io/cl-bunny/tutorials/). 5 | 6 | ## Requirements 7 | 8 | To run this code you need [Cl-Bunny](https://cl-rabbit.io/cl-bunny). 9 | 10 | You can install it via Quicklisp: 11 | 12 | (ql:quickload :cl-bunny) 13 | 14 | Note: Cl-Bunny developed and tested using x64 sbcl on GNU/Linux 15 | 16 | All our examples are in fact executable sbcl scripts. You can run them from command line 17 | 18 | ## Code 19 | 20 | Tutorial one: "Hello World!"]: 21 | 22 | ./send.lisp 23 | ./receive.lisp 24 | 25 | Tutorial two: Work Queues: 26 | 27 | ./new-task.lisp 28 | ./worker.lisp 29 | 30 | Tutorial three: Publish/Subscribe 31 | 32 | ./receive-logs.lisp 33 | ./emit-log.lisp 34 | 35 | Tutorial four: Routing 36 | 37 | ./receive-logs-direct.lisp 38 | ./emit-log-direct.lisp 39 | 40 | Tutorial five: Topics 41 | 42 | ./receive-logs-topic.lisp 43 | ./emit-log-topic.lisp 44 | 45 | Tutorial six: RPC 46 | 47 | ./rpc-server.lisp 48 | ./rpc-client.lisp 49 | 50 | To learn more, visit [Cl-Bunny documentation](https://cl-rabbit.io/cl-bunny) site. 51 | -------------------------------------------------------------------------------- /common-lisp/emit-log-direct.lisp: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sbcl --noinform --noprint $@ < 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char const *const *argv) 8 | { 9 | amqp_connection_state_t conn = amqp_new_connection(); 10 | amqp_socket_t *socket = amqp_tcp_socket_new(conn); 11 | amqp_socket_open(socket, "localhost", AMQP_PROTOCOL_PORT); 12 | amqp_login(conn, "/", 0, AMQP_DEFAULT_FRAME_SIZE, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"); 13 | const amqp_channel_t KChannel = 1; 14 | amqp_channel_open(conn, KChannel); 15 | 16 | amqp_bytes_t queueName(amqp_cstring_bytes("hello")); 17 | amqp_queue_declare(conn, KChannel, queueName, false, false, false, false, amqp_empty_table); 18 | 19 | amqp_basic_publish(conn, KChannel, amqp_empty_bytes, /* routing key*/ queueName, false, false, nullptr, amqp_cstring_bytes("Hello World!")); 20 | std::cout << " [x] Sent 'Hello World!'" << std::endl; 21 | 22 | amqp_channel_close(conn, KChannel, AMQP_REPLY_SUCCESS); 23 | amqp_connection_close(conn, AMQP_REPLY_SUCCESS); 24 | amqp_destroy_connection(conn); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /dart/emit_log.dart: -------------------------------------------------------------------------------- 1 | import "package:dart_amqp/dart_amqp.dart"; 2 | 3 | void main (List arguments) { 4 | ConnectionSettings settings = new ConnectionSettings( 5 | host: "localhost" 6 | ); 7 | 8 | Client client = new Client(settings: settings); 9 | 10 | String msg = arguments.isEmpty ? "Hello World!" : arguments[0]; 11 | 12 | client 13 | .channel() 14 | .then((Channel channel) => 15 | channel.exchange("logs", ExchangeType.FANOUT, durable: false)) 16 | .then((Exchange exchange) { 17 | exchange.publish(msg, null); 18 | print(" [x] Sent ${msg}"); 19 | return client.close(); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /dart/emit_log_direct.dart: -------------------------------------------------------------------------------- 1 | import "package:dart_amqp/dart_amqp.dart"; 2 | 3 | void main(List arguments) { 4 | ConnectionSettings settings = new ConnectionSettings( 5 | host: "localhost" 6 | ); 7 | 8 | Client client = new Client(settings: settings); 9 | 10 | String routingKey = arguments.length < 1 ? "info" : arguments[0]; 11 | String msg = arguments.length < 2 ? "Hello World!" : arguments[1]; 12 | 13 | client 14 | .channel() 15 | .then((Channel channel) => 16 | channel.exchange("direct_logs", ExchangeType.DIRECT, 17 | durable: false)) 18 | .then((Exchange exchange) { 19 | exchange.publish(msg, routingKey); 20 | print(" [x] Sent ${routingKey}: ${msg}"); 21 | return client.close(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /dart/emit_log_topic.dart: -------------------------------------------------------------------------------- 1 | import "package:dart_amqp/dart_amqp.dart"; 2 | 3 | void main(List arguments) { 4 | ConnectionSettings settings = new ConnectionSettings( 5 | host: "localhost" 6 | ); 7 | 8 | Client client = new Client(settings: settings); 9 | 10 | String routingKey = arguments.length < 1 ? "anonymous.info" : arguments[0]; 11 | String msg = arguments.length < 2 ? "Hello World!" : arguments[1]; 12 | 13 | client 14 | .channel() 15 | .then((Channel channel) => 16 | channel.exchange("topic_logs", ExchangeType.TOPIC, 17 | durable: false)) 18 | .then((Exchange exchange) { 19 | exchange.publish(msg, routingKey); 20 | print(" [x] Sent ${routingKey}: ${msg}"); 21 | return client.close(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /dart/new_task.dart: -------------------------------------------------------------------------------- 1 | import "package:dart_amqp/dart_amqp.dart"; 2 | 3 | void main(List arguments) { 4 | ConnectionSettings settings = new ConnectionSettings( 5 | host: "localhost" 6 | ); 7 | 8 | Client client = new Client(settings: settings); 9 | 10 | String consumeTag = "task_queue"; 11 | String msg = arguments.isEmpty ? "Hello World!" : arguments[0]; 12 | 13 | MessageProperties properties = new MessageProperties.persistentMessage(); 14 | 15 | client 16 | .channel() 17 | .then((Channel channel) => 18 | channel.queue(consumeTag, durable: true)) 19 | .then((Queue queue) { 20 | queue.publish(msg, properties: properties); 21 | print(" [x] Sent ${msg}"); 22 | return client.close(); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /dart/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://www.dartlang.org/tools/pub/glossary#lockfile 3 | packages: 4 | dart_amqp: 5 | dependency: "direct main" 6 | description: 7 | name: dart_amqp 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "0.1.1" 11 | logging: 12 | dependency: transitive 13 | description: 14 | name: logging 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "0.11.3+2" 18 | sdks: 19 | dart: ">=2.0.0-dev <3.0.0" 20 | -------------------------------------------------------------------------------- /dart/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dart_rabbitmq_example 2 | dependencies: 3 | dart_amqp: 0.1.1 4 | -------------------------------------------------------------------------------- /dart/receive.dart: -------------------------------------------------------------------------------- 1 | import "dart:io"; 2 | import "package:dart_amqp/dart_amqp.dart"; 3 | 4 | void main (List arguments) { 5 | ConnectionSettings settings = new ConnectionSettings( 6 | host: "localhost" 7 | ); 8 | 9 | Client client = new Client(settings: settings); 10 | 11 | ProcessSignal.sigint.watch().listen((_) { 12 | client.close().then((_) { 13 | print("close client"); 14 | exit(0); 15 | }); 16 | }); 17 | 18 | String msg = arguments.isEmpty ? "Hello World!": arguments[0]; 19 | 20 | String queueTag = "hello"; 21 | 22 | client 23 | .channel() 24 | .then((Channel channel) => channel.queue(queueTag, durable: false)) 25 | .then((Queue queue) { 26 | print(" [*] Waiting for messages in ${queueTag}. To Exit press CTRL+C"); 27 | return queue.consume(consumerTag: queueTag, noAck: true); 28 | }) 29 | .then((Consumer consumer) { 30 | consumer.listen((AmqpMessage event) { 31 | print(" [x] Received ${event.payloadAsString}"); 32 | }); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /dart/receive_logs.dart: -------------------------------------------------------------------------------- 1 | import "dart:io"; 2 | import "package:dart_amqp/dart_amqp.dart"; 3 | 4 | void main (List arguments) { 5 | ConnectionSettings settings = new ConnectionSettings( 6 | host: "localhost" 7 | ); 8 | 9 | Client client = new Client(settings: settings); 10 | 11 | ProcessSignal.sigint.watch().listen((_) { 12 | client.close().then((_) { 13 | print("close client"); 14 | exit(0); 15 | }); 16 | }); 17 | 18 | String msg = arguments.isEmpty ? "Hello World!": arguments[0]; 19 | 20 | client 21 | .channel() 22 | .then((Channel channel) { 23 | return channel.exchange("logs", ExchangeType.FANOUT, durable: false); 24 | }) 25 | .then((Exchange exchange) { 26 | print(" [*] Waiting for messages in logs. To Exit press CTRL+C"); 27 | return exchange.bindPrivateQueueConsumer(null); 28 | }) 29 | .then((Consumer consumer) { 30 | consumer.listen((AmqpMessage event) { 31 | print(" [x] Received ${event.payloadAsString}"); 32 | }); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /dart/rpc_server.dart: -------------------------------------------------------------------------------- 1 | import "dart:io"; 2 | import "package:dart_amqp/dart_amqp.dart"; 3 | 4 | // Slow implementation of fib 5 | int fib(int n) { 6 | if (n >= 0 && n <= 1) { 7 | return n; 8 | } else 9 | return fib(n - 1) + fib(n - 2); 10 | } 11 | 12 | void main(List args) { 13 | 14 | Client client = new Client(); 15 | 16 | // Setup a signal handler to cleanly exit if CTRL+C is pressed 17 | ProcessSignal.sigint.watch().listen((_) { 18 | client.close().then((_) { 19 | exit(0); 20 | }); 21 | }); 22 | 23 | client 24 | .channel() 25 | .then((Channel channel) => channel.qos(0, 1)) 26 | .then((Channel channel) => channel.queue("rpc_queue")) 27 | .then((Queue queue) => queue.consume()) 28 | .then((Consumer consumer) { 29 | print(" [x] Awaiting RPC request"); 30 | consumer.listen((AmqpMessage message) { 31 | var n = message.payloadAsJson["n"]; 32 | print(" [.] fib(${n})"); 33 | message.reply(fib(n).toString()); 34 | }); 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /dart/send.dart: -------------------------------------------------------------------------------- 1 | import "package:dart_amqp/dart_amqp.dart"; 2 | 3 | void main (List arguments) { 4 | ConnectionSettings settings = new ConnectionSettings( 5 | host: "localhost" 6 | ); 7 | 8 | Client client = new Client(settings: settings); 9 | 10 | String consumeTag = "hello"; 11 | String msg = "hello"; 12 | 13 | client 14 | .channel() 15 | .then((Channel channel) { 16 | return channel.queue(consumeTag, durable: false); 17 | }) 18 | .then((Queue queue) { 19 | queue.publish(msg); 20 | print(" [x] Sent ${msg}"); 21 | client.close(); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /dart/worker.dart: -------------------------------------------------------------------------------- 1 | import "dart:io"; 2 | import "package:dart_amqp/dart_amqp.dart"; 3 | 4 | void main (List arguments) { 5 | ConnectionSettings settings = new ConnectionSettings( 6 | host: "localhost" 7 | ); 8 | 9 | Client client = new Client(settings: settings); 10 | 11 | ProcessSignal.sigint.watch().listen((_) { 12 | client.close().then((_) { 13 | print("close client"); 14 | exit(0); 15 | }); 16 | }); 17 | 18 | String consumeTag = "task_queue"; 19 | 20 | client 21 | .channel() 22 | .then((Channel channel) { 23 | return channel.qos(0, 1) 24 | .then((Channel channel) => 25 | channel.queue(consumeTag, durable: true)); 26 | }) 27 | .then((Queue queue) => queue.consume(noAck: false)) 28 | .then((Consumer consumer) { 29 | consumer.listen((AmqpMessage event) { 30 | String payload = event.payloadAsString; 31 | print(" [x] Received ${payload}"); 32 | sleep(new Duration(seconds : payload.split(".").length)); 33 | print(" [x] Done"); 34 | event.ack(); 35 | }); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /dotnet-stream/OffsetTrackingReceive/OffsetTrackingReceive.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet-stream/OffsetTrackingSend/OffsetTrackingSend.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Threading.Tasks; 3 | using RabbitMQ.Stream.Client; 4 | using RabbitMQ.Stream.Client.Reliable; 5 | 6 | var streamSystem = await StreamSystem.Create(new StreamSystemConfig()); 7 | 8 | var stream = "stream-offset-tracking-dotnet"; 9 | await streamSystem.CreateStream(new StreamSpec(stream)); 10 | 11 | var messageCount = 100; 12 | var confirmedCde = new CountdownEvent(messageCount); 13 | var producer = await Producer.Create(new ProducerConfig(streamSystem, stream) { 14 | ConfirmationHandler = async confirmation => { 15 | if (confirmation.Status == ConfirmationStatus.Confirmed) { 16 | confirmedCde.Signal(); 17 | } 18 | await Task.CompletedTask.ConfigureAwait(false); 19 | } 20 | }); 21 | 22 | Console.WriteLine("Publishing {0} messages...", messageCount); 23 | for (int i = 0; i < messageCount; i++) { 24 | var body = i == messageCount - 1 ? "marker" : "hello"; 25 | await producer.Send(new Message(Encoding.UTF8.GetBytes(body))); 26 | } 27 | 28 | confirmedCde.Wait(); 29 | Console.WriteLine("Messages confirmed."); 30 | await producer.Close(); 31 | await streamSystem.Close(); 32 | -------------------------------------------------------------------------------- /dotnet-stream/OffsetTrackingSend/OffsetTrackingSend.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet-stream/Receive/Receive.cs: -------------------------------------------------------------------------------- 1 | // See https://aka.ms/new-console-template for more information 2 | 3 | using System.Text; 4 | using RabbitMQ.Stream.Client; 5 | using RabbitMQ.Stream.Client.Reliable; 6 | 7 | var streamSystem = await StreamSystem.Create(new StreamSystemConfig()); 8 | 9 | await streamSystem.CreateStream(new StreamSpec("hello-stream") 10 | { 11 | MaxLengthBytes = 5_000_000_000 12 | }); 13 | 14 | 15 | var consumer = await Consumer.Create(new ConsumerConfig(streamSystem, "hello-stream") 16 | { 17 | OffsetSpec = new OffsetTypeFirst(), 18 | MessageHandler = async (stream, _, _, message) => 19 | { 20 | Console.WriteLine($"Stream: {stream} - " + 21 | $"Received message: {Encoding.UTF8.GetString(message.Data.Contents)}"); 22 | await Task.CompletedTask; 23 | } 24 | }); 25 | 26 | Console.WriteLine(" [x] Press any key to exit"); 27 | Console.ReadKey(); 28 | 29 | await consumer.Close(); 30 | await streamSystem.Close(); -------------------------------------------------------------------------------- /dotnet-stream/Receive/Receive.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | ReceiveHello 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /dotnet-stream/Send/Send.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using RabbitMQ.Stream.Client; 3 | using RabbitMQ.Stream.Client.Reliable; 4 | 5 | var streamSystem = await StreamSystem.Create(new StreamSystemConfig()); 6 | 7 | await streamSystem.CreateStream(new StreamSpec("hello-stream") 8 | { 9 | MaxLengthBytes = 5_000_000_000 10 | }); 11 | 12 | var producer = await Producer.Create(new ProducerConfig(streamSystem, "hello-stream")); 13 | 14 | 15 | await producer.Send(new Message(Encoding.UTF8.GetBytes($"Hello, World"))); 16 | Console.WriteLine(" [x] Sent 'Hello, World'"); 17 | 18 | Console.WriteLine(" [x] Press any key to exit"); 19 | Console.ReadKey(); 20 | await producer.Close(); 21 | await streamSystem.Close(); -------------------------------------------------------------------------------- /dotnet-stream/Send/Send.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | SendHello 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /dotnet/.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Auto detect text files and perform LF normalization 5 | *.cs text=auto eol=lf 6 | *.txt text=auto 7 | 8 | # Declare files that will always have CRLF line endings on checkout. 9 | *.sln text eol=crlf 10 | *.csproj text eol=crlf 11 | 12 | # Custom for Visual Studio 13 | *.cs diff=csharp 14 | 15 | -------------------------------------------------------------------------------- /dotnet/.gitignore: -------------------------------------------------------------------------------- 1 | *.dll 2 | *.exe 3 | *.lock.json 4 | packages/ 5 | -------------------------------------------------------------------------------- /dotnet/EmitLog/EmitLog.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | var factory = new ConnectionFactory { HostName = "localhost" }; 5 | using var connection = await factory.CreateConnectionAsync(); 6 | using var channel = await connection.CreateChannelAsync(); 7 | 8 | await channel.ExchangeDeclareAsync(exchange: "logs", type: ExchangeType.Fanout); 9 | 10 | var message = GetMessage(args); 11 | var body = Encoding.UTF8.GetBytes(message); 12 | await channel.BasicPublishAsync(exchange: "logs", routingKey: string.Empty, body: body); 13 | Console.WriteLine($" [x] Sent {message}"); 14 | 15 | Console.WriteLine(" Press [enter] to exit."); 16 | Console.ReadLine(); 17 | 18 | static string GetMessage(string[] args) 19 | { 20 | return ((args.Length > 0) ? string.Join(" ", args) : "info: Hello World!"); 21 | } 22 | -------------------------------------------------------------------------------- /dotnet/EmitLog/EmitLog.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/EmitLogDirect/EmitLogDirect.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | var factory = new ConnectionFactory { HostName = "localhost" }; 5 | using var connection = await factory.CreateConnectionAsync(); 6 | using var channel = await connection.CreateChannelAsync(); 7 | 8 | await channel.ExchangeDeclareAsync(exchange: "direct_logs", type: ExchangeType.Direct); 9 | 10 | var severity = (args.Length > 0) ? args[0] : "info"; 11 | var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!"; 12 | var body = Encoding.UTF8.GetBytes(message); 13 | await channel.BasicPublishAsync(exchange: "direct_logs", routingKey: severity, body: body); 14 | Console.WriteLine($" [x] Sent '{severity}':'{message}'"); 15 | 16 | Console.WriteLine(" Press [enter] to exit."); 17 | Console.ReadLine(); 18 | -------------------------------------------------------------------------------- /dotnet/EmitLogDirect/EmitLogDirect.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/EmitLogTopic/EmitLogTopic.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | var factory = new ConnectionFactory { HostName = "localhost" }; 5 | using var connection = await factory.CreateConnectionAsync(); 6 | using var channel = await connection.CreateChannelAsync(); 7 | 8 | await channel.ExchangeDeclareAsync(exchange: "topic_logs", type: ExchangeType.Topic); 9 | 10 | var routingKey = (args.Length > 0) ? args[0] : "anonymous.info"; 11 | var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!"; 12 | var body = Encoding.UTF8.GetBytes(message); 13 | await channel.BasicPublishAsync(exchange: "topic_logs", routingKey: routingKey, body: body); 14 | Console.WriteLine($" [x] Sent '{routingKey}':'{message}'"); 15 | -------------------------------------------------------------------------------- /dotnet/EmitLogTopic/EmitLogTopic.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/NewTask/NewTask.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | var factory = new ConnectionFactory { HostName = "localhost" }; 5 | using var connection = await factory.CreateConnectionAsync(); 6 | using var channel = await connection.CreateChannelAsync(); 7 | 8 | await channel.QueueDeclareAsync(queue: "task_queue", durable: true, exclusive: false, 9 | autoDelete: false, arguments: null); 10 | 11 | var message = GetMessage(args); 12 | var body = Encoding.UTF8.GetBytes(message); 13 | 14 | var properties = new BasicProperties 15 | { 16 | Persistent = true 17 | }; 18 | 19 | await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "task_queue", mandatory: true, 20 | basicProperties: properties, body: body); 21 | Console.WriteLine($" [x] Sent {message}"); 22 | 23 | static string GetMessage(string[] args) 24 | { 25 | return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!"); 26 | } 27 | -------------------------------------------------------------------------------- /dotnet/NewTask/NewTask.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/PublisherConfirms/PublisherConfirms.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/RPCClient/RPCClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/RPCServer/RPCServer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/Receive/Receive.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System.Text; 4 | 5 | var factory = new ConnectionFactory { HostName = "localhost" }; 6 | using var connection = await factory.CreateConnectionAsync(); 7 | using var channel = await connection.CreateChannelAsync(); 8 | 9 | await channel.QueueDeclareAsync(queue: "hello", durable: false, exclusive: false, autoDelete: false, 10 | arguments: null); 11 | 12 | Console.WriteLine(" [*] Waiting for messages."); 13 | 14 | var consumer = new AsyncEventingBasicConsumer(channel); 15 | consumer.ReceivedAsync += (model, ea) => 16 | { 17 | var body = ea.Body.ToArray(); 18 | var message = Encoding.UTF8.GetString(body); 19 | Console.WriteLine($" [x] Received {message}"); 20 | return Task.CompletedTask; 21 | }; 22 | 23 | await channel.BasicConsumeAsync("hello", autoAck: true, consumer: consumer); 24 | 25 | Console.WriteLine(" Press [enter] to exit."); 26 | Console.ReadLine(); 27 | -------------------------------------------------------------------------------- /dotnet/Receive/Receive.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/ReceiveLogs/ReceiveLogs.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System.Text; 4 | 5 | var factory = new ConnectionFactory { HostName = "localhost" }; 6 | using var connection = await factory.CreateConnectionAsync(); 7 | using var channel = await connection.CreateChannelAsync(); 8 | 9 | await channel.ExchangeDeclareAsync(exchange: "logs", 10 | type: ExchangeType.Fanout); 11 | 12 | // declare a server-named queue 13 | QueueDeclareOk queueDeclareResult = await channel.QueueDeclareAsync(); 14 | string queueName = queueDeclareResult.QueueName; 15 | await channel.QueueBindAsync(queue: queueName, exchange: "logs", routingKey: string.Empty); 16 | 17 | Console.WriteLine(" [*] Waiting for logs."); 18 | 19 | var consumer = new AsyncEventingBasicConsumer(channel); 20 | consumer.ReceivedAsync += (model, ea) => 21 | { 22 | byte[] body = ea.Body.ToArray(); 23 | var message = Encoding.UTF8.GetString(body); 24 | Console.WriteLine($" [x] {message}"); 25 | return Task.CompletedTask; 26 | }; 27 | 28 | await channel.BasicConsumeAsync(queueName, autoAck: true, consumer: consumer); 29 | 30 | Console.WriteLine(" Press [enter] to exit."); 31 | Console.ReadLine(); 32 | -------------------------------------------------------------------------------- /dotnet/ReceiveLogs/ReceiveLogs.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/ReceiveLogsDirect/ReceiveLogsDirect.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/ReceiveLogsTopic/ReceiveLogsTopic.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/Send/Send.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | var factory = new ConnectionFactory { HostName = "localhost" }; 5 | using var connection = await factory.CreateConnectionAsync(); 6 | using var channel = await connection.CreateChannelAsync(); 7 | 8 | await channel.QueueDeclareAsync(queue: "hello", durable: false, exclusive: false, autoDelete: false, 9 | arguments: null); 10 | 11 | const string message = "Hello World!"; 12 | var body = Encoding.UTF8.GetBytes(message); 13 | 14 | await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "hello", body: body); 15 | Console.WriteLine($" [x] Sent {message}"); 16 | 17 | Console.WriteLine(" Press [enter] to exit."); 18 | Console.ReadLine(); 19 | -------------------------------------------------------------------------------- /dotnet/Send/Send.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /dotnet/Worker/Worker.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /elixir-stream/README.md: -------------------------------------------------------------------------------- 1 | # Elixir code for RabbitMQ tutorials 2 | 3 | Here you can find Elixir code examples from [RabbitMQ tutorials](https://www.rabbitmq.com/getstarted.html). 4 | 5 | ## Requirements 6 | 7 | These examples use the [`VictorGaiva/rabbitmq-stream`](https://github.com/VictorGaiva/rabbitmq-stream) client library. 8 | 9 | The dependencies are installed during the exection of the examples using `Mix.install/1` 10 | 11 | ## Code 12 | 13 | Code examples are executed via `elixir`: 14 | 15 | Tutorial one: "Hello World!": 16 | 17 | ``` shell 18 | # run the publisher 19 | elixir publish.exs 20 | 21 | # run the consumer 22 | elixir consume.exs 23 | ``` 24 | 25 | To learn more, see [`VictorGaiva/rabbitmq-stream`](https://github.com/VictorGaiva/rabbitmq-stream). 26 | -------------------------------------------------------------------------------- /elixir-stream/consume.exs: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env elixir 2 | require Logger 3 | 4 | # Installing the rabbitmq_stream Library 5 | Mix.install([ 6 | {:rabbitmq_stream, "~> 0.4.1"} 7 | ]) 8 | 9 | # First we start a Connection to the RabbitMQ Server 10 | {:ok, connection} = RabbitMQStream.Connection.start_link() 11 | 12 | # We can assume the stream doesn't exist yet, and attempt to create it. If it already exists, 13 | # it should be still be good to go. 14 | RabbitMQStream.Connection.create_stream(connection, "my_stream") 15 | 16 | # Now we can subscribe to the stream, receiving up to 1 chunk. 17 | {:ok, subscription_id} = 18 | RabbitMQStream.Connection.subscribe(connection, "my_stream", self(), :first, 1) 19 | 20 | # Now we can consume the messages 21 | receive do 22 | # Each 'deliver' data comes inside a Chunk, which may contain multiple messages 23 | {:deliver, %{subscription_id: ^subscription_id, osiris_chunk: chunk}} -> 24 | for message <- chunk.data_entries do 25 | Logger.info("Received: #{inspect(message)}") 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /elixir/.gitignore: -------------------------------------------------------------------------------- 1 | .mix_tasks 2 | mix.lock 3 | /_build 4 | /deps 5 | -------------------------------------------------------------------------------- /elixir/config/config.exs: -------------------------------------------------------------------------------- 1 | use Mix.Config 2 | 3 | config :lager, 4 | handlers: [ 5 | lager_console_backend: [{:level, :warning}] 6 | ] 7 | -------------------------------------------------------------------------------- /elixir/emit_log.exs: -------------------------------------------------------------------------------- 1 | {:ok, connection} = AMQP.Connection.open 2 | {:ok, channel} = AMQP.Channel.open(connection) 3 | 4 | message = 5 | case System.argv do 6 | [] -> "Hello World!" 7 | words -> Enum.join(words, " ") 8 | end 9 | 10 | AMQP.Exchange.declare(channel, "logs", :fanout) 11 | AMQP.Basic.publish(channel, "logs", "", message) 12 | IO.puts " [x] Sent '#{message}'" 13 | 14 | AMQP.Connection.close(connection) 15 | -------------------------------------------------------------------------------- /elixir/emit_log_direct.exs: -------------------------------------------------------------------------------- 1 | {:ok, connection} = AMQP.Connection.open 2 | {:ok, channel} = AMQP.Channel.open(connection) 3 | 4 | {severities, raw_message, _} = 5 | System.argv 6 | |> OptionParser.parse(strict: [info: :boolean, 7 | warning: :boolean, 8 | error: :boolean]) 9 | |> case do 10 | {[], msg, _} -> {[info: true], msg, []} 11 | other -> other 12 | end 13 | 14 | message = 15 | case raw_message do 16 | [] -> "Hello World!" 17 | words -> Enum.join(words, " ") 18 | end 19 | 20 | AMQP.Exchange.declare(channel, "direct_logs", :direct) 21 | 22 | for {severity, true} <- severities do 23 | severity = severity |> to_string 24 | AMQP.Basic.publish(channel, "direct_logs", severity, message) 25 | IO.puts " [x] Sent '[#{severity}] #{message}'" 26 | end 27 | 28 | AMQP.Connection.close(connection) 29 | -------------------------------------------------------------------------------- /elixir/emit_log_topic.exs: -------------------------------------------------------------------------------- 1 | {:ok, connection} = AMQP.Connection.open 2 | {:ok, channel} = AMQP.Channel.open(connection) 3 | 4 | {topic, message} = 5 | System.argv 6 | |> case do 7 | [] -> {"anonymous.info", "Hello World!"} 8 | [message] -> {"anonymous.info", message} 9 | [topic|words] -> {topic, Enum.join(words, " ")} 10 | end 11 | 12 | AMQP.Exchange.declare(channel, "topic_logs", :topic) 13 | 14 | AMQP.Basic.publish(channel, "topic_logs", topic, message) 15 | IO.puts " [x] Sent '[#{topic}] #{message}'" 16 | 17 | AMQP.Connection.close(connection) 18 | -------------------------------------------------------------------------------- /elixir/mix.exs: -------------------------------------------------------------------------------- 1 | defmodule RabbitmqTutorials.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [app: :rabbitmq_tutorials, 6 | version: "1.0.0", 7 | elixir: "~> 1.5", 8 | build_embedded: Mix.env == :prod, 9 | start_permanent: Mix.env == :prod, 10 | deps: deps()] 11 | end 12 | 13 | # Configuration for the OTP application 14 | # 15 | # Type "mix help compile.app" for more information 16 | def application do 17 | [applications: [:amqp]] 18 | end 19 | 20 | # Dependencies can be Hex packages: 21 | # 22 | # {:mydep, "~> 0.3.0"} 23 | # 24 | # Or git/path repositories: 25 | # 26 | # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} 27 | # 28 | # Type "mix help deps" for more examples and options 29 | defp deps do 30 | [ 31 | {:amqp, "~> 3.3"}, 32 | ] 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /elixir/new_task.exs: -------------------------------------------------------------------------------- 1 | {:ok, connection} = AMQP.Connection.open 2 | {:ok, channel} = AMQP.Channel.open(connection) 3 | 4 | AMQP.Queue.declare(channel, "task_queue", durable: true) 5 | 6 | message = 7 | case System.argv do 8 | [] -> "Hello World!" 9 | words -> Enum.join(words, " ") 10 | end 11 | 12 | AMQP.Basic.publish(channel, "", "task_queue", message, persistent: true) 13 | IO.puts " [x] Sent '#{message}'" 14 | 15 | AMQP.Connection.close(connection) 16 | -------------------------------------------------------------------------------- /elixir/receive.exs: -------------------------------------------------------------------------------- 1 | defmodule Receive do 2 | def wait_for_messages do 3 | receive do 4 | {:basic_deliver, payload, _meta} -> 5 | IO.puts " [x] Received #{payload}" 6 | wait_for_messages() 7 | end 8 | end 9 | end 10 | 11 | {:ok, connection} = AMQP.Connection.open 12 | {:ok, channel} = AMQP.Channel.open(connection) 13 | AMQP.Queue.declare(channel, "hello") 14 | AMQP.Basic.consume(channel, "hello", nil, no_ack: true) 15 | IO.puts " [*] Waiting for messages. To exit press CTRL+C, CTRL+C" 16 | 17 | Receive.wait_for_messages() 18 | -------------------------------------------------------------------------------- /elixir/receive_logs.exs: -------------------------------------------------------------------------------- 1 | defmodule ReceiveLogs do 2 | def wait_for_messages(channel) do 3 | receive do 4 | {:basic_deliver, payload, _meta} -> 5 | IO.puts " [x] Received #{payload}" 6 | 7 | wait_for_messages(channel) 8 | end 9 | end 10 | end 11 | 12 | {:ok, connection} = AMQP.Connection.open 13 | {:ok, channel} = AMQP.Channel.open(connection) 14 | 15 | AMQP.Exchange.declare(channel, "logs", :fanout) 16 | {:ok, %{queue: queue_name}} = AMQP.Queue.declare(channel, "", exclusive: true) 17 | AMQP.Queue.bind(channel, queue_name, "logs") 18 | AMQP.Basic.consume(channel, queue_name, nil, no_ack: true) 19 | IO.puts " [*] Waiting for messages. To exit press CTRL+C, CTRL+C" 20 | 21 | ReceiveLogs.wait_for_messages(channel) 22 | -------------------------------------------------------------------------------- /elixir/receive_logs_direct.exs: -------------------------------------------------------------------------------- 1 | defmodule ReceiveLogsDirect do 2 | def wait_for_messages(channel) do 3 | receive do 4 | {:basic_deliver, payload, meta} -> 5 | IO.puts " [x] Received [#{meta.routing_key}] #{payload}" 6 | 7 | wait_for_messages(channel) 8 | end 9 | end 10 | end 11 | 12 | {:ok, connection} = AMQP.Connection.open 13 | {:ok, channel} = AMQP.Channel.open(connection) 14 | 15 | {severities, _, _} = 16 | System.argv 17 | |> OptionParser.parse(strict: [info: :boolean, 18 | warning: :boolean, 19 | error: :boolean]) 20 | 21 | AMQP.Exchange.declare(channel, "direct_logs", :direct) 22 | 23 | {:ok, %{queue: queue_name}} = AMQP.Queue.declare(channel, "", exclusive: true) 24 | 25 | for {severity, true} <- severities do 26 | binding_key = severity |> to_string 27 | AMQP.Queue.bind(channel, queue_name, "direct_logs", routing_key: binding_key) 28 | end 29 | 30 | AMQP.Basic.consume(channel, queue_name, nil, no_ack: true) 31 | 32 | IO.puts " [*] Waiting for messages. To exist press CTRL+C, CTRL+C" 33 | 34 | 35 | ReceiveLogsDirect.wait_for_messages(channel) 36 | -------------------------------------------------------------------------------- /elixir/receive_logs_topic.exs: -------------------------------------------------------------------------------- 1 | defmodule ReceiveLogsTopic do 2 | def wait_for_messages(channel) do 3 | receive do 4 | {:basic_deliver, payload, meta} -> 5 | IO.puts " [x] Received [#{meta.routing_key}] #{payload}" 6 | 7 | wait_for_messages(channel) 8 | end 9 | end 10 | end 11 | 12 | {:ok, connection} = AMQP.Connection.open 13 | {:ok, channel} = AMQP.Channel.open(connection) 14 | 15 | AMQP.Exchange.declare(channel, "topic_logs", :topic) 16 | 17 | {:ok, %{queue: queue_name}} = AMQP.Queue.declare(channel, "", exclusive: true) 18 | 19 | if length(System.argv) == 0 do 20 | IO.puts "Usage: mix run receive_logs_topic.exs [binding_key]..." 21 | System.halt(1) 22 | end 23 | for binding_key <- System.argv do 24 | AMQP.Queue.bind(channel, queue_name, "topic_logs", routing_key: binding_key) 25 | end 26 | 27 | AMQP.Basic.consume(channel, queue_name, nil, no_ack: true) 28 | 29 | IO.puts " [*] Waiting for messages. To exist press CTRL+C, CTRL+C" 30 | 31 | ReceiveLogsTopic.wait_for_messages(channel) 32 | -------------------------------------------------------------------------------- /elixir/rpc_client.exs: -------------------------------------------------------------------------------- 1 | defmodule FibonacciRpcClient do 2 | def wait_for_messages(_channel, correlation_id) do 3 | receive do 4 | {:basic_deliver, payload, %{correlation_id: ^correlation_id}} -> 5 | {n, _} = Integer.parse(payload) 6 | n 7 | end 8 | end 9 | def call(n) do 10 | {:ok, connection} = AMQP.Connection.open 11 | {:ok, channel} = AMQP.Channel.open(connection) 12 | 13 | {:ok, %{queue: queue_name}} = AMQP.Queue.declare(channel, "", exclusive: true) 14 | AMQP.Basic.consume(channel, queue_name, nil, no_ack: true) 15 | correlation_id = :erlang.unique_integer |> :erlang.integer_to_binary |> Base.encode64 16 | request = to_string(n) 17 | AMQP.Basic.publish(channel, "", "rpc_queue", request, reply_to: queue_name, correlation_id: correlation_id) 18 | 19 | FibonacciRpcClient.wait_for_messages(channel, correlation_id) 20 | end 21 | end 22 | 23 | num = 24 | case System.argv do 25 | [] -> 30 26 | param -> 27 | {x, _} = 28 | param 29 | |> Enum.join(" ") 30 | |> Integer.parse 31 | x 32 | end 33 | 34 | IO.puts " [x] Requesting fib(#{num})" 35 | response = FibonacciRpcClient.call(num) 36 | IO.puts " [.] Got #{response}" 37 | -------------------------------------------------------------------------------- /elixir/rpc_server.exs: -------------------------------------------------------------------------------- 1 | defmodule FibServer do 2 | def fib(0), do: 0 3 | def fib(1), do: 1 4 | def fib(n) when n > 1, do: fib(n-1) + fib(n-2) 5 | 6 | def wait_for_messages(channel) do 7 | receive do 8 | {:basic_deliver, payload, meta} -> 9 | {n, _} = Integer.parse(payload) 10 | IO.puts " [.] fib(#{n})" 11 | response = fib(n) 12 | 13 | AMQP.Basic.publish(channel, "", meta.reply_to, "#{response}", correlation_id: meta.correlation_id) 14 | AMQP.Basic.ack(channel, meta.delivery_tag) 15 | 16 | wait_for_messages(channel) 17 | end 18 | end 19 | end 20 | 21 | {:ok, connection} = AMQP.Connection.open 22 | {:ok, channel} = AMQP.Channel.open(connection) 23 | 24 | AMQP.Queue.declare(channel, "rpc_queue") 25 | 26 | AMQP.Basic.qos(channel, prefetch_count: 1) 27 | 28 | AMQP.Basic.consume(channel, "rpc_queue") 29 | 30 | IO.puts " [x] Awaiting RPC requests" 31 | 32 | FibServer.wait_for_messages(channel) 33 | 34 | -------------------------------------------------------------------------------- /elixir/send.exs: -------------------------------------------------------------------------------- 1 | {:ok, connection} = AMQP.Connection.open 2 | {:ok, channel} = AMQP.Channel.open(connection) 3 | AMQP.Queue.declare(channel, "hello") 4 | AMQP.Basic.publish(channel, "", "hello", "Hello World!") 5 | IO.puts " [x] Sent 'Hello World!'" 6 | AMQP.Connection.close(connection) 7 | -------------------------------------------------------------------------------- /elixir/worker.exs: -------------------------------------------------------------------------------- 1 | defmodule Worker do 2 | def wait_for_messages(channel) do 3 | receive do 4 | {:basic_deliver, payload, meta} -> 5 | IO.puts " [x] Received #{payload}" 6 | payload 7 | |> to_charlist 8 | |> Enum.count(fn x -> x == ?. end) 9 | |> Kernel.*(1000) 10 | |> :timer.sleep 11 | IO.puts " [x] Done." 12 | AMQP.Basic.ack(channel, meta.delivery_tag) 13 | 14 | wait_for_messages(channel) 15 | end 16 | end 17 | end 18 | 19 | {:ok, connection} = AMQP.Connection.open 20 | {:ok, channel} = AMQP.Channel.open(connection) 21 | 22 | AMQP.Queue.declare(channel, "task_queue", durable: true) 23 | AMQP.Basic.qos(channel, prefetch_count: 1) 24 | 25 | AMQP.Basic.consume(channel, "task_queue") 26 | IO.puts " [*] Waiting for messages. To exit press CTRL+C, CTRL+C" 27 | 28 | Worker.wait_for_messages(channel) 29 | -------------------------------------------------------------------------------- /erlang/.gitignore: -------------------------------------------------------------------------------- 1 | .rebar3 2 | _build 3 | _checkouts 4 | _vendor 5 | .eunit 6 | *.o 7 | *.beam 8 | *.plt 9 | *.swp 10 | *.swo 11 | .erlang.cookie 12 | ebin 13 | log 14 | erl_crash.dump 15 | .rebar 16 | logs 17 | .idea 18 | *.iml 19 | rebar3.crashdump 20 | *~ 21 | -------------------------------------------------------------------------------- /erlang/src/emit_log.erl: -------------------------------------------------------------------------------- 1 | -module(emit_log). 2 | -export([start/1]). 3 | 4 | -include_lib("amqp_client/include/amqp_client.hrl"). 5 | 6 | start(Argv) -> 7 | {ok, Connection} = 8 | amqp_connection:start(#amqp_params_network{host = "localhost"}), 9 | {ok, Channel} = amqp_connection:open_channel(Connection), 10 | 11 | amqp_channel:call(Channel, #'exchange.declare'{exchange = <<"logs">>, 12 | type = <<"fanout">>}), 13 | 14 | Message = case Argv of 15 | [] -> <<"info: Hello World!">>; 16 | Msg -> list_to_binary(string:join(Msg, " ")) 17 | end, 18 | amqp_channel:cast(Channel, 19 | #'basic.publish'{exchange = <<"logs">>}, 20 | #amqp_msg{payload = Message}), 21 | io:format(" [x] Sent ~p~n", [Message]), 22 | ok = amqp_channel:close(Channel), 23 | ok = amqp_connection:close(Connection), 24 | ok. 25 | -------------------------------------------------------------------------------- /erlang/src/erlang.app.src: -------------------------------------------------------------------------------- 1 | {application, erlang, [ 2 | {description, "An OTP library"}, 3 | {vsn, "0.1.0"}, 4 | {registered, []}, 5 | {applications, [ 6 | kernel, 7 | stdlib 8 | ]}, 9 | {env, []}, 10 | {modules, []}, 11 | {licenses, ["Apache-2.0"]}, 12 | {links, []} 13 | ]}. 14 | -------------------------------------------------------------------------------- /erlang/src/new_task.erl: -------------------------------------------------------------------------------- 1 | -module(new_task). 2 | -export([start/1]). 3 | 4 | -include_lib("amqp_client/include/amqp_client.hrl"). 5 | 6 | start(Argv) -> 7 | {ok, Connection} = 8 | amqp_connection:start(#amqp_params_network{host = "localhost"}), 9 | {ok, Channel} = amqp_connection:open_channel(Connection), 10 | 11 | amqp_channel:call(Channel, #'queue.declare'{queue = <<"task_queue">>, 12 | durable = true}), 13 | 14 | Message = case Argv of 15 | [] -> <<"Hello World!">>; 16 | Msg -> list_to_binary(string:join(Msg, " ")) 17 | end, 18 | amqp_channel:cast(Channel, 19 | #'basic.publish'{ 20 | exchange = <<"">>, 21 | routing_key = <<"task_queue">>}, 22 | #amqp_msg{props = #'P_basic'{delivery_mode = 2}, 23 | payload = Message}), 24 | io:format(" [x] Sent ~p~n", [Message]), 25 | ok = amqp_channel:close(Channel), 26 | ok = amqp_connection:close(Connection), 27 | ok. 28 | -------------------------------------------------------------------------------- /erlang/src/receive_logs.erl: -------------------------------------------------------------------------------- 1 | -module(receive_logs). 2 | -export([start/0]). 3 | 4 | -include_lib("amqp_client/include/amqp_client.hrl"). 5 | 6 | start() -> 7 | {ok, Connection} = 8 | amqp_connection:start(#amqp_params_network{host = "localhost"}), 9 | {ok, Channel} = amqp_connection:open_channel(Connection), 10 | 11 | amqp_channel:call(Channel, #'exchange.declare'{exchange = <<"logs">>, 12 | type = <<"fanout">>}), 13 | 14 | #'queue.declare_ok'{queue = Queue} = 15 | amqp_channel:call(Channel, #'queue.declare'{exclusive = true}), 16 | 17 | amqp_channel:call(Channel, #'queue.bind'{exchange = <<"logs">>, 18 | queue = Queue}), 19 | 20 | io:format(" [*] Waiting for logs. To exit press CTRL+C~n"), 21 | 22 | amqp_channel:subscribe(Channel, #'basic.consume'{queue = Queue, 23 | no_ack = true}, self()), 24 | receive 25 | #'basic.consume_ok'{} -> ok 26 | end, 27 | loop(Channel). 28 | 29 | loop(Channel) -> 30 | receive 31 | {#'basic.deliver'{}, #amqp_msg{payload = Body}} -> 32 | io:format(" [x] ~p~n", [Body]), 33 | loop(Channel) 34 | end. 35 | -------------------------------------------------------------------------------- /erlang/src/recv.erl: -------------------------------------------------------------------------------- 1 | -module(recv). 2 | -export([start/0]). 3 | 4 | -include_lib("amqp_client/include/amqp_client.hrl"). 5 | 6 | start() -> 7 | {ok, Connection} = 8 | amqp_connection:start(#amqp_params_network{host = "localhost", heartbeat = 30}), 9 | {ok, Channel} = amqp_connection:open_channel(Connection), 10 | 11 | amqp_channel:call(Channel, #'queue.declare'{queue = <<"hello">>}), 12 | io:format(" [*] Waiting for messages. To exit press CTRL+C~n"), 13 | 14 | Method = #'basic.consume'{queue = <<"hello">>, no_ack = true}, 15 | amqp_channel:subscribe(Channel, Method, self()), 16 | loop(Channel). 17 | 18 | loop(Channel) -> 19 | receive 20 | #'basic.consume_ok'{} -> 21 | io:format(" [x] Saw basic.consume_ok~n"), 22 | loop(Channel); 23 | {#'basic.deliver'{}, #amqp_msg{payload = Body}} -> 24 | io:format(" [x] Received ~p~n", [Body]), 25 | loop(Channel) 26 | end. 27 | -------------------------------------------------------------------------------- /erlang/src/send.erl: -------------------------------------------------------------------------------- 1 | -module(send). 2 | -export([start/0]). 3 | 4 | -include_lib("amqp_client/include/amqp_client.hrl"). 5 | 6 | start() -> 7 | {ok, Connection} = 8 | amqp_connection:start(#amqp_params_network{host = "localhost"}), 9 | {ok, Channel} = amqp_connection:open_channel(Connection), 10 | 11 | amqp_channel:call(Channel, #'queue.declare'{queue = <<"hello">>}), 12 | 13 | amqp_channel:cast(Channel, 14 | #'basic.publish'{ 15 | exchange = <<"">>, 16 | routing_key = <<"hello">>}, 17 | #amqp_msg{payload = <<"Hello World!">>}), 18 | io:format(" [x] Sent 'Hello World!'~n"), 19 | ok = amqp_channel:close(Channel), 20 | ok = amqp_connection:close(Connection), 21 | ok. 22 | -------------------------------------------------------------------------------- /go-stream/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rabbitmq/rabbitmq-tutorials 2 | 3 | go 1.22.0 4 | 5 | require github.com/rabbitmq/rabbitmq-stream-go-client v1.4.6 6 | 7 | require ( 8 | github.com/golang/snappy v0.0.4 // indirect 9 | github.com/klauspost/compress v1.17.9 // indirect 10 | github.com/pierrec/lz4 v2.6.1+incompatible // indirect 11 | github.com/pkg/errors v0.9.1 // indirect 12 | github.com/spaolacci/murmur3 v1.1.0 // indirect 13 | ) 14 | -------------------------------------------------------------------------------- /go-stream/send.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp" 7 | "github.com/rabbitmq/rabbitmq-stream-go-client/pkg/stream" 8 | "os" 9 | ) 10 | 11 | func CheckErrSend(err error) { 12 | if err != nil { 13 | fmt.Printf("%s ", err) 14 | os.Exit(1) 15 | } 16 | } 17 | func main() { 18 | env, err := stream.NewEnvironment( 19 | stream.NewEnvironmentOptions(). 20 | SetHost("localhost"). 21 | SetPort(5552). 22 | SetUser("guest"). 23 | SetPassword("guest")) 24 | CheckErrSend(err) 25 | 26 | streamName := "hello-go-stream" 27 | err = env.DeclareStream(streamName, 28 | &stream.StreamOptions{ 29 | MaxLengthBytes: stream.ByteCapacity{}.GB(2), 30 | }, 31 | ) 32 | CheckErrSend(err) 33 | 34 | producer, err := env.NewProducer(streamName, stream.NewProducerOptions()) 35 | CheckErrSend(err) 36 | 37 | // Send a message 38 | err = producer.Send(amqp.NewMessage([]byte("Hello world"))) 39 | CheckErrSend(err) 40 | fmt.Printf(" [x] 'Hello world' Message sent\n") 41 | 42 | reader := bufio.NewReader(os.Stdin) 43 | fmt.Println(" [x] Press enter to close the producer") 44 | _, _ = reader.ReadString('\n') 45 | err = producer.Close() 46 | CheckErrSend(err) 47 | } 48 | -------------------------------------------------------------------------------- /go/.gitignore: -------------------------------------------------------------------------------- 1 | pkg/* 2 | src/* 3 | 4 | -------------------------------------------------------------------------------- /go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rabbitmq/rabbitmq-tutorials 2 | 3 | go 1.17 4 | 5 | require github.com/rabbitmq/amqp091-go v1.9.0 6 | -------------------------------------------------------------------------------- /haskell/emitLog.hs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env stack 2 | {- stack --install-ghc 3 | runghc 4 | --package amqp 5 | --package bytestring 6 | -} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | 9 | import Network.AMQP 10 | import qualified Data.ByteString.Lazy.Char8 as BL 11 | import Data.Monoid ((<>)) 12 | import System.Environment (getArgs) 13 | 14 | logsExchange = "logs" 15 | 16 | main :: IO () 17 | main = do 18 | args <- getArgs 19 | let body = bodyFor args 20 | conn <- openConnection "127.0.0.1" "/" "guest" "guest" 21 | ch <- openChannel conn 22 | 23 | declareExchange ch newExchange {exchangeName = logsExchange, 24 | exchangeType = "fanout", 25 | exchangeDurable = False} 26 | publishMsg ch logsExchange "" 27 | (newMsg {msgBody = body, 28 | msgDeliveryMode = Just NonPersistent}) 29 | 30 | BL.putStrLn $ " [x] Sent " <> body 31 | closeConnection conn 32 | 33 | bodyFor :: [String] -> BL.ByteString 34 | bodyFor [] = "Hello, world!" 35 | bodyFor xs = BL.pack . unwords $ xs 36 | -------------------------------------------------------------------------------- /haskell/newTask.hs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env stack 2 | {- stack --install-ghc 3 | runghc 4 | --package amqp 5 | --package bytestring 6 | -} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | 9 | import Network.AMQP 10 | 11 | import qualified Data.ByteString.Lazy.Char8 as BL 12 | import Data.Monoid ((<>)) 13 | import System.Environment (getArgs) 14 | 15 | main :: IO () 16 | main = do 17 | args <- getArgs 18 | let body = bodyFor args 19 | conn <- openConnection "127.0.0.1" "/" "guest" "guest" 20 | ch <- openChannel conn 21 | 22 | publishMsg ch "" "task_queue" 23 | (newMsg {msgBody = body, 24 | msgDeliveryMode = Just Persistent}) 25 | 26 | BL.putStrLn $ " [x] Sent " <> body 27 | closeConnection conn 28 | 29 | bodyFor :: [String] -> BL.ByteString 30 | bodyFor [] = "Hello, world!" 31 | bodyFor xs = BL.pack . unwords $ xs 32 | -------------------------------------------------------------------------------- /haskell/receive.hs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env stack 2 | {- stack --install-ghc 3 | runghc 4 | --package amqp 5 | -} 6 | {-# LANGUAGE OverloadedStrings #-} 7 | 8 | import Network.AMQP 9 | 10 | import qualified Data.ByteString.Lazy.Char8 as BL 11 | import Data.Monoid ((<>)) 12 | 13 | main :: IO () 14 | main = do 15 | conn <- openConnection "127.0.0.1" "/" "guest" "guest" 16 | ch <- openChannel conn 17 | 18 | declareQueue ch newQueue {queueName = "hello", 19 | queueAutoDelete = False, 20 | queueDurable = False} 21 | 22 | putStrLn " [*] Waiting for messages. To exit press CTRL+C" 23 | consumeMsgs ch "hello" NoAck deliveryHandler 24 | 25 | -- waits for keypresses 26 | getLine 27 | closeConnection conn 28 | 29 | deliveryHandler :: (Message, Envelope) -> IO () 30 | deliveryHandler (msg, metadata) = 31 | BL.putStrLn $ " [x] Received " <> msgBody msg 32 | -------------------------------------------------------------------------------- /haskell/send.hs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env stack 2 | {- stack --install-ghc 3 | runghc 4 | --package amqp 5 | --package bytestring 6 | -} 7 | {-# LANGUAGE OverloadedStrings #-} 8 | 9 | import Network.AMQP 10 | 11 | import qualified Data.ByteString.Lazy.Char8 as BL 12 | 13 | main :: IO () 14 | main = do 15 | conn <- openConnection "127.0.0.1" "/" "guest" "guest" 16 | ch <- openChannel conn 17 | 18 | declareQueue ch newQueue {queueName = "hello", 19 | queueAutoDelete = False, 20 | queueDurable = False} 21 | 22 | publishMsg ch "" "hello" 23 | (newMsg {msgBody = "Hello World!", 24 | msgDeliveryMode = Just NonPersistent}) 25 | 26 | BL.putStrLn " [x] Sent 'Hello World!'" 27 | closeConnection conn 28 | -------------------------------------------------------------------------------- /java-gradle/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### IntelliJ IDEA ### 8 | .idea/ 9 | *.iws 10 | *.iml 11 | *.ipr 12 | out/ 13 | !**/src/main/**/out/ 14 | !**/src/test/**/out/ 15 | 16 | ### Eclipse ### 17 | .apt_generated 18 | .classpath 19 | .factorypath 20 | .project 21 | .settings 22 | .springBeans 23 | .sts4-cache 24 | bin/ 25 | !**/src/main/**/bin/ 26 | !**/src/test/**/bin/ 27 | 28 | ### NetBeans ### 29 | /nbproject/private/ 30 | /nbbuild/ 31 | /dist/ 32 | /nbdist/ 33 | /.nb-gradle/ 34 | 35 | ### VS Code ### 36 | .vscode/ 37 | 38 | ### Mac OS ### 39 | .DS_Store 40 | -------------------------------------------------------------------------------- /java-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | } 4 | 5 | group 'com.rabbitmq.client' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation 'com.rabbitmq:amqp-client:5.25.0' 14 | implementation 'org.slf4j:slf4j-simple:2.0.17' 15 | testImplementation 'org.assertj:assertj-core:3.27.3' 16 | testImplementation 'org.mockito:mockito-core:5.18.0' 17 | testImplementation 'io.dropwizard.metrics:metrics-core:4.2.32' 18 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.13.0' 19 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.13.0' 20 | } 21 | 22 | test { 23 | useJUnitPlatform() 24 | } 25 | 26 | application { 27 | mainClassName = project.hasProperty("main") ? 28 | project.getProperty("main") : "NULL" 29 | } -------------------------------------------------------------------------------- /java-gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/java-gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /java-gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /java-gradle/pull-source-files.bat: -------------------------------------------------------------------------------- 1 | copy ..\java\*.java src\main\java\ -------------------------------------------------------------------------------- /java-gradle/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rabbitmq-tutorials' 2 | 3 | -------------------------------------------------------------------------------- /java-gradle/src/main/java/EmitLog.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLog.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/EmitLogDirect.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogDirect.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/EmitLogHeader.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogHeader.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/EmitLogTopic.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogTopic.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/NewTask.java: -------------------------------------------------------------------------------- 1 | ../../../../java/NewTask.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/PublisherConfirms.java: -------------------------------------------------------------------------------- 1 | ../../../../java/PublisherConfirms.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/RPCClient.java: -------------------------------------------------------------------------------- 1 | ../../../../java/RPCClient.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/RPCServer.java: -------------------------------------------------------------------------------- 1 | ../../../../java/RPCServer.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/ReceiveLogHeader.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogHeader.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/ReceiveLogs.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogs.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/ReceiveLogsDirect.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogsDirect.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/ReceiveLogsTopic.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogsTopic.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/Recv.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Recv.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/Send.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Send.java -------------------------------------------------------------------------------- /java-gradle/src/main/java/Worker.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Worker.java -------------------------------------------------------------------------------- /java-mvn/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/java-mvn/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /java-mvn/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /java-mvn/pull-source-files.bat: -------------------------------------------------------------------------------- 1 | copy ..\java\*.java src\main\java\ -------------------------------------------------------------------------------- /java-mvn/src/main/java/EmitLog.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLog.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/EmitLogDirect.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogDirect.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/EmitLogHeader.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogHeader.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/EmitLogTopic.java: -------------------------------------------------------------------------------- 1 | ../../../../java/EmitLogTopic.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/NewTask.java: -------------------------------------------------------------------------------- 1 | ../../../../java/NewTask.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/PublisherConfirms.java: -------------------------------------------------------------------------------- 1 | ../../../../java/PublisherConfirms.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/RPCClient.java: -------------------------------------------------------------------------------- 1 | ../../../../java/RPCClient.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/RPCServer.java: -------------------------------------------------------------------------------- 1 | ../../../../java/RPCServer.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/ReceiveLogHeader.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogHeader.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/ReceiveLogs.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogs.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/ReceiveLogsDirect.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogsDirect.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/ReceiveLogsTopic.java: -------------------------------------------------------------------------------- 1 | ../../../../java/ReceiveLogsTopic.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/Recv.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Recv.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/Send.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Send.java -------------------------------------------------------------------------------- /java-mvn/src/main/java/Worker.java: -------------------------------------------------------------------------------- 1 | ../../../../java/Worker.java -------------------------------------------------------------------------------- /java-stream-mvn/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | rmq-conf/ 3 | 4 | !.mvn/wrapper/maven-wrapper.jar 5 | !**/src/main/**/target/ 6 | !**/src/test/**/target/ 7 | 8 | ### IntelliJ IDEA ### 9 | .idea/modules.xml 10 | .idea/jarRepositories.xml 11 | .idea/compiler.xml 12 | .idea/libraries/ 13 | *.iws 14 | *.iml 15 | *.ipr 16 | 17 | ### Eclipse ### 18 | .apt_generated 19 | .classpath 20 | .factorypath 21 | .project 22 | .settings 23 | .springBeans 24 | .sts4-cache 25 | 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | build/ 33 | !**/src/main/**/build/ 34 | !**/src/test/**/build/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | 39 | ### Mac OS ### 40 | .DS_Store 41 | -------------------------------------------------------------------------------- /java-stream-mvn/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/java-stream-mvn/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /java-stream-mvn/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /java-stream-mvn/src/main/java/Receive.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.stream.ByteCapacity; 2 | import com.rabbitmq.stream.Consumer; 3 | import com.rabbitmq.stream.Environment; 4 | import com.rabbitmq.stream.OffsetSpecification; 5 | 6 | import java.io.IOException; 7 | 8 | public class Receive { 9 | 10 | public static void main(String[] args) throws IOException { 11 | Environment environment = Environment.builder().build(); 12 | String stream = "hello-java-stream"; 13 | environment.streamCreator().stream(stream).maxLengthBytes(ByteCapacity.GB(5)).create(); 14 | 15 | Consumer consumer = environment.consumerBuilder() 16 | .stream(stream) 17 | .offset(OffsetSpecification.first()) 18 | .messageHandler((unused, message) -> { 19 | System.out.println("Received message: " + new String(message.getBodyAsBinary())); 20 | }).build(); 21 | 22 | System.out.println(" [x] Press Enter to close the consumer..."); 23 | System.in.read(); 24 | consumer.close(); 25 | environment.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java-stream-mvn/src/main/java/Send.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.stream.*; 2 | import java.io.IOException; 3 | 4 | public class Send { 5 | 6 | public static void main(String[] args) throws IOException { 7 | Environment environment = Environment.builder().build(); 8 | String stream = "hello-java-stream"; 9 | environment.streamCreator().stream(stream).maxLengthBytes(ByteCapacity.GB(5)).create(); 10 | 11 | Producer producer = environment.producerBuilder().stream(stream).build(); 12 | producer.send(producer.messageBuilder().addData("Hello, World!".getBytes()).build(), null); 13 | System.out.println(" [x] 'Hello, World!' message sent"); 14 | 15 | System.out.println(" [x] Press Enter to close the producer..."); 16 | System.in.read(); 17 | producer.close(); 18 | environment.close(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java-stream-mvn/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /java/EmitLog.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.BuiltinExchangeType; 2 | import com.rabbitmq.client.Channel; 3 | import com.rabbitmq.client.Connection; 4 | import com.rabbitmq.client.ConnectionFactory; 5 | 6 | public class EmitLog { 7 | 8 | private static final String EXCHANGE_NAME = "logs"; 9 | 10 | public static void main(String[] argv) throws Exception { 11 | ConnectionFactory factory = new ConnectionFactory(); 12 | factory.setHost("localhost"); 13 | try (Connection connection = factory.newConnection(); 14 | Channel channel = connection.createChannel()) { 15 | channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT); 16 | 17 | String message = argv.length < 1 ? "info: Hello World!" : 18 | String.join(" ", argv); 19 | 20 | channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8")); 21 | System.out.println(" [x] Sent '" + message + "'"); 22 | } 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /java/NewTask.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.Channel; 2 | import com.rabbitmq.client.Connection; 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import com.rabbitmq.client.MessageProperties; 5 | 6 | public class NewTask { 7 | 8 | private static final String TASK_QUEUE_NAME = "task_queue"; 9 | 10 | public static void main(String[] argv) throws Exception { 11 | ConnectionFactory factory = new ConnectionFactory(); 12 | factory.setHost("localhost"); 13 | try (Connection connection = factory.newConnection(); 14 | Channel channel = connection.createChannel()) { 15 | channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); 16 | 17 | String message = String.join(" ", argv); 18 | 19 | channel.basicPublish("", TASK_QUEUE_NAME, 20 | MessageProperties.PERSISTENT_TEXT_PLAIN, 21 | message.getBytes("UTF-8")); 22 | System.out.println(" [x] Sent '" + message + "'"); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /java/ReceiveLogs.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.*; 2 | 3 | public class ReceiveLogs { 4 | private static final String EXCHANGE_NAME = "logs"; 5 | 6 | public static void main(String[] argv) throws Exception { 7 | ConnectionFactory factory = new ConnectionFactory(); 8 | factory.setHost("localhost"); 9 | Connection connection = factory.newConnection(); 10 | Channel channel = connection.createChannel(); 11 | 12 | channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT); 13 | String queueName = channel.queueDeclare().getQueue(); 14 | channel.queueBind(queueName, EXCHANGE_NAME, ""); 15 | 16 | System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); 17 | 18 | DeliverCallback deliverCallback = (consumerTag, delivery) -> { 19 | String message = new String(delivery.getBody(), "UTF-8"); 20 | System.out.println(" [x] Received '" + message + "'"); 21 | }; 22 | channel.basicConsume(queueName, true, deliverCallback, consumerTag -> { }); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /java/Recv.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.Channel; 2 | import com.rabbitmq.client.Connection; 3 | import com.rabbitmq.client.ConnectionFactory; 4 | import com.rabbitmq.client.DeliverCallback; 5 | import java.nio.charset.StandardCharsets; 6 | 7 | public class Recv { 8 | 9 | private final static String QUEUE_NAME = "hello"; 10 | 11 | public static void main(String[] argv) throws Exception { 12 | ConnectionFactory factory = new ConnectionFactory(); 13 | factory.setHost("localhost"); 14 | Connection connection = factory.newConnection(); 15 | Channel channel = connection.createChannel(); 16 | 17 | channel.queueDeclare(QUEUE_NAME, false, false, false, null); 18 | System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); 19 | 20 | DeliverCallback deliverCallback = (consumerTag, delivery) -> { 21 | String message = new String(delivery.getBody(), StandardCharsets.UTF_8); 22 | System.out.println(" [x] Received '" + message + "'"); 23 | }; 24 | channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> { }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/Send.java: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.Channel; 2 | import com.rabbitmq.client.Connection; 3 | import com.rabbitmq.client.ConnectionFactory; 4 | 5 | import java.nio.charset.StandardCharsets; 6 | 7 | public class Send { 8 | 9 | private final static String QUEUE_NAME = "hello"; 10 | 11 | public static void main(String[] argv) throws Exception { 12 | ConnectionFactory factory = new ConnectionFactory(); 13 | factory.setHost("localhost"); 14 | try (Connection connection = factory.newConnection(); 15 | Channel channel = connection.createChannel()) { 16 | channel.queueDeclare(QUEUE_NAME, false, false, false, null); 17 | String message = "Hello World!"; 18 | channel.basicPublish("", QUEUE_NAME, null, message.getBytes(StandardCharsets.UTF_8)); 19 | System.out.println(" [x] Sent '" + message + "'"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /java/recompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | javac -cp .:amqp-client-5.21.0.jar:slf4j-api-2.0.13.jar:slf4j-simple-2.0.13.jar *.java 4 | -------------------------------------------------------------------------------- /javascript-nodejs-stream/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /javascript-nodejs-stream/offset_tracking_send.js: -------------------------------------------------------------------------------- 1 | const rabbit = require("rabbitmq-stream-js-client"); 2 | 3 | async function main() { 4 | console.log("Connecting..."); 5 | const client = await rabbit.connect({ 6 | vhost: "/", 7 | port: 5552, 8 | hostname: "localhost", 9 | username: "guest", 10 | password: "guest", 11 | }); 12 | 13 | console.log("Making sure the stream exists..."); 14 | const streamName = "stream-offset-tracking-javascript"; 15 | await client.createStream({ stream: streamName, arguments: {} }); 16 | 17 | console.log("Creating the publisher..."); 18 | const publisher = await client.declarePublisher({ stream: streamName }); 19 | 20 | const messageCount = 100; 21 | console.log(`Publishing ${messageCount} messages`); 22 | for (let i = 0; i < messageCount; i++) { 23 | const body = i === messageCount - 1 ? "marker" : `hello ${i}`; 24 | await publisher.send(Buffer.from(body)); 25 | } 26 | 27 | console.log("Closing the connection..."); 28 | await client.close(); 29 | } 30 | 31 | main() 32 | .then(() => console.log("done!")) 33 | .catch((res) => { 34 | console.log("Error in publishing message!", res); 35 | process.exit(-1); 36 | }); 37 | -------------------------------------------------------------------------------- /javascript-nodejs-stream/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rabbitmq-stream-node-tutorial", 3 | "version": "1.0.0", 4 | "description": "Tutorial for the nodejs RabbitMQ stream client", 5 | "scripts": { 6 | "offset-tracking-publish": "node offset_tracking_send.js", 7 | "offset-tracking-receive": "node offset_tracking_receive.js", 8 | "send": "node send.js", 9 | "receive": "node receive.js" 10 | }, 11 | "dependencies": { 12 | "rabbitmq-stream-js-client": "^0.4.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /javascript-nodejs-stream/receive.js: -------------------------------------------------------------------------------- 1 | const rabbit = require("rabbitmq-stream-js-client") 2 | 3 | async function main() { 4 | const streamName = "hello-nodejs-stream" 5 | 6 | console.log("Connecting..."); 7 | const client = await rabbit.connect({ 8 | hostname: "localhost", 9 | port: 5552, 10 | username: "guest", 11 | password: "guest", 12 | vhost: "/", 13 | }) 14 | 15 | console.log("Making sure the stream exists..."); 16 | const streamSizeRetention = 5 * 1e9 17 | await client.createStream({ stream: streamName, arguments: { "max-length-bytes": streamSizeRetention } }); 18 | 19 | console.log("Declaring the consumer with offset..."); 20 | await client.declareConsumer({ stream: streamName, offset: rabbit.Offset.first() }, (message) => { 21 | console.log(`Received message ${message.content.toString()}`) 22 | }) 23 | 24 | } 25 | 26 | main() 27 | .then(async () => { 28 | await new Promise(function () { }) 29 | }) 30 | .catch((res) => { 31 | console.log("Error while receiving message!", res) 32 | process.exit(-1) 33 | }) 34 | -------------------------------------------------------------------------------- /javascript-nodejs-stream/send.js: -------------------------------------------------------------------------------- 1 | const rabbit = require("rabbitmq-stream-js-client"); 2 | 3 | async function main() { 4 | const streamName = "hello-nodejs-stream"; 5 | 6 | console.log("Connecting..."); 7 | const client = await rabbit.connect({ 8 | vhost: "/", 9 | port: 5552, 10 | hostname: "localhost", 11 | username: "guest", 12 | password: "guest", 13 | }); 14 | 15 | console.log("Making sure the stream exists..."); 16 | const streamSizeRetention = 5 * 1e9 17 | await client.createStream({ stream: streamName, arguments: { "max-length-bytes": streamSizeRetention } }); 18 | 19 | console.log("Creating the publisher..."); 20 | const publisher = await client.declarePublisher({ stream: streamName }); 21 | 22 | console.log("Sending a message..."); 23 | await publisher.send(Buffer.from("Test message")); 24 | 25 | console.log("Closing the connection..."); 26 | await client.close(); 27 | } 28 | 29 | main() 30 | .then(() => console.log("done!")) 31 | .catch((res) => { 32 | console.log("Error in publishing message!", res); 33 | process.exit(-1); 34 | }); 35 | -------------------------------------------------------------------------------- /javascript-nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rabbitmq-node-tutorial", 3 | "version": "1.0.0", 4 | "description": "RabbitMQ amqplib tutorial ", 5 | "dependencies": { 6 | "amqplib": "latest", 7 | "js-beautify": "^1.9.1", 8 | "url-parse": ">=1.5.9" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /javascript-nodejs/src/emit_log.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var exchange = 'logs'; 14 | var msg = process.argv.slice(2).join(' ') || 'Hello World!'; 15 | 16 | channel.assertExchange(exchange, 'fanout', { 17 | durable: false 18 | }); 19 | channel.publish(exchange, '', Buffer.from(msg)); 20 | console.log(" [x] Sent %s", msg); 21 | }); 22 | 23 | setTimeout(function() { 24 | connection.close(); 25 | process.exit(0); 26 | }, 500); 27 | }); 28 | -------------------------------------------------------------------------------- /javascript-nodejs/src/emit_log_direct.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var exchange = 'direct_logs'; 14 | var args = process.argv.slice(2); 15 | var msg = args.slice(1).join(' ') || 'Hello World!'; 16 | var severity = (args.length > 0) ? args[0] : 'info'; 17 | 18 | channel.assertExchange(exchange, 'direct', { 19 | durable: false 20 | }); 21 | channel.publish(exchange, severity, Buffer.from(msg)); 22 | console.log(" [x] Sent %s: '%s'", severity, msg); 23 | }); 24 | 25 | setTimeout(function() { 26 | connection.close(); 27 | process.exit(0); 28 | }, 500); 29 | }); 30 | -------------------------------------------------------------------------------- /javascript-nodejs/src/emit_log_topic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var exchange = 'topic_logs'; 14 | var args = process.argv.slice(2); 15 | var key = (args.length > 0) ? args[0] : 'anonymous.info'; 16 | var msg = args.slice(1).join(' ') || 'Hello World!'; 17 | 18 | channel.assertExchange(exchange, 'topic', { 19 | durable: false 20 | }); 21 | channel.publish(exchange, key, Buffer.from(msg)); 22 | console.log(" [x] Sent %s: '%s'", key, msg); 23 | }); 24 | 25 | setTimeout(function() { 26 | connection.close(); 27 | process.exit(0); 28 | }, 500); 29 | }); 30 | -------------------------------------------------------------------------------- /javascript-nodejs/src/new_task.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var queue = 'task_queue'; 14 | var msg = process.argv.slice(2).join(' ') || "Hello World!"; 15 | 16 | channel.assertQueue(queue, { 17 | durable: true 18 | }); 19 | channel.sendToQueue(queue, Buffer.from(msg), { 20 | persistent: true 21 | }); 22 | console.log(" [x] Sent '%s'", msg); 23 | }); 24 | setTimeout(function() { 25 | connection.close(); 26 | process.exit(0); 27 | }, 500); 28 | }); 29 | -------------------------------------------------------------------------------- /javascript-nodejs/src/receive.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | 14 | var queue = 'hello'; 15 | 16 | channel.assertQueue(queue, { 17 | durable: false 18 | }); 19 | 20 | console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue); 21 | 22 | channel.consume(queue, function(msg) { 23 | console.log(" [x] Received %s", msg.content.toString()); 24 | }, { 25 | noAck: true 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /javascript-nodejs/src/receive_logs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var exchange = 'logs'; 14 | 15 | channel.assertExchange(exchange, 'fanout', { 16 | durable: false 17 | }); 18 | 19 | channel.assertQueue('', { 20 | exclusive: true 21 | }, function(error2, q) { 22 | if (error2) { 23 | throw error2; 24 | } 25 | console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue); 26 | channel.bindQueue(q.queue, exchange, ''); 27 | 28 | channel.consume(q.queue, function(msg) { 29 | if (msg.content) { 30 | console.log(" [x] %s", msg.content.toString()); 31 | } 32 | }, { 33 | noAck: true 34 | }); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /javascript-nodejs/src/rpc_server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | var queue = 'rpc_queue'; 14 | 15 | channel.assertQueue(queue, { 16 | durable: false 17 | }); 18 | channel.prefetch(1); 19 | console.log(' [x] Awaiting RPC requests'); 20 | channel.consume(queue, function reply(msg) { 21 | var n = parseInt(msg.content.toString()); 22 | 23 | console.log(" [.] fib(%d)", n); 24 | 25 | var r = fibonacci(n); 26 | 27 | channel.sendToQueue(msg.properties.replyTo, 28 | Buffer.from(r.toString()), { 29 | correlationId: msg.properties.correlationId 30 | }); 31 | 32 | channel.ack(msg); 33 | }); 34 | }); 35 | }); 36 | 37 | function fibonacci(n) { 38 | if (n === 0 || n === 1) 39 | return n; 40 | else 41 | return fibonacci(n - 1) + fibonacci(n - 2); 42 | } 43 | -------------------------------------------------------------------------------- /javascript-nodejs/src/send.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error0, connection) { 6 | if (error0) { 7 | throw error0; 8 | } 9 | connection.createChannel(function(error1, channel) { 10 | if (error1) { 11 | throw error1; 12 | } 13 | 14 | var queue = 'hello'; 15 | var msg = 'Hello World!'; 16 | 17 | channel.assertQueue(queue, { 18 | durable: false 19 | }); 20 | channel.sendToQueue(queue, Buffer.from(msg)); 21 | 22 | console.log(" [x] Sent %s", msg); 23 | }); 24 | setTimeout(function() { 25 | connection.close(); 26 | process.exit(0); 27 | }, 500); 28 | }); 29 | -------------------------------------------------------------------------------- /javascript-nodejs/src/worker.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var amqp = require('amqplib/callback_api'); 4 | 5 | amqp.connect('amqp://localhost', function(error, connection) { 6 | connection.createChannel(function(error, channel) { 7 | var queue = 'task_queue'; 8 | 9 | channel.assertQueue(queue, { 10 | durable: true 11 | }); 12 | channel.prefetch(1); 13 | console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue); 14 | channel.consume(queue, function(msg) { 15 | var secs = msg.content.toString().split('.').length - 1; 16 | 17 | console.log(" [x] Received %s", msg.content.toString()); 18 | setTimeout(function() { 19 | console.log(" [x] Done"); 20 | channel.ack(msg); 21 | }, secs * 1000); 22 | }, { 23 | noAck: false 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /julia/emit_log.jl: -------------------------------------------------------------------------------- 1 | using AMQPClient 2 | const VIRTUALHOST = "/" 3 | const HOST = "127.0.0.1" 4 | 5 | function send() 6 | # 1. Create a connection to the localhost or 127.0.0.1 of virtualhost '/' 7 | connection(; virtualhost=VIRTUALHOST, host=HOST) do conn 8 | # 2. Create a channel to send messages 9 | channel(conn, AMQPClient.UNUSED_CHANNEL, true) do chan 10 | exchange = "logs" 11 | # 3. Declare the exchange 12 | exchange_declare(chan, exchange, EXCHANGE_TYPE_FANOUT) 13 | if length(Base.ARGS) >= 1 14 | received = join(Base.ARGS, ' ') 15 | else 16 | received = "info: Hello World" 17 | end 18 | 19 | data = convert(Vector{UInt8}, codeunits(received)) 20 | msg = Message(data, content_type="text/plain", delivery_mode=PERSISTENT) 21 | 22 | # 4. Publish message 23 | basic_publish(chan, msg; exchange=exchange, routing_key="") 24 | println("Message sent: $received") 25 | end 26 | end 27 | end 28 | 29 | send() 30 | -------------------------------------------------------------------------------- /julia/emit_log_direct.jl: -------------------------------------------------------------------------------- 1 | using AMQPClient 2 | const VIRTUALHOST = "/" 3 | const HOST = "127.0.0.1" 4 | 5 | 6 | function send() 7 | # 1. Create a connection to the localhost or 127.0.0.1 of virtualhost '/' 8 | connection(; virtualhost=VIRTUALHOST, host=HOST) do conn 9 | # 2. Create a channel to send messages 10 | channel(conn, AMQPClient.UNUSED_CHANNEL, true) do chan 11 | # 3. Declare exchange 12 | exchange = "direct_logs" 13 | exchange_declare(chan, exchange, EXCHANGE_TYPE_DIRECT) 14 | # 4. Get severity and message 15 | if length(Base.ARGS) >= 3 16 | severity = Base.ARGS[1] 17 | received = join(Base.ARGS[2:end], ' ') 18 | else 19 | severity = "info" 20 | received = "Hello World" 21 | end 22 | data = convert(Vector{UInt8}, codeunits(received)) 23 | msg = Message(data, content_type="text/plain", delivery_mode=PERSISTENT) 24 | # 5. Publish the message 25 | basic_publish(chan, msg; exchange=exchange, routing_key=severity) 26 | println("Message sent: $received, Severity: $severity") 27 | end 28 | end 29 | end 30 | 31 | send() 32 | -------------------------------------------------------------------------------- /julia/new_task.jl: -------------------------------------------------------------------------------- 1 | using AMQPClient 2 | const VIRTUALHOST = "/" 3 | const HOST = "127.0.0.1" 4 | 5 | function send() 6 | # 1. Create a connection to the localhost or 127.0.0.1 of virtualhost '/' 7 | connection(; virtualhost=VIRTUALHOST, host=HOST) do conn 8 | # 2. Create a channel to send messages 9 | channel(conn, AMQPClient.UNUSED_CHANNEL, true) do chan 10 | queue = "task_queue" 11 | # 3. Configure the queue 12 | success, queue_name, message_count, consumer_count = queue_declare(chan, queue, durable=true) 13 | 14 | # 4. Prepare the message text 15 | if length(Base.ARGS) >= 1 16 | received = Base.ARGS[1] 17 | else 18 | received = "Hello World" 19 | end 20 | 21 | # 5. Prepare the payload 22 | data = convert(Vector{UInt8}, codeunits(received)) 23 | msg = Message(data, content_type="text/plain", delivery_mode=PERSISTENT) 24 | 25 | # 6. Send the payload 26 | basic_publish(chan, msg; exchange="", routing_key=queue) 27 | println("Message sent: $received") 28 | end 29 | end 30 | end 31 | 32 | send() 33 | -------------------------------------------------------------------------------- /julia/send.jl: -------------------------------------------------------------------------------- 1 | using AMQPClient 2 | const VIRTUALHOST ="/" 3 | const HOST = "127.0.0.1" 4 | 5 | 6 | function send(message) 7 | # 1. Create a connection to the localhost or 127.0.0.1 of virtualhost '/' 8 | connection(; virtualhost=VIRTUALHOST, host=HOST) do conn 9 | # 2. Create a channel to send messages 10 | channel(conn, AMQPClient.UNUSED_CHANNEL, true) do chan 11 | # 3. Declare a queue 12 | success, queue_name, message_count, consumer_count = queue_declare(chan, "hello") 13 | # 4.1 Create a message, AMQPCleint only accepts message in UInt8 14 | data = convert(Vector{UInt8}, codeunits(message)) 15 | msg = Message(data, content_type="text/plain", delivery_mode=PERSISTENT) 16 | # 4.2 Send a message 17 | basic_publish(chan, msg; exchange="", routing_key="hello") 18 | println("Message sent: $message") 19 | # 5. Auto-closes the channel and connection 20 | end 21 | end 22 | end 23 | 24 | send("Hello World!") 25 | -------------------------------------------------------------------------------- /kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | .gradle/* 3 | -------------------------------------------------------------------------------- /kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.8.10' 3 | 4 | repositories { 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 9 | } 10 | } 11 | 12 | group 'com.rabbitmq' 13 | version '1.0-SNAPSHOT' 14 | 15 | apply plugin: 'kotlin' 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 23 | implementation "com.rabbitmq:amqp-client:latest.release" 24 | implementation "org.slf4j:slf4j-simple:1.7.25" 25 | } 26 | 27 | compileKotlin { 28 | kotlinOptions.jvmTarget = "1.8" 29 | } 30 | compileTestKotlin { 31 | kotlinOptions.jvmTarget = "1.8" 32 | } 33 | 34 | task run(type: JavaExec, dependsOn: classes) { 35 | if ("$argv".trim().size() > 0) 36 | args = "$argv".split(",").toList() 37 | if ("$main".trim().size() > 0) 38 | main = "${project.getProperty('main')}Kt" 39 | classpath = sourceSets.main.runtimeClasspath 40 | } -------------------------------------------------------------------------------- /kotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | main = 2 | argv = 3 | -------------------------------------------------------------------------------- /kotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rabbitmq-tutorial' 2 | 3 | -------------------------------------------------------------------------------- /kotlin/src/main/kotlin/ReceiveLogs.kt: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.* 2 | 3 | 4 | class ReceiveLogs { 5 | companion object { 6 | const val EXCHANGE_NAME = "logs" 7 | } 8 | } 9 | 10 | fun main(argv: Array) { 11 | val factory = ConnectionFactory() 12 | factory.host = "localhost" 13 | val connection = factory.newConnection() 14 | val channel = connection.createChannel() 15 | 16 | channel.exchangeDeclare(ReceiveLogs.EXCHANGE_NAME, BuiltinExchangeType.FANOUT) 17 | val queueName = channel.queueDeclare().queue 18 | channel.queueBind(queueName, ReceiveLogs.EXCHANGE_NAME, "") 19 | 20 | println(" [*] Waiting for messages. To exit press CTRL+C") 21 | 22 | val consumer = object : DefaultConsumer(channel) { 23 | override fun handleDelivery(consumerTag: String, envelope: Envelope, 24 | properties: AMQP.BasicProperties, body: ByteArray) { 25 | val message = String(body, charset("UTF-8")) 26 | println(" [x] Received '$message'") 27 | } 28 | } 29 | channel.basicConsume(queueName, true, consumer) 30 | } -------------------------------------------------------------------------------- /kotlin/src/main/kotlin/Recv.kt: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.AMQP 2 | import com.rabbitmq.client.ConnectionFactory 3 | import com.rabbitmq.client.DefaultConsumer 4 | import com.rabbitmq.client.Envelope 5 | 6 | 7 | class Recv { 8 | companion object { 9 | const val QUEUE_NAME = "hello" 10 | } 11 | } 12 | 13 | fun main(argv: Array) { 14 | val factory = ConnectionFactory() 15 | factory.host = "localhost" 16 | val connection = factory.newConnection() 17 | val channel = connection.createChannel() 18 | 19 | channel.queueDeclare(Recv.QUEUE_NAME, false, false, false, null) 20 | println(" [*] Waiting for messages. To exit press CTRL+C") 21 | 22 | val consumer = object : DefaultConsumer(channel) { 23 | override fun handleDelivery(consumerTag: String, envelope: Envelope, properties: AMQP.BasicProperties, body: ByteArray) { 24 | val message = String(body, charset("UTF-8")) 25 | println(" [x] Received '$message'") 26 | } 27 | } 28 | channel.basicConsume(Recv.QUEUE_NAME, true, consumer) 29 | } -------------------------------------------------------------------------------- /kotlin/src/main/kotlin/Send.kt: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.ConnectionFactory 2 | 3 | 4 | class Send { 5 | companion object { 6 | const val QUEUE_NAME = "hello" 7 | } 8 | } 9 | 10 | fun main(argv: Array) { 11 | val factory = ConnectionFactory() 12 | factory.host = "localhost" 13 | val connection = factory.newConnection() 14 | val channel = connection.createChannel() 15 | 16 | channel.queueDeclare(Send.QUEUE_NAME, false, false, false, null) 17 | val message = "Hello World!" 18 | channel.basicPublish("", Send.QUEUE_NAME, null, message.toByteArray(charset("UTF-8"))) 19 | println(" [x] Sent '$message'") 20 | 21 | channel.close() 22 | connection.close() 23 | } -------------------------------------------------------------------------------- /objective-c/.gitignore: -------------------------------------------------------------------------------- 1 | tutorial?/Carthage/Build 2 | tutorial?/Carthage/Checkouts 3 | *xcuserdata* 4 | -------------------------------------------------------------------------------- /objective-c/bump_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | rm -rf ~/Library/Caches/org.carthage.CarthageKit 6 | 7 | for dir in `ls | grep "tutorial[1-9]"` 8 | do 9 | cd $dir 10 | carthage update --platform iOS 11 | carthage copy-frameworks 12 | cd .. 13 | done 14 | -------------------------------------------------------------------------------- /objective-c/tutorial1/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 2 | -------------------------------------------------------------------------------- /objective-c/tutorial1/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "jeffh/JKVValue" "v1.3.3" 2 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 3 | github "robbiehanson/CocoaAsyncSocket" "7.6.4" 4 | -------------------------------------------------------------------------------- /objective-c/tutorial1/tutorial1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial1/tutorial1.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /objective-c/tutorial1/tutorial1/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property (strong, nonatomic) UIWindow *window; 6 | 7 | 8 | @end 9 | 10 | -------------------------------------------------------------------------------- /objective-c/tutorial1/tutorial1/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ViewController : UIViewController 4 | 5 | 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial1/tutorial1/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // tutorial1 4 | // 5 | // Created by Pivotal on 04/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /objective-c/tutorial2/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 2 | -------------------------------------------------------------------------------- /objective-c/tutorial2/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "jeffh/JKVValue" "v1.3.3" 2 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 3 | github "robbiehanson/CocoaAsyncSocket" "7.6.4" 4 | -------------------------------------------------------------------------------- /objective-c/tutorial2/tutorial2.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial2/tutorial2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /objective-c/tutorial2/tutorial2/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property (strong, nonatomic) UIWindow *window; 6 | 7 | 8 | @end 9 | 10 | -------------------------------------------------------------------------------- /objective-c/tutorial2/tutorial2/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ViewController : UIViewController 4 | 5 | 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial2/tutorial2/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // tutorial2 4 | // 5 | // Created by Pivotal on 04/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /objective-c/tutorial3/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 2 | -------------------------------------------------------------------------------- /objective-c/tutorial3/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "jeffh/JKVValue" "v1.3.3" 2 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 3 | github "robbiehanson/CocoaAsyncSocket" "7.6.4" 4 | -------------------------------------------------------------------------------- /objective-c/tutorial3/tutorial3.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial3/tutorial3.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /objective-c/tutorial3/tutorial3/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // tutorial3 4 | // 5 | // Created by Pivotal on 25/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /objective-c/tutorial3/tutorial3/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // tutorial3 4 | // 5 | // Created by Pivotal on 25/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /objective-c/tutorial3/tutorial3/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // tutorial3 4 | // 5 | // Created by Pivotal on 25/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /objective-c/tutorial4/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 2 | -------------------------------------------------------------------------------- /objective-c/tutorial4/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "jeffh/JKVValue" "v1.3.3" 2 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 3 | github "robbiehanson/CocoaAsyncSocket" "7.6.4" 4 | -------------------------------------------------------------------------------- /objective-c/tutorial4/tutorial4.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial4/tutorial4.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /objective-c/tutorial4/tutorial4/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // tutorial4 4 | // 5 | // Created by Pivotal on 25/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /objective-c/tutorial4/tutorial4/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ViewController : UIViewController 4 | 5 | 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial4/tutorial4/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // tutorial4 4 | // 5 | // Created by Pivotal on 25/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /objective-c/tutorial5/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 2 | -------------------------------------------------------------------------------- /objective-c/tutorial5/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "jeffh/JKVValue" "v1.3.3" 2 | github "rabbitmq/rabbitmq-objc-client" "v0.11.0" 3 | github "robbiehanson/CocoaAsyncSocket" "7.6.4" 4 | -------------------------------------------------------------------------------- /objective-c/tutorial5/tutorial5.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial5/tutorial5.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /objective-c/tutorial5/tutorial5/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // tutorial5 4 | // 5 | // Created by Pivotal on 26/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /objective-c/tutorial5/tutorial5/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ViewController : UIViewController 4 | 5 | 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /objective-c/tutorial5/tutorial5/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // tutorial5 4 | // 5 | // Created by Pivotal on 26/04/2016. 6 | // Copyright © 2016 RabbitMQ. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /perl/emit_log.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use Net::RabbitFoot; 8 | 9 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 10 | host => 'localhost', 11 | port => 5672, 12 | user => 'guest', 13 | pass => 'guest', 14 | vhost => '/', 15 | ); 16 | 17 | my $channel = $conn->open_channel(); 18 | 19 | $channel->declare_exchange( 20 | exchange => 'logs', 21 | type => 'fanout', 22 | ); 23 | 24 | my $msg = join(' ', @ARGV) || "info: Hello World!"; 25 | 26 | $channel->publish( 27 | exchange => 'logs', 28 | routing_key => '', 29 | body => $msg, 30 | ); 31 | 32 | print " [x] Sent $msg\n"; 33 | 34 | $conn->close(); 35 | -------------------------------------------------------------------------------- /perl/emit_log_direct.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use Net::RabbitFoot; 8 | 9 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 10 | host => 'localhost', 11 | port => 5672, 12 | user => 'guest', 13 | pass => 'guest', 14 | vhost => '/', 15 | ); 16 | 17 | my $channel = $conn->open_channel(); 18 | 19 | $channel->declare_exchange( 20 | exchange => 'direct_logs', 21 | type => 'direct', 22 | ); 23 | 24 | my $severity = delete $ARGV[0] || 'info'; 25 | my $msg = join(' ', @ARGV[1..$#ARGV]) || 'Hello World!'; 26 | 27 | $channel->publish( 28 | exchange => 'direct_logs', 29 | routing_key => $severity, 30 | body => $msg, 31 | ); 32 | 33 | print " [x] Send $severity: $msg\n"; 34 | 35 | $conn->close(); 36 | -------------------------------------------------------------------------------- /perl/emit_log_topic.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use AnyEvent; 8 | use Net::RabbitFoot; 9 | 10 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 11 | host => 'localhost', 12 | port => 5672, 13 | user => 'guest', 14 | pass => 'guest', 15 | vhost => '/', 16 | ); 17 | 18 | my $channel = $conn->open_channel(); 19 | 20 | $channel->declare_exchange( 21 | exchange => 'topic_logs', 22 | type => 'topic', 23 | ); 24 | 25 | my $routing_key = $ARGV[0] || 'anonymous.info'; 26 | my $msg = join(' ', @ARGV[1..$#ARGV]) || 'Hello World!'; 27 | 28 | $channel->publish( 29 | exchange => 'topic_logs', 30 | routing_key => $routing_key, 31 | body => $msg, 32 | ); 33 | 34 | print " [x] Sent $routing_key:$msg\n"; 35 | 36 | $conn->close(); 37 | 38 | -------------------------------------------------------------------------------- /perl/new_task.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use Net::RabbitFoot; 8 | 9 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 10 | host => 'localhost', 11 | port => 5672, 12 | user => 'guest', 13 | pass => 'guest', 14 | vhost => '/', 15 | ); 16 | 17 | 18 | my $chan = $conn->open_channel(); 19 | 20 | $chan->declare_queue( 21 | queue => 'task_queue', 22 | durable => 1, 23 | ); 24 | 25 | my $msg = join(' ', @ARGV) || "Hello World!"; 26 | 27 | $chan->publish( 28 | exchange => '', 29 | routing_key => 'task_queue', 30 | body => $msg, 31 | ); 32 | 33 | print " [x] Sent '$msg'\n"; 34 | 35 | $conn->close(); 36 | 37 | -------------------------------------------------------------------------------- /perl/receive.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use AnyEvent; 8 | use Net::RabbitFoot; 9 | 10 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 11 | host => 'localhost', 12 | port => 5672, 13 | user => 'guest', 14 | pass => 'guest', 15 | vhost => '/', 16 | ); 17 | 18 | my $ch = $conn->open_channel(); 19 | 20 | $ch->declare_queue(queue => 'hello'); 21 | 22 | print " [*] Waiting for messages. To exit press CTRL-C\n"; 23 | 24 | sub callback { 25 | my $var = shift; 26 | my $body = $var->{body}->{payload}; 27 | print " [x] Received $body\n"; 28 | } 29 | 30 | $ch->consume( 31 | on_consume => \&callback, 32 | no_ack => 1, 33 | ); 34 | 35 | # Wait forever 36 | AnyEvent->condvar->recv; 37 | 38 | -------------------------------------------------------------------------------- /perl/receive_logs.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use AnyEvent; 8 | use Net::RabbitFoot; 9 | 10 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 11 | host => 'localhost', 12 | port => 5672, 13 | user => 'guest', 14 | pass => 'guest', 15 | vhost => '/', 16 | ); 17 | 18 | my $channel = $conn->open_channel(); 19 | 20 | $channel->declare_exchange( 21 | exchange => 'logs', 22 | type => 'fanout', 23 | ); 24 | 25 | my $result = $channel->declare_queue( exclusive => 1, ); 26 | 27 | my $queue_name = $result->{method_frame}->{queue}; 28 | 29 | $channel->bind_queue( 30 | exchange => 'logs', 31 | queue => $queue_name, 32 | ); 33 | 34 | print " [*] Waiting for logs. To exit press CTRL-C\n"; 35 | 36 | sub callback { 37 | my $var = shift; 38 | my $body = $var->{body}->{payload}; 39 | 40 | print " [x] $body\n"; 41 | } 42 | 43 | $channel->consume( 44 | on_consume => \&callback, 45 | queue => $queue_name, 46 | no_ack => 1, 47 | ); 48 | 49 | AnyEvent->condvar->recv; 50 | -------------------------------------------------------------------------------- /perl/send.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use Net::RabbitFoot; 8 | 9 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 10 | host => 'localhost', 11 | port => 5672, 12 | user => 'guest', 13 | pass => 'guest', 14 | vhost => '/', 15 | ); 16 | 17 | 18 | my $chan = $conn->open_channel(); 19 | 20 | $chan->publish( 21 | exchange => '', 22 | routing_key => 'hello', 23 | body => 'Hello World!', 24 | ); 25 | 26 | print " [x] Sent 'Hello World!'\n"; 27 | 28 | $conn->close(); 29 | 30 | -------------------------------------------------------------------------------- /perl/worker.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | $|++; 7 | use Net::RabbitFoot; 8 | 9 | my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( 10 | host => 'localhost', 11 | port => 5672, 12 | user => 'guest', 13 | pass => 'guest', 14 | vhost => '/', 15 | ); 16 | 17 | my $ch = $conn->open_channel(); 18 | 19 | $ch->declare_queue( 20 | queue => 'task_queue', 21 | durable => 1, 22 | ); 23 | 24 | print " [*] Waiting for messages. To exit press CTRL-C\n"; 25 | 26 | sub callback { 27 | my $var = shift; 28 | my $body = $var->{body}->{payload}; 29 | print " [x] Received $body\n"; 30 | 31 | my @c = $body =~ /\./g; 32 | sleep(scalar(@c)); 33 | 34 | print " [x] Done\n"; 35 | $ch->ack(); 36 | } 37 | 38 | $ch->qos(prefetch_count => 1,); 39 | 40 | $ch->consume( 41 | on_consume => \&callback, 42 | no_ack => 0, 43 | ); 44 | 45 | # Wait forever 46 | AnyEvent->condvar->recv; 47 | -------------------------------------------------------------------------------- /php-amqp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/php-amqp/.gitkeep -------------------------------------------------------------------------------- /php-amqp/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/php-amqp/README.md -------------------------------------------------------------------------------- /php-amqp/emit_log.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 6 | $connection->setLogin('guest'); 7 | $connection->setPassword('guest'); 8 | $connection->connect(); 9 | 10 | //Create and declare channel 11 | $channel = new AMQPChannel($connection); 12 | 13 | try { 14 | //Declare Exchange 15 | $exchange_name = 'logs'; 16 | 17 | $exchange = new AMQPExchange($channel); 18 | $exchange->setType(AMQP_EX_TYPE_FANOUT); 19 | $exchange->setName($exchange_name); 20 | $exchange->declareExchange(); 21 | 22 | //Do not declasre the queue name by setting AMQPQueue::setName() 23 | $queue = new AMQPQueue($channel); 24 | $queue->setFlags(AMQP_EXCLUSIVE); 25 | $queue->declareQueue(); 26 | $queue->bind($exchange_name,$queue->getName()); 27 | echo sprintf("Queue Name: %s", $queue->getName()), PHP_EOL; 28 | } catch(Exception $ex) { 29 | print_r($ex); 30 | } 31 | 32 | 33 | //Read from stdin 34 | $message = implode(' ',array_slice($argv,1)); 35 | if(empty($message)) 36 | $message = "info: Hello World!"; 37 | 38 | $exchange->publish($message, ''); 39 | 40 | echo " [X] Sent {$message}", PHP_EOL; 41 | $connection->disconnect(); 42 | -------------------------------------------------------------------------------- /php-amqp/emit_log_direct.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 6 | $connection->setLogin('guest'); 7 | $connection->setPassword('guest'); 8 | $connection->connect(); 9 | 10 | 11 | //Declare Channel 12 | $channel = new AMQPChannel($connection); 13 | 14 | 15 | $routing_key = $severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info'; 16 | 17 | $message = implode(' ',array_slice($argv, 2)); 18 | if(empty($message)) $message = 'Hello World!'; 19 | 20 | try { 21 | //Declare Exchange 22 | $exchange_name = 'direct_logs'; 23 | $exchange = new AMQPExchange($channel); 24 | $exchange->setType(AMQP_EX_TYPE_DIRECT); 25 | $exchange->setName($exchange_name); 26 | $exchange->declareExchange(); 27 | 28 | $queue = new AMQPQueue($channel); 29 | $queue->setFlags(AMQP_EXCLUSIVE); 30 | $queue->setName('monitor.1'); 31 | $queue->declareQueue(); 32 | 33 | $queue->bind($exchange_name, $routing_key); 34 | $exchange->publish($message,$routing_key); 35 | echo " [x] Sent {$severity}:{$message}", PHP_EOL; 36 | } catch(Exception $ex) { 37 | print_r($ex); 38 | } 39 | 40 | $connection->disconnect(); 41 | -------------------------------------------------------------------------------- /php-amqp/emit_log_topic.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 6 | $connection->setLogin('guest'); 7 | $connection->setPassword('guest'); 8 | $connection->connect(); 9 | 10 | 11 | //Declare Channel 12 | $channel = new AMQPChannel($connection); 13 | 14 | 15 | $routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info'; 16 | 17 | $message = implode(' ',array_slice($argv, 2)); 18 | if(empty($message)) $message = "Hello World!"; 19 | 20 | 21 | try { 22 | //Declare Exchange 23 | $exchange_name = 'topic_logs'; 24 | $exchange = new AMQPExchange($channel); 25 | $exchange->setType(AMQP_EX_TYPE_TOPIC); 26 | $exchange->setName($exchange_name); 27 | $exchange->declareExchange(); 28 | 29 | $exchange->publish($message, $routing_key); 30 | echo " [x] Sent {$routing_key}:{$message}", PHP_EOL; 31 | } catch(Exception $ex) { 32 | print_r($ex); 33 | } 34 | -------------------------------------------------------------------------------- /php-amqp/new_task.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 6 | $connection->setLogin('guest'); 7 | $connection->setPassword('guest'); 8 | $connection->connect(); 9 | 10 | 11 | 12 | //Create and declare channel 13 | $channel = new AMQPChannel($connection); 14 | $channel->setPrefetchCount(1); 15 | 16 | 17 | $routing_key = 'task_queue'; 18 | 19 | try{ 20 | $queue = new AMQPQueue($channel); 21 | $queue->setName($routing_key); 22 | $queue->setFlags(AMQP_DURABLE); 23 | $queue->declareQueue(); 24 | 25 | }catch(Exception $ex){ 26 | print_r($ex); 27 | } 28 | 29 | 30 | //Read from stdin 31 | $message = implode(' ', array_slice($argv,1)); 32 | if(empty($message)) 33 | $message = "Hello World!"; 34 | 35 | $exchange = new AMQPExchange($channel); 36 | $exchange->publish($message, $routing_key, AMQP_NOPARAM, array('delivery_mode' => 2)); 37 | 38 | echo " [x] Sent {$message}", PHP_EOL; 39 | 40 | $connection->disconnect(); 41 | -------------------------------------------------------------------------------- /php-amqp/receive.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 7 | $connection->setLogin('guest'); 8 | $connection->setPassword('guest'); 9 | $connection->connect(); 10 | 11 | //Create and declare channel 12 | $channel = new AMQPChannel($connection); 13 | 14 | //AMQPC Exchange is the publishing mechanism 15 | $exchange = new AMQPExchange($channel); 16 | 17 | 18 | $callback_func = function(AMQPEnvelope $message, AMQPQueue $q) use (&$max_consume) { 19 | echo PHP_EOL, "------------", PHP_EOL; 20 | echo " [x] Received ", $message->getBody(), PHP_EOL; 21 | echo PHP_EOL, "------------", PHP_EOL; 22 | 23 | $q->nack($message->getDeliveryTag()); 24 | sleep(1); 25 | }; 26 | 27 | try{ 28 | $routing_key = 'hello'; 29 | 30 | $queue = new AMQPQueue($channel); 31 | $queue->setName($routing_key); 32 | $queue->setFlags(AMQP_NOPARAM); 33 | $queue->declareQueue(); 34 | 35 | echo ' [*] Waiting for messages. To exit press CTRL+C ', PHP_EOL; 36 | $queue->consume($callback_func); 37 | }catch(AMQPQueueException $ex){ 38 | print_r($ex); 39 | }catch(Exception $ex){ 40 | print_r($ex); 41 | } 42 | 43 | echo 'Close connection...', PHP_EOL; 44 | $queue->cancel(); 45 | $connection->disconnect(); 46 | 47 | -------------------------------------------------------------------------------- /php-amqp/send.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 7 | $connection->setLogin('guest'); 8 | $connection->setPassword('guest'); 9 | $connection->connect(); 10 | 11 | //Create and declare channel 12 | $channel = new AMQPChannel($connection); 13 | 14 | 15 | //AMQPC Exchange is the publishing mechanism 16 | $exchange = new AMQPExchange($channel); 17 | 18 | 19 | try{ 20 | $routing_key = 'hello'; 21 | 22 | $queue = new AMQPQueue($channel); 23 | $queue->setName($routing_key); 24 | $queue->setFlags(AMQP_NOPARAM); 25 | $queue->declareQueue(); 26 | 27 | 28 | $message = 'howdy-do'; 29 | $exchange->publish($message, $routing_key); 30 | 31 | $connection->disconnect(); 32 | }catch(Exception $ex){ 33 | print_r($ex); 34 | } 35 | -------------------------------------------------------------------------------- /php-amqp/worker.php: -------------------------------------------------------------------------------- 1 | setHost('127.0.0.1'); 7 | $connection->setLogin('guest'); 8 | $connection->setPassword('guest'); 9 | $connection->connect(); 10 | 11 | //Create and declare channel 12 | $channel = new AMQPChannel($connection); 13 | 14 | $routing_key = 'task_queue'; 15 | 16 | $callback_func = function(AMQPEnvelope $message, AMQPQueue $q) use (&$max_jobs) { 17 | echo " [x] Received: ", $message->getBody(), PHP_EOL; 18 | sleep(sleep(substr_count($message->getBody(), '.'))); 19 | echo " [X] Done", PHP_EOL; 20 | $q->ack($message->getDeliveryTag()); 21 | }; 22 | 23 | try{ 24 | $queue = new AMQPQueue($channel); 25 | $queue->setName($routing_key); 26 | $queue->setFlags(AMQP_DURABLE); 27 | $queue->declareQueue(); 28 | 29 | 30 | echo ' [*] Waiting for logs. To exit press CTRL+C', PHP_EOL; 31 | $queue->consume($callback_func); 32 | }catch(AMQPQueueException $ex){ 33 | print_r($ex); 34 | }catch(Exception $ex){ 35 | print_r($ex); 36 | } 37 | 38 | $connection->disconnect(); 39 | -------------------------------------------------------------------------------- /php-interop/emit_log.php: -------------------------------------------------------------------------------- 1 | 'localhost', 11 | 'port' => 5672, 12 | 'user' => 'guest', 13 | 'pass' => 'guest', 14 | ]; 15 | 16 | $connection = new AmqpConnectionFactory($config); 17 | $context = $connection->createContext(); 18 | 19 | $topic = $context->createTopic('logs'); 20 | $topic->setType(AmqpTopic::TYPE_FANOUT); 21 | 22 | $context->declareTopic($topic); 23 | 24 | $data = implode(' ', array_slice($argv, 1)); 25 | if (empty($data)) { 26 | $data = 'info: Hello World!'; 27 | } 28 | $message = $context->createMessage($data); 29 | 30 | $context->createProducer()->send($topic, $message); 31 | 32 | echo ' [x] Sent ', $data, "\n"; 33 | 34 | $context->close(); 35 | -------------------------------------------------------------------------------- /php-interop/emit_log_direct.php: -------------------------------------------------------------------------------- 1 | 'localhost', 11 | 'port' => 5672, 12 | 'user' => 'guest', 13 | 'pass' => 'guest', 14 | ]; 15 | 16 | $connection = new AmqpConnectionFactory($config); 17 | $context = $connection->createContext(); 18 | 19 | $topic = $context->createTopic('direct_logs'); 20 | $topic->setType(AmqpTopic::TYPE_DIRECT); 21 | 22 | $context->declareTopic($topic); 23 | 24 | $severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info'; 25 | 26 | $data = implode(' ', array_slice($argv, 2)); 27 | if (empty($data)) { 28 | $data = 'Hello World!'; 29 | } 30 | 31 | $message = $context->createMessage($data); 32 | $message->setRoutingKey($severity); 33 | 34 | $context->createProducer()->send($topic, $message); 35 | 36 | echo ' [x] Sent ',$severity,':',$data," \n"; 37 | 38 | $context->close(); 39 | -------------------------------------------------------------------------------- /php-interop/emit_log_topic.php: -------------------------------------------------------------------------------- 1 | 'localhost', 11 | 'port' => 5672, 12 | 'user' => 'guest', 13 | 'pass' => 'guest', 14 | ]; 15 | 16 | $connection = new AmqpConnectionFactory($config); 17 | $context = $connection->createContext(); 18 | 19 | $topic = $context->createTopic('topic_logs'); 20 | $topic->setType(AmqpTopic::TYPE_TOPIC); 21 | 22 | $context->declareTopic($topic); 23 | 24 | $routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info'; 25 | 26 | $data = implode(' ', array_slice($argv, 2)); 27 | if (empty($data)) { 28 | $data = 'Hello World!'; 29 | } 30 | 31 | $message = $context->createMessage($data); 32 | $message->setRoutingKey($routing_key); 33 | 34 | $context->createProducer()->send($topic, $message); 35 | 36 | echo ' [x] Sent ',$routing_key,':',$data," \n"; 37 | 38 | $context->close(); 39 | -------------------------------------------------------------------------------- /php-interop/new_task.php: -------------------------------------------------------------------------------- 1 | 'localhost', 12 | 'port' => 5672, 13 | 'user' => 'guest', 14 | 'pass' => 'guest', 15 | ]; 16 | 17 | $connection = new AmqpConnectionFactory($config); 18 | $context = $connection->createContext(); 19 | 20 | $queue = $context->createQueue('task_queue'); 21 | $queue->addFlag(AmqpQueue::FLAG_DURABLE); 22 | 23 | $context->declareQueue($queue); 24 | 25 | $data = implode(' ', array_slice($argv, 1)); 26 | if (empty($data)) { 27 | $data = 'Hello World!'; 28 | } 29 | $message = $context->createMessage($data); 30 | $message->setDeliveryMode(AmqpMessage::DELIVERY_MODE_PERSISTENT); 31 | 32 | $context->createProducer()->send($queue, $message); 33 | 34 | echo ' [x] Sent ', $data, "\n"; 35 | 36 | $context->close(); 37 | -------------------------------------------------------------------------------- /php-interop/receive.php: -------------------------------------------------------------------------------- 1 | 'localhost', 11 | 'port' => 5672, 12 | 'user' => 'guest', 13 | 'pass' => 'guest', 14 | 'receive_method' => 'basic_consume', 15 | ]; 16 | 17 | $connection = new AmqpConnectionFactory($config); 18 | $context = $connection->createContext(); 19 | 20 | $queue = $context->createQueue('hello'); 21 | $context->declareQueue($queue); 22 | 23 | $consumer = $context->createConsumer($queue); 24 | $consumer->addFlag(AmqpConsumer::FLAG_NOACK); 25 | 26 | echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; 27 | 28 | while (true) { 29 | if ($message = $consumer->receive()) { 30 | echo ' [x] Received ', $message->getBody(), "\n"; 31 | } 32 | } 33 | 34 | $context->close(); 35 | -------------------------------------------------------------------------------- /php-interop/receive_logs.php: -------------------------------------------------------------------------------- 1 | 'localhost', 13 | 'port' => 5672, 14 | 'user' => 'guest', 15 | 'pass' => 'guest', 16 | 'receive_method' => 'basic_consume', 17 | ]; 18 | 19 | $connection = new AmqpConnectionFactory($config); 20 | $context = $connection->createContext(); 21 | 22 | $topic = $context->createTopic('logs'); 23 | $topic->setType(AmqpTopic::TYPE_FANOUT); 24 | 25 | $context->declareTopic($topic); 26 | 27 | $queue = $context->createTemporaryQueue(); 28 | 29 | $context->bind(new AmqpBind($topic, $queue)); 30 | 31 | $consumer = $context->createConsumer($queue); 32 | $consumer->addFlag(AmqpConsumer::FLAG_NOACK); 33 | 34 | echo ' [*] Waiting for logs. To exit press CTRL+C', "\n"; 35 | 36 | while (true) { 37 | if ($message = $consumer->receive()) { 38 | echo ' [x] ', $message->getBody(), "\n"; 39 | } 40 | } 41 | 42 | $context->close(); 43 | -------------------------------------------------------------------------------- /php-interop/send.php: -------------------------------------------------------------------------------- 1 | 'localhost', 10 | 'port' => 5672, 11 | 'user' => 'guest', 12 | 'pass' => 'guest', 13 | ]; 14 | 15 | $connection = new AmqpConnectionFactory($config); 16 | $context = $connection->createContext(); 17 | 18 | $queue = $context->createQueue('hello'); 19 | $context->declareQueue($queue); 20 | 21 | $message = $context->createMessage('Hello World!'); 22 | 23 | $context->createProducer()->send($queue, $message); 24 | 25 | echo " [x] Sent 'Hello World!'\n"; 26 | 27 | $context->close(); 28 | -------------------------------------------------------------------------------- /php-interop/worker.php: -------------------------------------------------------------------------------- 1 | 'localhost', 11 | 'port' => 5672, 12 | 'user' => 'guest', 13 | 'pass' => 'guest', 14 | 'receive_method' => 'basic_consume', 15 | ]; 16 | 17 | $connection = new AmqpConnectionFactory($config); 18 | $context = $connection->createContext(); 19 | $context->setQos(0, 1, false); 20 | 21 | $queue = $context->createQueue('task_queue'); 22 | $queue->addFlag(AmqpQueue::FLAG_DURABLE); 23 | 24 | $context->declareQueue($queue); 25 | 26 | $consumer = $context->createConsumer($queue); 27 | 28 | echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; 29 | 30 | while (true) { 31 | if ($message = $consumer->receive()) { 32 | echo ' [x] Received ', $message->getBody(), "\n"; 33 | sleep(substr_count($message->getBody(), '.')); 34 | echo ' [x] Done', "\n"; 35 | $consumer->acknowledge($message); 36 | } 37 | } 38 | 39 | $context->close(); 40 | -------------------------------------------------------------------------------- /php/.gitignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | vendor/* 3 | composer.phar 4 | composer.lock 5 | -------------------------------------------------------------------------------- /php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "php-amqplib/php-amqplib": "^3.2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /php/emit_log.php: -------------------------------------------------------------------------------- 1 | channel(); 9 | 10 | $channel->exchange_declare('logs', 'fanout', false, false, false); 11 | 12 | $data = implode(' ', array_slice($argv, 1)); 13 | if (empty($data)) { 14 | $data = "info: Hello World!"; 15 | } 16 | $msg = new AMQPMessage($data); 17 | 18 | $channel->basic_publish($msg, 'logs'); 19 | 20 | echo ' [x] Sent ', $data, "\n"; 21 | 22 | $channel->close(); 23 | $connection->close(); 24 | ?> 25 | -------------------------------------------------------------------------------- /php/emit_log_direct.php: -------------------------------------------------------------------------------- 1 | channel(); 9 | 10 | $channel->exchange_declare('direct_logs', 'direct', false, false, false); 11 | 12 | $severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info'; 13 | 14 | $data = implode(' ', array_slice($argv, 2)); 15 | if (empty($data)) { 16 | $data = "Hello World!"; 17 | } 18 | 19 | $msg = new AMQPMessage($data); 20 | 21 | $channel->basic_publish($msg, 'direct_logs', $severity); 22 | 23 | echo ' [x] Sent ', $severity, ':', $data, "\n"; 24 | 25 | $channel->close(); 26 | $connection->close(); 27 | ?> 28 | -------------------------------------------------------------------------------- /php/emit_log_topic.php: -------------------------------------------------------------------------------- 1 | channel(); 9 | 10 | $channel->exchange_declare('topic_logs', 'topic', false, false, false); 11 | 12 | $routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info'; 13 | $data = implode(' ', array_slice($argv, 2)); 14 | if (empty($data)) { 15 | $data = "Hello World!"; 16 | } 17 | 18 | $msg = new AMQPMessage($data); 19 | 20 | $channel->basic_publish($msg, 'topic_logs', $routing_key); 21 | 22 | echo ' [x] Sent ', $routing_key, ':', $data, "\n"; 23 | 24 | $channel->close(); 25 | $connection->close(); 26 | ?> 27 | -------------------------------------------------------------------------------- /php/new_task.php: -------------------------------------------------------------------------------- 1 | channel(); 9 | 10 | $channel->queue_declare('task_queue', false, true, false, false); 11 | 12 | $data = implode(' ', array_slice($argv, 1)); 13 | if (empty($data)) { 14 | $data = "Hello World!"; 15 | } 16 | $msg = new AMQPMessage( 17 | $data, 18 | array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT) 19 | ); 20 | 21 | $channel->basic_publish($msg, '', 'task_queue'); 22 | 23 | echo ' [x] Sent ', $data, "\n"; 24 | 25 | $channel->close(); 26 | $connection->close(); 27 | ?> 28 | -------------------------------------------------------------------------------- /php/receive.php: -------------------------------------------------------------------------------- 1 | channel(); 8 | 9 | $channel->queue_declare('hello', false, false, false, false); 10 | 11 | echo " [*] Waiting for messages. To exit press CTRL+C\n"; 12 | 13 | $callback = function ($msg) { 14 | echo ' [x] Received ', $msg->getBody(), "\n"; 15 | }; 16 | 17 | $channel->basic_consume('hello', '', false, true, false, false, $callback); 18 | 19 | try { 20 | $channel->consume(); 21 | } catch (\Throwable $exception) { 22 | echo $exception->getMessage(); 23 | } 24 | 25 | $channel->close(); 26 | $connection->close(); 27 | -------------------------------------------------------------------------------- /php/receive_logs.php: -------------------------------------------------------------------------------- 1 | channel(); 8 | 9 | $channel->exchange_declare('logs', 'fanout', false, false, false); 10 | 11 | list($queue_name, ,) = $channel->queue_declare("", false, false, true, false); 12 | 13 | $channel->queue_bind($queue_name, 'logs'); 14 | 15 | echo " [*] Waiting for logs. To exit press CTRL+C\n"; 16 | 17 | $callback = function ($msg) { 18 | echo ' [x] ', $msg->getBody(), "\n"; 19 | }; 20 | 21 | $channel->basic_consume($queue_name, '', false, true, false, false, $callback); 22 | 23 | try { 24 | $channel->consume(); 25 | } catch (\Throwable $exception) { 26 | echo $exception->getMessage(); 27 | } 28 | 29 | $channel->close(); 30 | $connection->close(); 31 | -------------------------------------------------------------------------------- /php/receive_logs_direct.php: -------------------------------------------------------------------------------- 1 | channel(); 8 | 9 | $channel->exchange_declare('direct_logs', 'direct', false, false, false); 10 | 11 | list($queue_name, ,) = $channel->queue_declare("", false, false, true, false); 12 | 13 | $severities = array_slice($argv, 1); 14 | if (empty($severities)) { 15 | file_put_contents('php://stderr', "Usage: $argv[0] [info] [warning] [error]\n"); 16 | exit(1); 17 | } 18 | 19 | foreach ($severities as $severity) { 20 | $channel->queue_bind($queue_name, 'direct_logs', $severity); 21 | } 22 | 23 | echo " [*] Waiting for logs. To exit press CTRL+C\n"; 24 | 25 | $callback = function ($msg) { 26 | echo ' [x] ', $msg->getRoutingKey(), ':', $msg->getBody(), "\n"; 27 | }; 28 | 29 | $channel->basic_consume($queue_name, '', false, true, false, false, $callback); 30 | 31 | try { 32 | $channel->consume(); 33 | } catch (\Throwable $exception) { 34 | echo $exception->getMessage(); 35 | } 36 | 37 | $channel->close(); 38 | $connection->close(); 39 | -------------------------------------------------------------------------------- /php/receive_logs_topic.php: -------------------------------------------------------------------------------- 1 | channel(); 8 | 9 | $channel->exchange_declare('topic_logs', 'topic', false, false, false); 10 | 11 | list($queue_name, ,) = $channel->queue_declare("", false, false, true, false); 12 | 13 | $binding_keys = array_slice($argv, 1); 14 | if (empty($binding_keys)) { 15 | file_put_contents('php://stderr', "Usage: $argv[0] [binding_key]\n"); 16 | exit(1); 17 | } 18 | 19 | foreach ($binding_keys as $binding_key) { 20 | $channel->queue_bind($queue_name, 'topic_logs', $binding_key); 21 | } 22 | 23 | echo " [*] Waiting for logs. To exit press CTRL+C\n"; 24 | 25 | $callback = function ($msg) { 26 | echo ' [x] ', $msg->getRoutingKey(), ':', $msg->getBody(), "\n"; 27 | }; 28 | 29 | $channel->basic_consume($queue_name, '', false, true, false, false, $callback); 30 | 31 | try { 32 | $channel->consume(); 33 | } catch (\Throwable $exception) { 34 | echo $exception->getMessage(); 35 | } 36 | 37 | $channel->close(); 38 | $connection->close(); 39 | -------------------------------------------------------------------------------- /php/send.php: -------------------------------------------------------------------------------- 1 | channel(); 9 | 10 | $channel->queue_declare('hello', false, false, false, false); 11 | 12 | $msg = new AMQPMessage('Hello World!'); 13 | $channel->basic_publish($msg, '', 'hello'); 14 | 15 | echo " [x] Sent 'Hello World!'\n"; 16 | 17 | $channel->close(); 18 | $connection->close(); 19 | ?> 20 | -------------------------------------------------------------------------------- /php/worker.php: -------------------------------------------------------------------------------- 1 | channel(); 8 | 9 | $channel->queue_declare('task_queue', false, true, false, false); 10 | 11 | echo " [*] Waiting for messages. To exit press CTRL+C\n"; 12 | 13 | $callback = function ($msg) { 14 | echo ' [x] Received ', $msg->getBody(), "\n"; 15 | sleep(substr_count($msg->getBody(), '.')); 16 | echo " [x] Done\n"; 17 | $msg->ack(); 18 | }; 19 | 20 | $channel->basic_qos(null, 1, false); 21 | $channel->basic_consume('task_queue', '', false, false, false, false, $callback); 22 | 23 | try { 24 | $channel->consume(); 25 | } catch (\Throwable $exception) { 26 | echo $exception->getMessage(); 27 | } 28 | 29 | $channel->close(); 30 | $connection->close(); 31 | -------------------------------------------------------------------------------- /python-stream/README.md: -------------------------------------------------------------------------------- 1 | # Python code for RabbitMQ tutorials 2 | 3 | 4 | Here you can find Python code examples from [RabbitMQ tutorials](https://www.rabbitmq.com/getstarted.html). 5 | 6 | 7 | ## Requirements 8 | 9 | These examples use the [`qweeze/rstream`](https://github.com/qweeze/rstream) client library. 10 | 11 | Get it first with the necessary dependencies: 12 | 13 | pip3 install -r requirements.txt 14 | 15 | ## Code 16 | 17 | Code examples are executed via `python3`: 18 | 19 | [Tutorial one: "Hello World!"](https://www.rabbitmq.com/tutorials/tutorial-one-python-stream): 20 | 21 | python3 send.py 22 | python3 receive.py 23 | 24 | [Tutorial two: "Offset tracking"](https://www.rabbitmq.com/tutorials/tutorial-two-python-stream): 25 | 26 | python3 offset_tracking_send.py 27 | python3 offset_tracking_receive.py 28 | 29 | 30 | To learn more, see [`rqweeze/rstream`](https://github.com/qweeze/rstream). -------------------------------------------------------------------------------- /python-stream/requirements.txt: -------------------------------------------------------------------------------- 1 | rstream 2 | -------------------------------------------------------------------------------- /python-stream/send.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from rstream import Producer 4 | 5 | STREAM_NAME = "hello-python-stream" 6 | # 5GB 7 | STREAM_RETENTION = 5000000000 8 | 9 | 10 | async def send(): 11 | async with Producer( 12 | host="localhost", 13 | username="guest", 14 | password="guest", 15 | ) as producer: 16 | await producer.create_stream( 17 | STREAM_NAME, exists_ok=True, arguments={"max-length-bytes": STREAM_RETENTION} 18 | ) 19 | 20 | await producer.send(stream=STREAM_NAME, message=b"Hello, World!") 21 | 22 | print(" [x] Hello, World! message sent") 23 | 24 | input(" [x] Press Enter to close the producer ...") 25 | 26 | with asyncio.Runner() as runner: 27 | runner.run(send()) 28 | -------------------------------------------------------------------------------- /python/emit_log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | import pika 5 | 6 | connection = pika.BlockingConnection( 7 | pika.ConnectionParameters(host="localhost"), 8 | ) 9 | channel = connection.channel() 10 | 11 | channel.exchange_declare(exchange="logs", exchange_type="fanout") 12 | 13 | message = " ".join(sys.argv[1:]) or "info: Hello World!" 14 | channel.basic_publish(exchange="logs", routing_key="", body=message) 15 | print(f" [x] Sent {message}") 16 | 17 | connection.close() 18 | -------------------------------------------------------------------------------- /python/emit_log_direct.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | import pika 5 | 6 | connection = pika.BlockingConnection( 7 | pika.ConnectionParameters(host="localhost"), 8 | ) 9 | channel = connection.channel() 10 | 11 | channel.exchange_declare(exchange="direct_logs", exchange_type="direct") 12 | 13 | severity = sys.argv[1] if len(sys.argv) > 2 else "info" 14 | message = " ".join(sys.argv[2:]) or "Hello World!" 15 | channel.basic_publish( 16 | exchange="direct_logs", 17 | routing_key=severity, 18 | body=message, 19 | ) 20 | print(f" [x] Sent {severity}:{message}") 21 | 22 | connection.close() 23 | -------------------------------------------------------------------------------- /python/emit_log_topic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | import pika 5 | 6 | connection = pika.BlockingConnection( 7 | pika.ConnectionParameters(host="localhost"), 8 | ) 9 | channel = connection.channel() 10 | 11 | channel.exchange_declare(exchange="topic_logs", exchange_type="topic") 12 | 13 | routing_key = sys.argv[1] if len(sys.argv) > 2 else "anonymous.info" 14 | message = " ".join(sys.argv[2:]) or "Hello World!" 15 | channel.basic_publish( 16 | exchange="topic_logs", 17 | routing_key=routing_key, 18 | body=message, 19 | ) 20 | print(f" [x] Sent {routing_key}:{message}") 21 | 22 | connection.close() 23 | -------------------------------------------------------------------------------- /python/new_task.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | 4 | import pika 5 | 6 | connection = pika.BlockingConnection( 7 | pika.ConnectionParameters(host="localhost"), 8 | ) 9 | channel = connection.channel() 10 | 11 | channel.queue_declare(queue="task_queue", durable=True) 12 | 13 | message = " ".join(sys.argv[1:]) or "Hello World!" 14 | channel.basic_publish( 15 | exchange="", 16 | routing_key="task_queue", 17 | body=message, 18 | properties=pika.BasicProperties( 19 | delivery_mode=pika.DeliveryMode.Persistent, 20 | ), 21 | ) 22 | print(f" [x] Sent {message}") 23 | 24 | connection.close() 25 | -------------------------------------------------------------------------------- /python/receive.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | import pika 6 | 7 | 8 | def main(): 9 | connection = pika.BlockingConnection( 10 | pika.ConnectionParameters(host="localhost"), 11 | ) 12 | channel = connection.channel() 13 | 14 | channel.queue_declare(queue="hello") 15 | 16 | def callback(ch, method, properties, body): 17 | print(f" [x] Received {body.decode()}") 18 | 19 | channel.basic_consume( 20 | queue="hello", 21 | on_message_callback=callback, 22 | auto_ack=True, 23 | ) 24 | 25 | print(" [*] Waiting for messages. To exit press CTRL+C") 26 | channel.start_consuming() 27 | 28 | 29 | if __name__ == "__main__": 30 | try: 31 | main() 32 | except KeyboardInterrupt: 33 | print("Interrupted") 34 | try: 35 | sys.exit(0) 36 | except SystemExit: 37 | os._exit(0) 38 | -------------------------------------------------------------------------------- /python/receive_logs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | import pika 6 | 7 | 8 | def main(): 9 | connection = pika.BlockingConnection( 10 | pika.ConnectionParameters(host="localhost"), 11 | ) 12 | channel = connection.channel() 13 | 14 | channel.exchange_declare(exchange="logs", exchange_type="fanout") 15 | 16 | result = channel.queue_declare(queue="", exclusive=True) 17 | queue_name = result.method.queue 18 | 19 | channel.queue_bind(exchange="logs", queue=queue_name) 20 | 21 | def callback(ch, method, properties, body): 22 | print(f" [x] {body.decode()}") 23 | 24 | print(" [*] Waiting for logs. To exit press CTRL+C") 25 | channel.basic_consume( 26 | queue=queue_name, 27 | on_message_callback=callback, 28 | auto_ack=True, 29 | ) 30 | 31 | channel.start_consuming() 32 | 33 | 34 | if __name__ == "__main__": 35 | try: 36 | main() 37 | except KeyboardInterrupt: 38 | print("Interrupted") 39 | try: 40 | sys.exit(0) 41 | except SystemExit: 42 | os._exit(0) 43 | -------------------------------------------------------------------------------- /python/rpc_server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import pika 3 | 4 | connection = pika.BlockingConnection( 5 | pika.ConnectionParameters(host="localhost"), 6 | ) 7 | channel = connection.channel() 8 | 9 | channel.queue_declare(queue="rpc_queue") 10 | 11 | 12 | def fib(n): 13 | if n == 0: 14 | return 0 15 | elif n == 1: 16 | return 1 17 | else: 18 | return fib(n - 1) + fib(n - 2) 19 | 20 | 21 | def on_request(ch, method, props, body): 22 | n = int(body) 23 | 24 | print(f" [.] fib({n})") 25 | response = fib(n) 26 | 27 | ch.basic_publish( 28 | exchange="", 29 | routing_key=props.reply_to, 30 | properties=pika.BasicProperties(correlation_id=props.correlation_id), 31 | body=str(response), 32 | ) 33 | ch.basic_ack(delivery_tag=method.delivery_tag) 34 | 35 | 36 | channel.basic_qos(prefetch_count=1) 37 | channel.basic_consume(queue="rpc_queue", on_message_callback=on_request) 38 | 39 | print(" [x] Awaiting RPC requests") 40 | channel.start_consuming() 41 | -------------------------------------------------------------------------------- /python/send.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import pika 3 | 4 | connection = pika.BlockingConnection( 5 | pika.ConnectionParameters(host="localhost"), 6 | ) 7 | channel = connection.channel() 8 | 9 | channel.queue_declare(queue="hello") 10 | 11 | channel.basic_publish(exchange="", routing_key="hello", body="Hello World!") 12 | print(" [x] Sent 'Hello World!'") 13 | 14 | connection.close() 15 | -------------------------------------------------------------------------------- /python/worker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import time 3 | 4 | import pika 5 | 6 | connection = pika.BlockingConnection( 7 | pika.ConnectionParameters(host="localhost"), 8 | ) 9 | channel = connection.channel() 10 | 11 | channel.queue_declare(queue="task_queue", durable=True) 12 | print(" [*] Waiting for messages. To exit press CTRL+C") 13 | 14 | 15 | def callback(ch, method, properties, body): 16 | print(f" [x] Received {body.decode()}") 17 | time.sleep(body.count(b".")) 18 | print(" [x] Done") 19 | ch.basic_ack(delivery_tag=method.delivery_tag) 20 | 21 | 22 | channel.basic_qos(prefetch_count=1) 23 | channel.basic_consume(queue="task_queue", on_message_callback=callback) 24 | 25 | channel.start_consuming() 26 | -------------------------------------------------------------------------------- /ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | ruby ">= 2.5.0" 4 | 5 | gem "bunny", ">= 2.14.2", " < 3.0" 6 | -------------------------------------------------------------------------------- /ruby/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | amq-protocol (2.3.0) 5 | bunny (2.14.2) 6 | amq-protocol (~> 2.3, >= 2.3.0) 7 | 8 | PLATFORMS 9 | ruby 10 | 11 | DEPENDENCIES 12 | bunny (>= 2.14.2, < 3.0) 13 | 14 | RUBY VERSION 15 | ruby 2.5.1p57 16 | 17 | BUNDLED WITH 18 | 1.17.2 19 | -------------------------------------------------------------------------------- /ruby/emit_log.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bunny' 4 | 5 | connection = Bunny.new 6 | connection.start 7 | 8 | channel = connection.create_channel 9 | exchange = channel.fanout('logs') 10 | 11 | message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ') 12 | 13 | exchange.publish(message) 14 | puts " [x] Sent #{message}" 15 | 16 | connection.close 17 | -------------------------------------------------------------------------------- /ruby/emit_log_direct.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | exchange = channel.direct('direct_logs') 9 | severity = ARGV.shift || 'info' 10 | message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ') 11 | 12 | exchange.publish(message, routing_key: severity) 13 | puts " [x] Sent '#{message}'" 14 | 15 | connection.close 16 | -------------------------------------------------------------------------------- /ruby/emit_log_topic.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | exchange = channel.topic('topic_logs') 9 | severity = ARGV.shift || 'anonymous.info' 10 | message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ') 11 | 12 | exchange.publish(message, routing_key: severity) 13 | puts " [x] Sent #{severity}:#{message}" 14 | 15 | connection.close 16 | -------------------------------------------------------------------------------- /ruby/new_task.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | queue = channel.queue('task_queue', durable: true) 9 | 10 | message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ') 11 | 12 | queue.publish(message, persistent: true) 13 | puts " [x] Sent #{message}" 14 | 15 | connection.close 16 | -------------------------------------------------------------------------------- /ruby/receive.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | queue = channel.queue('hello') 9 | 10 | begin 11 | puts ' [*] Waiting for messages. To exit press CTRL+C' 12 | # block: true is only used to keep the main thread 13 | # alive. Please avoid using it in real world applications. 14 | queue.subscribe(block: true) do |_delivery_info, _properties, body| 15 | puts " [x] Received #{body}" 16 | end 17 | rescue Interrupt => _ 18 | connection.close 19 | 20 | exit(0) 21 | end 22 | -------------------------------------------------------------------------------- /ruby/receive_logs.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bunny' 4 | 5 | connection = Bunny.new 6 | connection.start 7 | 8 | channel = connection.create_channel 9 | exchange = channel.fanout('logs') 10 | queue = channel.queue('', exclusive: true) 11 | 12 | queue.bind(exchange) 13 | 14 | puts ' [*] Waiting for logs. To exit press CTRL+C' 15 | 16 | begin 17 | # block: true is only used to keep the main thread 18 | # alive. Please avoid using it in real world applications. 19 | queue.subscribe(block: true) do |_delivery_info, _properties, body| 20 | puts " [x] #{body}" 21 | end 22 | rescue Interrupt => _ 23 | channel.close 24 | connection.close 25 | end 26 | -------------------------------------------------------------------------------- /ruby/receive_logs_direct.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | abort "Usage: #{$PROGRAM_NAME} [info] [warning] [error]" if ARGV.empty? 5 | 6 | connection = Bunny.new(automatically_recover: false) 7 | connection.start 8 | 9 | channel = connection.create_channel 10 | exchange = channel.direct('direct_logs') 11 | queue = channel.queue('', exclusive: true) 12 | 13 | ARGV.each do |severity| 14 | queue.bind(exchange, routing_key: severity) 15 | end 16 | 17 | puts ' [*] Waiting for logs. To exit press CTRL+C' 18 | 19 | begin 20 | # block: true is only used to keep the main thread 21 | # alive. Please avoid using it in real world applications. 22 | queue.subscribe(block: true) do |delivery_info, _properties, body| 23 | puts " [x] #{delivery_info.routing_key}:#{body}" 24 | end 25 | rescue Interrupt => _ 26 | channel.close 27 | connection.close 28 | 29 | exit(0) 30 | end 31 | -------------------------------------------------------------------------------- /ruby/receive_logs_topic.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | abort "Usage: #{$PROGRAM_NAME} [binding key]" if ARGV.empty? 5 | 6 | connection = Bunny.new(automatically_recover: false) 7 | connection.start 8 | 9 | channel = connection.create_channel 10 | exchange = channel.topic('topic_logs') 11 | queue = channel.queue('', exclusive: true) 12 | 13 | ARGV.each do |severity| 14 | queue.bind(exchange, routing_key: severity) 15 | end 16 | 17 | puts ' [*] Waiting for logs. To exit press CTRL+C' 18 | 19 | begin 20 | # block: true is only used to keep the main thread 21 | # alive. Please avoid using it in real world applications. 22 | queue.subscribe(block: true) do |delivery_info, _properties, body| 23 | puts " [x] #{delivery_info.routing_key}:#{body}" 24 | end 25 | rescue Interrupt => _ 26 | channel.close 27 | connection.close 28 | 29 | exit(0) 30 | end 31 | -------------------------------------------------------------------------------- /ruby/send.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | queue = channel.queue('hello') 9 | 10 | channel.default_exchange.publish('Hello World!', routing_key: queue.name) 11 | puts " [x] Sent 'Hello World!'" 12 | 13 | connection.close 14 | -------------------------------------------------------------------------------- /ruby/worker.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'bunny' 3 | 4 | connection = Bunny.new(automatically_recover: false) 5 | connection.start 6 | 7 | channel = connection.create_channel 8 | queue = channel.queue('task_queue', durable: true) 9 | 10 | channel.prefetch(1) 11 | puts ' [*] Waiting for messages. To exit press CTRL+C' 12 | 13 | begin 14 | # block: true is only used to keep the main thread 15 | # alive. Please avoid using it in real world applications. 16 | queue.subscribe(manual_ack: true, block: true) do |delivery_info, _properties, body| 17 | puts " [x] Received '#{body}'" 18 | # imitate some work 19 | sleep body.count('.') 20 | puts ' [x] Done' 21 | channel.ack(delivery_info.delivery_tag) 22 | end 23 | rescue Interrupt => _ 24 | connection.close 25 | end 26 | -------------------------------------------------------------------------------- /rust-amqprs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rabbitmq-tutorials" 3 | version = "1.0.0" 4 | authors = ["Michael Klishin "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | amqprs = "1.2" 9 | tokio = "1" -------------------------------------------------------------------------------- /rust-lapin/.gitignore: -------------------------------------------------------------------------------- 1 | !bin/ 2 | -------------------------------------------------------------------------------- /rust-lapin/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rabbitmq-tutorials" 3 | version = "1.0.0" 4 | authors = ["Michal Malek "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | futures = "0.3.21" 9 | lapin = "2.1.1" 10 | tokio = { version = "1.43.1", features = ["full"] } 11 | uuid = { version = "1.1.1", features = ["v4"] } 12 | tokio-stream = "0.1" 13 | -------------------------------------------------------------------------------- /rust-lapin/src/bin/new_task.rs: -------------------------------------------------------------------------------- 1 | use lapin::{BasicProperties, Connection, ConnectionProperties, options::*, types::FieldTable}; 2 | 3 | #[tokio::main] 4 | async fn main() -> Result<(), Box> { 5 | let args: Vec<_> = std::env::args().skip(1).collect(); 6 | let message = match args.len() { 7 | 0 => "hello".to_string(), 8 | _ => args.join(" ").to_string(), 9 | }; 10 | 11 | let addr = "amqp://127.0.0.1:5672"; 12 | let conn = Connection::connect(addr, ConnectionProperties::default()).await?; 13 | let channel = conn.create_channel().await?; 14 | 15 | channel 16 | .queue_declare( 17 | "task_queue", 18 | QueueDeclareOptions::default(), 19 | FieldTable::default(), 20 | ) 21 | .await?; 22 | 23 | channel 24 | .basic_publish( 25 | "", 26 | "task_queue", 27 | BasicPublishOptions::default(), 28 | message.as_bytes(), 29 | BasicProperties::default(), 30 | ) 31 | .await?; 32 | 33 | println!(" [x] Sent {:?}", std::str::from_utf8(message.as_bytes())?); 34 | 35 | conn.close(0, "").await?; 36 | 37 | Ok(()) 38 | } 39 | -------------------------------------------------------------------------------- /rust-lapin/src/bin/send.rs: -------------------------------------------------------------------------------- 1 | use lapin::{options::*, types::FieldTable, BasicProperties, Connection, ConnectionProperties}; 2 | 3 | #[tokio::main] 4 | async fn main() -> Result<(), Box> { 5 | let addr = "amqp://127.0.0.1:5672"; 6 | let conn = Connection::connect(addr, ConnectionProperties::default()).await?; 7 | let channel = conn.create_channel().await?; 8 | 9 | channel 10 | .queue_declare( 11 | "hello", 12 | QueueDeclareOptions::default(), 13 | FieldTable::default(), 14 | ) 15 | .await?; 16 | 17 | let payload = "Hello world!".as_bytes(); 18 | channel 19 | .basic_publish( 20 | "", 21 | "hello", 22 | BasicPublishOptions::default(), 23 | payload, 24 | BasicProperties::default(), 25 | ) 26 | .await?; 27 | 28 | println!(" [x] Sent \"Hello World!\""); 29 | 30 | conn.close(0, "").await?; 31 | 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /rust-stream/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust-stream" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | rabbitmq-stream-client = "0.4.4" 10 | tokio = { version = "1.43.1", features = ["rt", "rt-multi-thread", "macros"] } 11 | futures = "0.3.30" 12 | -------------------------------------------------------------------------------- /scala/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/scala/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /scala/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip -------------------------------------------------------------------------------- /scala/src/main/scala/EmitLog.scala: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client.ConnectionFactory 2 | 3 | object EmitLog { 4 | 5 | private val EXCHANGE_NAME = "logs" 6 | 7 | def main(argv: Array[String]) { 8 | val factory = new ConnectionFactory() 9 | factory.setHost("localhost") 10 | val connection = factory.newConnection() 11 | val channel = connection.createChannel() 12 | channel.exchangeDeclare(EXCHANGE_NAME, "fanout") 13 | val message = if (argv.length < 1) "Hello World!" else argv.mkString(" ") 14 | channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8")) 15 | println(" [x] Sent '" + message + "'") 16 | channel.close() 17 | connection.close() 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /scala/src/main/scala/NewTask.scala: -------------------------------------------------------------------------------- 1 | 2 | import com.rabbitmq.client.{ConnectionFactory, MessageProperties} 3 | 4 | object NewTask { 5 | 6 | private val TASK_QUEUE_NAME = "task_queue" 7 | 8 | def main(argv: Array[String]) { 9 | val factory = new ConnectionFactory() 10 | factory.setHost("localhost") 11 | val connection = factory.newConnection() 12 | val channel = connection.createChannel() 13 | channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null) 14 | val message = if (argv.length < 1) "Hello World!" else argv.mkString(" ") 15 | channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8")) 16 | println(" [x] Sent '" + message + "'") 17 | channel.close() 18 | connection.close() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /scala/src/main/scala/ReceiveLogs.scala: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client._ 2 | 3 | object ReceiveLogs { 4 | 5 | private val EXCHANGE_NAME = "logs" 6 | 7 | def main(argv: Array[String]) { 8 | val factory = new ConnectionFactory() 9 | factory.setHost("localhost") 10 | 11 | val connection = factory.newConnection() 12 | val channel = connection.createChannel() 13 | channel.exchangeDeclare(EXCHANGE_NAME, "fanout") 14 | val queueName = channel.queueDeclare().getQueue 15 | channel.queueBind(queueName, EXCHANGE_NAME, "") 16 | println(" [*] Waiting for messages. To exit press CTRL+C") 17 | val deliverCallback: DeliverCallback = (_, delivery) => { 18 | val message = new String(delivery.getBody, "UTF-8") 19 | println(" [x] Received '" + message + "'") 20 | } 21 | channel.basicConsume(queueName, true, deliverCallback, _ => {}) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /scala/src/main/scala/ReceiveLogsDirect.scala: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client._ 2 | 3 | object ReceiveLogsDirect { 4 | 5 | private val EXCHANGE_NAME = "direct_logs" 6 | 7 | def main(argv: Array[String]) { 8 | val factory = new ConnectionFactory() 9 | factory.setHost("localhost") 10 | val connection = factory.newConnection() 11 | val channel = connection.createChannel() 12 | channel.exchangeDeclare(EXCHANGE_NAME, "direct") 13 | val queueName = channel.queueDeclare().getQueue 14 | if (argv.length < 1) { 15 | System.err.println("Usage: ReceiveLogsDirect [info] [warning] [error]") 16 | System.exit(1) 17 | } 18 | for (severity <- argv) { 19 | channel.queueBind(queueName, EXCHANGE_NAME, severity) 20 | } 21 | println(" [*] Waiting for messages. To exit press CTRL+C") 22 | val deliverCallback: DeliverCallback = (_, delivery) => { 23 | val message = new String(delivery.getBody, "UTF-8") 24 | println(" [x] Received '" + 25 | delivery.getEnvelope.getRoutingKey + "':'" + message + "'") 26 | } 27 | channel.basicConsume(queueName, true, deliverCallback, _ => { }) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /scala/src/main/scala/ReceiveLogsTopic.scala: -------------------------------------------------------------------------------- 1 | import com.rabbitmq.client._ 2 | 3 | object ReceiveLogsTopic { 4 | 5 | private val EXCHANGE_NAME = "topic_logs" 6 | 7 | def main(argv: Array[String]) { 8 | val factory = new ConnectionFactory() 9 | factory.setHost("localhost") 10 | val connection = factory.newConnection() 11 | val channel = connection.createChannel() 12 | channel.exchangeDeclare(EXCHANGE_NAME, "topic") 13 | val queueName = channel.queueDeclare().getQueue 14 | if (argv.length < 1) { 15 | System.err.println("Usage: ReceiveLogsTopic [binding_key]...") 16 | System.exit(1) 17 | } 18 | for (bindingKey <- argv) { 19 | channel.queueBind(queueName, EXCHANGE_NAME, bindingKey) 20 | } 21 | println(" [*] Waiting for messages. To exit press CTRL+C") 22 | val deliverCallback: DeliverCallback = (_, delivery) => { 23 | val message = new String(delivery.getBody, "UTF-8") 24 | println(" [x] Received '" + 25 | delivery.getEnvelope.getRoutingKey + "':'" + message + "'") 26 | } 27 | channel.basicConsume(queueName, true, deliverCallback, _ => {}) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /scala/src/main/scala/Recv.scala: -------------------------------------------------------------------------------- 1 | 2 | import com.rabbitmq.client._ 3 | 4 | object Recv { 5 | 6 | private val QUEUE_NAME = "hello" 7 | 8 | def main(argv: Array[String]) { 9 | val factory = new ConnectionFactory() 10 | factory.setHost("localhost") 11 | val connection = factory.newConnection() 12 | val channel = connection.createChannel() 13 | channel.queueDeclare(QUEUE_NAME, false, false, false, null) 14 | println(" [*] Waiting for messages. To exit press CTRL+C") 15 | val deliverCallback: DeliverCallback = (_, delivery) => { 16 | val message = new String(delivery.getBody, "UTF-8") 17 | println(" [x] Received '" + message + "'") 18 | } 19 | channel.basicConsume(QUEUE_NAME, true, deliverCallback, _ => { }) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /scala/src/main/scala/Send.scala: -------------------------------------------------------------------------------- 1 | 2 | import com.rabbitmq.client.ConnectionFactory 3 | 4 | object Send { 5 | 6 | private val QUEUE_NAME = "hello" 7 | 8 | def main(argv: Array[String]) { 9 | val factory = new ConnectionFactory() 10 | factory.setHost("localhost") 11 | val connection = factory.newConnection() 12 | val channel = connection.createChannel() 13 | channel.queueDeclare(QUEUE_NAME, false, false, false, null) 14 | val message = "Hello World!" 15 | channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8")) 16 | println(" [x] Sent '" + message + "'") 17 | channel.close() 18 | connection.close() 19 | } 20 | } -------------------------------------------------------------------------------- /soapui/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/soapui/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /soapui/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip -------------------------------------------------------------------------------- /spring-amqp-stream/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/spring-amqp-stream/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-amqp-stream/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/java/org/springframework/amqp/tutorials/RabbitAmqpTutorialsRunner.java: -------------------------------------------------------------------------------- 1 | package org.springframework.amqp.tutorials; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.context.ConfigurableApplicationContext; 7 | 8 | public class RabbitAmqpTutorialsRunner implements CommandLineRunner { 9 | 10 | @Value("${tutorial.client.duration:0}") 11 | private int duration; 12 | 13 | @Autowired 14 | private ConfigurableApplicationContext ctx; 15 | 16 | @Override 17 | public void run(String... arg0) throws Exception { 18 | System.out.println("Ready ... running for " + duration + "ms"); 19 | Thread.sleep(duration); 20 | ctx.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/java/org/springframework/amqp/tutorials/tut1/Tut1Receiver.java: -------------------------------------------------------------------------------- 1 | package org.springframework.amqp.tutorials.tut1; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 4 | 5 | import com.rabbitmq.stream.Message; 6 | 7 | public class Tut1Receiver { 8 | 9 | @RabbitListener(queues="hello-spring-stream", containerFactory="nativeFactory") 10 | public void listen(Message message) { 11 | System.out.println("Received message: " + new String(message.getBodyAsBinary())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/java/org/springframework/amqp/tutorials/tut1/Tut1Sender.java: -------------------------------------------------------------------------------- 1 | package org.springframework.amqp.tutorials.tut1; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.rabbit.stream.producer.RabbitStreamTemplate; 5 | import org.springframework.scheduling.annotation.Scheduled; 6 | 7 | public class Tut1Sender { 8 | 9 | @Autowired 10 | private RabbitStreamTemplate template; 11 | 12 | @Scheduled(fixedDelay = 1000, initialDelay = 500) 13 | public void send() { 14 | String message = "Hello World!"; 15 | this.template.convertAndSend(message); 16 | System.out.println(" [x] Sent '" + message + "'"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/resources/application-remote.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: 3 | host: rabbitserver 4 | username: tutorial 5 | password: tutorial 6 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: usage_message 4 | 5 | logging: 6 | level: 7 | org: ERROR 8 | 9 | tutorial: 10 | client: 11 | duration: 10000 12 | -------------------------------------------------------------------------------- /spring-amqp-stream/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ __ ___ 2 | |__)_ |_ |_ .|_|\/|/ \ | |_ _ _. _ | _ 3 | | \(_||_)|_)||_| |\_\/ | |_||_(_)| |(_||_) 4 | -------------------------------------------------------------------------------- /spring-amqp/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rabbitmq/rabbitmq-tutorials/36a8421104713cd055100d0d027e43626a5ec05a/spring-amqp/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-amqp/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /spring-amqp/src/main/java/org/springframework/amqp/tutorials/tut1/Tut1Receiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.amqp.tutorials.tut1; 17 | 18 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 19 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 20 | 21 | /** 22 | * @author Gary Russell 23 | * @author Scott Deeg 24 | * @author Wayne Lund 25 | */ 26 | @RabbitListener(queues = "hello") 27 | public class Tut1Receiver { 28 | 29 | @RabbitHandler 30 | public void receive(String in) { 31 | System.out.println(" [x] Received '" + in + "'"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-amqp/src/main/resources/application-pcfdev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: 3 | host: rabbitmq.local.pcfdev.io 4 | username: f5e10385-1db5-4a98-9d96-99600f55a500 5 | password: u6nog1g1pjadcj95937bk41vgb 6 | virtualHost: 5888c0ff-a99e-4749-90c9-77167abb8616 -------------------------------------------------------------------------------- /spring-amqp/src/main/resources/application-remote.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: 3 | host: rabbitserver 4 | username: tutorial 5 | password: tutorial 6 | -------------------------------------------------------------------------------- /spring-amqp/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: usage_message 4 | 5 | logging: 6 | level: 7 | org: ERROR 8 | 9 | tutorial: 10 | client: 11 | duration: 10000 12 | -------------------------------------------------------------------------------- /spring-amqp/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ __ ___ 2 | |__)_ |_ |_ .|_|\/|/ \ | |_ _ _. _ | _ 3 | | \(_||_)|_)||_| |\_\/ | |_||_(_)| |(_||_) 4 | -------------------------------------------------------------------------------- /swift/.gitignore: -------------------------------------------------------------------------------- 1 | tutorial?/Carthage/Build 2 | tutorial?/Carthage/Checkouts 3 | *xcuserdata* 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /swift/bump_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | rm -rf ~/Library/Caches/org.carthage.CarthageKit 6 | 7 | for tutdir in `ls | grep "tutorial[1-9]"` 8 | do 9 | cd $tutdir 10 | carthage update --platform iOS 11 | cd .. 12 | done 13 | -------------------------------------------------------------------------------- /swift/tutorial1/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 2 | -------------------------------------------------------------------------------- /swift/tutorial1/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "robbiehanson/CocoaAsyncSocket" "7.5.1" 2 | github "jeffh/JKVValue" "v1.3.2" 3 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 4 | -------------------------------------------------------------------------------- /swift/tutorial1/tutorial1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swift/tutorial2/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 2 | -------------------------------------------------------------------------------- /swift/tutorial2/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "robbiehanson/CocoaAsyncSocket" "7.5.1" 2 | github "jeffh/JKVValue" "v1.3.2" 3 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 4 | -------------------------------------------------------------------------------- /swift/tutorial2/tutorial2.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swift/tutorial3/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 2 | -------------------------------------------------------------------------------- /swift/tutorial3/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "robbiehanson/CocoaAsyncSocket" "7.5.1" 2 | github "jeffh/JKVValue" "v1.3.2" 3 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 4 | -------------------------------------------------------------------------------- /swift/tutorial3/tutorial3.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swift/tutorial4/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 2 | -------------------------------------------------------------------------------- /swift/tutorial4/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "robbiehanson/CocoaAsyncSocket" "7.5.1" 2 | github "jeffh/JKVValue" "v1.3.2" 3 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 4 | -------------------------------------------------------------------------------- /swift/tutorial4/tutorial4.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swift/tutorial5/Cartfile: -------------------------------------------------------------------------------- 1 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 2 | -------------------------------------------------------------------------------- /swift/tutorial5/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "robbiehanson/CocoaAsyncSocket" "7.5.1" 2 | github "jeffh/JKVValue" "v1.3.2" 3 | github "rabbitmq/rabbitmq-objc-client" "v0.10.0" 4 | -------------------------------------------------------------------------------- /swift/tutorial5/tutorial5.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | --------------------------------------------------------------------------------