azure-messaging-eventhubs
Loading...
Searching...
No Matches
consumer_client.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// cspell: word myeventhub
5
6#pragma once
7#include "models/consumer_client_models.hpp"
8#include "models/management_models.hpp"
9#include "partition_client.hpp"
10
11#include <azure/core/amqp.hpp>
12#include <azure/core/amqp/internal/connection.hpp>
13#include <azure/core/context.hpp>
14#include <azure/core/credentials/credentials.hpp>
15#include <azure/core/diagnostics/logger.hpp>
16#include <azure/core/http/policies/policy.hpp>
17#include <azure/core/internal/diagnostics/log.hpp>
18namespace Azure { namespace Messaging { namespace EventHubs {
19
21 constexpr const char* DefaultConsumerGroup = "$Default";
22
26 {
29 std::string ApplicationID;
30
34 Azure::Core::Http::Policies::RetryOptions RetryOptions{};
35
37 std::string Name{};
38 };
39
49 class ConsumerClient final {
50 public:
52 ConsumerClient(ConsumerClient const& other) = delete;
53
55 ConsumerClient(ConsumerClient&& other) = delete;
56
58 ConsumerClient& operator=(ConsumerClient const& other) = delete;
59
62
64
69 std::string const& GetEventHubName() const { return m_eventHub; }
70
75 std::string const& GetConsumerGroup() const { return m_consumerGroup; }
76
82 {
84 details.ClientId = m_consumerClientOptions.ApplicationID;
85 details.ConsumerGroup = m_consumerGroup;
86 details.EventHubName = m_eventHub;
87 details.FullyQualifiedNamespace = m_fullyQualifiedNamespace;
88 return details;
89 }
94 Azure::Core::Http::Policies::RetryOptions const& GetRetryOptions() const
95 {
96 return m_consumerClientOptions.RetryOptions;
97 }
98
116 std::string const& connectionString,
117 std::string const& eventHub = {},
118 std::string const& consumerGroup = DefaultConsumerGroup,
119 ConsumerClientOptions const& options = {});
120
131 ConsumerClient(
132 std::string const& fullyQualifiedNamespace,
133 std::string const& eventHub,
134 std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential,
135 std::string const& consumerGroup = DefaultConsumerGroup,
136 ConsumerClientOptions const& options = {});
137
144 PartitionClient CreatePartitionClient(
145 std::string const& partitionId,
146 PartitionClientOptions const& options = {},
147 Azure::Core::Context const& context = {});
148
153 Models::EventHubProperties GetEventHubProperties(Core::Context const& context = {});
154
162 Models::EventHubPartitionProperties GetPartitionProperties(
163 std::string const& partitionID,
164 Core::Context const& context = {});
165
166 private:
168 std::string m_connectionString;
169
171 std::string m_fullyQualifiedNamespace;
172
174 std::string m_eventHub;
175
177 std::string m_consumerGroup;
178
180 std::shared_ptr<Core::Credentials::TokenCredential> m_credential;
181
183 std::string m_hostUrl;
184
186 std::mutex m_receiversLock;
187 std::map<std::string, Azure::Core::Amqp::_internal::MessageReceiver> m_receivers;
188
190 std::mutex m_sessionsLock;
191 std::map<std::string, Azure::Core::Amqp::_internal::Session> m_sessions;
192 std::map<std::string, Azure::Core::Amqp::_internal::Connection> m_connections;
193
195 ConsumerClientOptions m_consumerClientOptions;
196
197 void EnsureConnection(std::string const& partitionId);
198 void EnsureSession(std::string const& partitionId);
199 Azure::Core::Amqp::_internal::Connection CreateConnection(std::string const& partitionId) const;
200 Azure::Core::Amqp::_internal::Session CreateSession(std::string const& partitionId);
201 Azure::Core::Amqp::_internal::Session GetSession(std::string const& partitionId);
202 };
203}}} // namespace Azure::Messaging::EventHubs
The ConsumerClient class is a high level class used to consume events from an Event Hub.
Definition consumer_client.hpp:49
ConsumerClient & operator=(ConsumerClient const &other)=delete
Models::EventHubPartitionProperties GetPartitionProperties(std::string const &partitionID, Core::Context const &context={})
GetPartitionProperties gets properties for a specific partition. This includes data like the last enq...
Definition consumer_client.cpp:151
std::string const & GetConsumerGroup() const
Getter for consumer group name.
Definition consumer_client.hpp:75
PartitionClient CreatePartitionClient(std::string const &partitionId, PartitionClientOptions const &options={}, Azure::Core::Context const &context={})
Create new Partition client.
Definition consumer_client.cpp:124
ConsumerClient(ConsumerClient &&other)=delete
ConsumerClient & operator=(ConsumerClient &&other)=delete
ConsumerClient(ConsumerClient const &other)=delete
Models::EventHubProperties GetEventHubProperties(Core::Context const &context={})
GetEventHubProperties gets properties of an eventHub. This includes data like name,...
Definition consumer_client.cpp:143
std::string const & GetEventHubName() const
Getter for event hub name.
Definition consumer_client.hpp:69
Models::ConsumerClientDetails GetDetails() const
Getter for client details.
Definition consumer_client.hpp:81
Azure::Core::Http::Policies::RetryOptions const & GetRetryOptions() const
Getter for retry options.
Definition consumer_client.hpp:94
Contains options for the ConsumerClient creation.
Definition consumer_client.hpp:26
std::string ApplicationID
ApplicationID is used as the identifier when setting the User-Agent property.
Definition consumer_client.hpp:29
Azure::Core::Http::Policies::RetryOptions RetryOptions
RetryOptions controls how often operations are retried from this client and any Receivers and Senders...
Definition consumer_client.hpp:34
std::string Name
Name of the consumer client.
Definition consumer_client.hpp:37
Contains options for the ConsumerClient creation.
Definition consumer_client_models.hpp:13
std::string ClientId
A unique name used to identify this consumer.
Definition consumer_client_models.hpp:29
std::string FullyQualifiedNamespace
The Fully Qualified Namespace that the Event Hub exists in.
Definition consumer_client_models.hpp:16
std::string ConsumerGroup
The name of the consumer group that this consumer is associated with. Events will be read only in the...
Definition consumer_client_models.hpp:21
std::string EventHubName
The name of the Event Hub that the consumer is connected to.
Definition consumer_client_models.hpp:25