-
Notifications
You must be signed in to change notification settings - Fork 378
feat rabbitmq: heartbeat and message headers support #1129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d23a777
feat: improved RabbitMQ driver
0d16930
refactor: review points resolved
4cf229b
fix: fixes after review
7bdba57
fix: fixes after review
591f9ec
fix: fixes after review
55205bd
refactor: full rework consume message headers
4fc56a0
refactor: extract AMQP field string conversion helper
2f17b93
feat: rabbitmq support integral header values in publish
3b017e5
feat: improved rabbitmq headers
8a04765
fix: fixes after review
22e03c8
feat: fix after review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| #include <amqpcpp.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
|
|
||
| #include <userver/formats/common/type.hpp> | ||
| #include <userver/formats/json/value_builder.hpp> | ||
| #include <userver/utest/utest.hpp> | ||
|
|
||
| #include <urabbitmq/impl/header_value.hpp> | ||
|
|
||
| USERVER_NAMESPACE_BEGIN | ||
|
|
||
| namespace { | ||
|
|
||
| template <typename T> | ||
| urabbitmq::HeaderValue MakeHeaderValue(T&& value) { | ||
| return urabbitmq::HeaderValue::Builder{std::forward<T>(value)}.ExtractValue(); | ||
| } | ||
|
|
||
| urabbitmq::HeaderValue MakeNestedArrayValue() { | ||
| urabbitmq::HeaderValue::Builder builder{formats::common::Type::kArray}; | ||
| builder.PushBack(std::int64_t{-7}); | ||
| builder.PushBack("array-value"); | ||
|
|
||
| urabbitmq::HeaderValue::Builder nested_object{formats::common::Type::kObject}; | ||
| nested_object["enabled"] = false; | ||
| nested_object["nullable"] = urabbitmq::HeaderValue::Builder{}; | ||
| builder.PushBack(std::move(nested_object)); | ||
|
|
||
| return builder.ExtractValue(); | ||
| } | ||
|
|
||
| urabbitmq::HeaderValue MakeNestedObjectValue() { | ||
| urabbitmq::HeaderValue::Builder builder{formats::common::Type::kObject}; | ||
| builder["count"] = std::uint64_t{42}; | ||
| builder["name"] = "nested-object"; | ||
| builder["array"] = urabbitmq::HeaderValue::Builder{MakeNestedArrayValue()}; | ||
|
|
||
| return builder.ExtractValue(); | ||
| } | ||
|
|
||
| void ExpectHeadersEqual( | ||
| const std::unordered_map<std::string, urabbitmq::HeaderValue>& actual, | ||
| const std::unordered_map<std::string, urabbitmq::HeaderValue>& expected | ||
| ) { | ||
| ASSERT_EQ(actual.size(), expected.size()); | ||
| for (const auto& [key, expected_value] : expected) { | ||
| const auto it = actual.find(key); | ||
| ASSERT_NE(it, actual.end()) << "Missing key: " << key; | ||
| EXPECT_EQ(it->second, expected_value) << "Unexpected value for key: " << key; | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| UTEST(HeaderValue, ConvertsNestedAmqpTypes) { | ||
| AMQP::Table headers; | ||
| headers.set("string", "value"); | ||
| headers.set("bool", true); | ||
| headers.set("signed", static_cast<std::int16_t>(-10)); | ||
| headers.set("unsigned", static_cast<std::uint16_t>(10)); | ||
| headers.set("double", AMQP::Double{1.5}); | ||
| headers.set("null", nullptr); | ||
|
|
||
| AMQP::Array nested_array; | ||
| nested_array.push_back(AMQP::LongLong{-7}); | ||
| nested_array.push_back(AMQP::LongString{"array-value"}); | ||
| AMQP::Table nested_array_object; | ||
| nested_array_object.set("enabled", false); | ||
| nested_array_object.set("nullable", nullptr); | ||
| nested_array.push_back(nested_array_object); | ||
| headers.set("array", nested_array); | ||
|
|
||
| AMQP::Table nested_object; | ||
| nested_object.set("count", static_cast<std::uint32_t>(42)); | ||
| nested_object.set("name", "nested-object"); | ||
| nested_object.set("array", nested_array); | ||
| headers.set("object", nested_object); | ||
|
|
||
| const std::unordered_map<std::string, urabbitmq::HeaderValue> expected{ | ||
| {"string", MakeHeaderValue("value")}, | ||
| {"bool", MakeHeaderValue(true)}, | ||
| {"signed", MakeHeaderValue(-10)}, | ||
| {"unsigned", MakeHeaderValue(10u)}, | ||
| {"double", MakeHeaderValue(1.5)}, | ||
| {"null", urabbitmq::HeaderValue::Builder{}.ExtractValue()}, | ||
| {"array", MakeNestedArrayValue()}, | ||
| {"object", MakeNestedObjectValue()}, | ||
| }; | ||
|
|
||
| const auto actual = urabbitmq::impl::TableToHeaders(headers); | ||
| ExpectHeadersEqual(actual, expected); | ||
| EXPECT_TRUE(actual.at("signed").IsInt()); | ||
| EXPECT_TRUE(actual.at("unsigned").IsUInt()); | ||
| } | ||
|
|
||
| UTEST(HeaderValue, RoundTripsHeaders) { | ||
| const std::unordered_map<std::string, urabbitmq::HeaderValue> expected{ | ||
| {"string", MakeHeaderValue("value")}, | ||
| {"bool", MakeHeaderValue(false)}, | ||
| {"signed", MakeHeaderValue(-123456789)}, | ||
| {"signed64", MakeHeaderValue(std::int64_t{-1234567890123})}, | ||
| {"unsigned", MakeHeaderValue(123456789u)}, | ||
| {"unsigned64", MakeHeaderValue(std::uint64_t{1234567890123})}, | ||
| {"double", MakeHeaderValue(3.25)}, | ||
| {"null", urabbitmq::HeaderValue::Builder{}.ExtractValue()}, | ||
| {"array", MakeNestedArrayValue()}, | ||
| {"object", MakeNestedObjectValue()}, | ||
| }; | ||
|
|
||
| AMQP::Table table; | ||
| urabbitmq::impl::AddHeadersToTable(table, expected); | ||
|
|
||
| const auto actual = urabbitmq::impl::TableToHeaders(table); | ||
| ExpectHeadersEqual(actual, expected); | ||
| EXPECT_TRUE(actual.at("signed").IsInt()); | ||
| EXPECT_TRUE(actual.at("signed64").IsInt64()); | ||
| EXPECT_TRUE(actual.at("unsigned").IsUInt()); | ||
| EXPECT_TRUE(actual.at("unsigned64").IsUInt64()); | ||
| } | ||
|
|
||
| USERVER_NAMESPACE_END |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.