Skip to content

Commit

Permalink
Storage Queue API review feedback (#2801)
Browse files Browse the repository at this point in the history
* fix

* sample

* CL

* service version

* fix

* ACL
  • Loading branch information
Jinming-Hu authored Aug 27, 2021
1 parent 8cae429 commit b801318
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 109 deletions.
1 change: 0 additions & 1 deletion sdk/storage/azure-storage-queues/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
- QueueClient::Create
- QueueClient::CreateIfNotExists
- QueueClient::Delete
- QueueClient::DeleteIfExists
- QueueClient::GetProperties
- QueueClient::SetMetadata
- QueueClient::GetAccessPolicy
Expand Down
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-queues/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(
AZURE_STORAGE_QUEUE_SOURCE
src/private/package_version.hpp
src/queue_client.cpp
src/queue_options.cpp
src/queue_responses.cpp
src/queue_rest_client.cpp
src/queue_sas_builder.cpp
Expand Down Expand Up @@ -93,6 +94,7 @@ if(BUILD_STORAGE_SAMPLES)
target_sources(
azure-storage-sample
PRIVATE
sample/queue_encode_message.cpp
sample/queue_getting_started.cpp
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ namespace Azure { namespace Storage { namespace Queues {
std::string m_value;
}; // extensible enum GeoReplicationStatus

/**
* @brief A peeked message object stored in the queue.
*/
struct PeekedQueueMessage final
{
/**
* The content of the message.
*/
std::string MessageText;
/**
* A GUID value that identifies the message in the queue.
*/
std::string MessageId;
/**
* The time the message was inserted into the queue.
*/
Azure::DateTime InsertedOn;
/**
* The time that the message will expire and be automatically deleted from the queue.
*/
Azure::DateTime ExpiresOn;
/**
* The number of times the message has been dequeued.
*/
int64_t DequeueCount = 0;
}; // struct PeekedQueueMessage

/**
* @brief A queue item from the result of
* #Azure::Storage::Queues::QueueServiceClient::ListQueues.
Expand All @@ -77,7 +104,7 @@ namespace Azure { namespace Storage { namespace Queues {
/**
* The content of the message.
*/
std::string Body;
std::string MessageText;
/**
* A GUID value that identifies the message in the queue.
*/
Expand All @@ -91,13 +118,11 @@ namespace Azure { namespace Storage { namespace Queues {
*/
Azure::DateTime ExpiresOn;
/**
* An opaque string that is required to delete or update a message. Empty if it's a peeked
* message.
* An opaque string that is required to delete or update a message.
*/
std::string PopReceipt;
/**
* The time that the message will again become visible in the queue. Invalid if it's a peeked
* message.
* The time that the message will again become visible in the queue.
*/
Azure::DateTime NextVisibleOn;
/**
Expand Down Expand Up @@ -134,11 +159,11 @@ namespace Azure { namespace Storage { namespace Queues {
/**
* Date and time since when this policy is active.
*/
Azure::DateTime StartsOn;
Azure::Nullable<Azure::DateTime> StartsOn;
/**
* Date and time the policy expires.
*/
Azure::DateTime ExpiresOn;
Azure::Nullable<Azure::DateTime> ExpiresOn;
/**
* The permissions for this ACL policy.
*/
Expand Down Expand Up @@ -346,7 +371,7 @@ namespace Azure { namespace Storage { namespace Queues {
/**
* A vector of peeked messages.
*/
std::vector<QueueMessage> Messages;
std::vector<PeekedQueueMessage> Messages;
}; // struct PeekMessagesResult

/**
Expand Down Expand Up @@ -1740,7 +1765,7 @@ namespace Azure { namespace Storage { namespace Queues {
struct EnqueueMessageOptions final
{
Azure::Nullable<int32_t> Timeout;
std::string Body;
std::string MessageText;
Azure::Nullable<std::chrono::seconds> VisibilityTimeout;
Azure::Nullable<std::chrono::seconds> TimeToLive;
}; // struct EnqueueMessageOptions
Expand Down Expand Up @@ -1993,7 +2018,7 @@ namespace Azure { namespace Storage { namespace Queues {

struct UpdateMessageOptions final
{
std::string Body;
std::string MessageText;
Azure::Nullable<int32_t> Timeout;
std::string PopReceipt;
std::chrono::seconds VisibilityTimeout;
Expand Down Expand Up @@ -2199,7 +2224,7 @@ namespace Azure { namespace Storage { namespace Queues {
if (path.size() == 2 && path[0] == XmlTagName::k_QueueMessagesList
&& path[1] == XmlTagName::k_QueueMessage)
{
ret.Messages.emplace_back(QueueMessageFromXml(reader));
ret.Messages.emplace_back(PeekedQueueMessageFromXml(reader));
path.pop_back();
}
}
Expand Down Expand Up @@ -2322,6 +2347,93 @@ namespace Azure { namespace Storage { namespace Queues {
return ret;
}

static PeekedQueueMessage PeekedQueueMessageFromXml(_internal::XmlReader& reader)
{
PeekedQueueMessage ret;
enum class XmlTagName
{
k_MessageText,
k_MessageId,
k_InsertionTime,
k_ExpirationTime,
k_DequeueCount,
k_Unknown,
};
std::vector<XmlTagName> path;
while (true)
{
auto node = reader.Read();
if (node.Type == _internal::XmlNodeType::End)
{
break;
}
else if (node.Type == _internal::XmlNodeType::EndTag)
{
if (path.size() > 0)
{
path.pop_back();
}
else
{
break;
}
}
else if (node.Type == _internal::XmlNodeType::StartTag)
{
if (node.Name == "MessageText")
{
path.emplace_back(XmlTagName::k_MessageText);
}
else if (node.Name == "MessageId")
{
path.emplace_back(XmlTagName::k_MessageId);
}
else if (node.Name == "InsertionTime")
{
path.emplace_back(XmlTagName::k_InsertionTime);
}
else if (node.Name == "ExpirationTime")
{
path.emplace_back(XmlTagName::k_ExpirationTime);
}
else if (node.Name == "DequeueCount")
{
path.emplace_back(XmlTagName::k_DequeueCount);
}
else
{
path.emplace_back(XmlTagName::k_Unknown);
}
}
else if (node.Type == _internal::XmlNodeType::Text)
{
if (path.size() == 1 && path[0] == XmlTagName::k_MessageText)
{
ret.MessageText = node.Value;
}
else if (path.size() == 1 && path[0] == XmlTagName::k_MessageId)
{
ret.MessageId = node.Value;
}
else if (path.size() == 1 && path[0] == XmlTagName::k_InsertionTime)
{
ret.InsertedOn
= Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
}
else if (path.size() == 1 && path[0] == XmlTagName::k_ExpirationTime)
{
ret.ExpiresOn
= Azure::DateTime::Parse(node.Value, Azure::DateTime::DateFormat::Rfc1123);
}
else if (path.size() == 1 && path[0] == XmlTagName::k_DequeueCount)
{
ret.DequeueCount = std::stoll(node.Value);
}
}
}
return ret;
}

static QueueMessage QueueMessageFromXml(_internal::XmlReader& reader)
{
QueueMessage ret;
Expand Down Expand Up @@ -2394,7 +2506,7 @@ namespace Azure { namespace Storage { namespace Queues {
{
if (path.size() == 1 && path[0] == XmlTagName::k_MessageText)
{
ret.Body = node.Value;
ret.MessageText = node.Value;
}
else if (path.size() == 1 && path[0] == XmlTagName::k_MessageId)
{
Expand Down Expand Up @@ -2524,7 +2636,7 @@ namespace Azure { namespace Storage { namespace Queues {
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "QueueMessage"});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MessageText"});
writer.Write(
_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.Body});
_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.MessageText});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
}
Expand All @@ -2548,7 +2660,7 @@ namespace Azure { namespace Storage { namespace Queues {
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "QueueMessage"});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "MessageText"});
writer.Write(
_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.Body});
_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.MessageText});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
}
Expand All @@ -2562,22 +2674,28 @@ namespace Azure { namespace Storage { namespace Queues {
writer.Write(_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.Id});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "AccessPolicy"});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"});
writer.Write(_internal::XmlNode{
_internal::XmlNodeType::Text,
std::string(),
options.StartsOn.ToString(
Azure::DateTime::DateFormat::Rfc3339,
Azure::DateTime::TimeFractionFormat::AllDigits)});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"});
writer.Write(_internal::XmlNode{
_internal::XmlNodeType::Text,
std::string(),
options.ExpiresOn.ToString(
Azure::DateTime::DateFormat::Rfc3339,
Azure::DateTime::TimeFractionFormat::AllDigits)});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
if (options.StartsOn.HasValue())
{
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Start"});
writer.Write(_internal::XmlNode{
_internal::XmlNodeType::Text,
std::string(),
options.StartsOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339,
Azure::DateTime::TimeFractionFormat::AllDigits)});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
}
if (options.ExpiresOn.HasValue())
{
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Expiry"});
writer.Write(_internal::XmlNode{
_internal::XmlNodeType::Text,
std::string(),
options.ExpiresOn.Value().ToString(
Azure::DateTime::DateFormat::Rfc3339,
Azure::DateTime::TimeFractionFormat::AllDigits)});
writer.Write(_internal::XmlNode{_internal::XmlNodeType::EndTag});
}
writer.Write(_internal::XmlNode{_internal::XmlNodeType::StartTag, "Permission"});
writer.Write(
_internal::XmlNode{_internal::XmlNodeType::Text, std::string(), options.Permissions});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,15 @@ namespace Azure { namespace Storage { namespace Queues {
const CreateQueueOptions& options = CreateQueueOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Marks the specified queue for deletion.
*
* @param options Optional parameters to execute this function.
* @param context Context for cancelling long running operations.
* @return A DeleteQueueResult if successful.
*/
Azure::Response<Models::DeleteQueueResult> Delete(
const DeleteQueueOptions& options = DeleteQueueOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

/**
* @brief Marks the specified queue for deletion if it exists.
*
* @param options Optional parameters to execute this function.
* @param context Context for cancelling long running operations.
* @return A DeleteQueueResult if successful.
* @return DeleteQueueResult.Deleted will be true if successful, false if the queue doesn't
* exist.
*/
Azure::Response<Models::DeleteQueueResult> DeleteIfExists(
Azure::Response<Models::DeleteQueueResult> Delete(
const DeleteQueueOptions& options = DeleteQueueOptions(),
const Azure::Core::Context& context = Azure::Core::Context()) const;

Expand Down
Loading

0 comments on commit b801318

Please sign in to comment.