azure-messaging-eventhubs
Loading...
Searching...
No Matches
producer_client.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// cspell: words myeventhub
5
6#pragma once
7#include "event_data_batch.hpp"
8#include "models/management_models.hpp"
9
10#include <azure/core/amqp.hpp>
11#include <azure/core/amqp/management.hpp>
12#include <azure/core/context.hpp>
13#include <azure/core/credentials/credentials.hpp>
14#include <azure/core/http/policies/policy.hpp>
15
16#include <iostream>
17
18namespace Azure { namespace Messaging { namespace EventHubs {
19
23 {
26 std::string ApplicationID = "";
27
31 Azure::Core::Http::Policies::RetryOptions RetryOptions{};
32
35 std::string Name{};
36
39 Azure::Nullable<std::uint64_t> MaxMessageSize{};
40 };
41
44 class ProducerClient final {
46 std::string m_connectionString;
47
49 std::string m_fullyQualifiedNamespace;
50
52 std::string m_eventHub{};
53
55 std::string m_targetUrl{};
56
58 std::shared_ptr<Core::Credentials::TokenCredential> m_credential{};
59
60 ProducerClientOptions m_producerClientOptions{};
61 std::map<std::string, Azure::Core::Amqp::_internal::MessageSender> m_senders{};
62 std::map<std::string, Azure::Core::Amqp::_internal::Session> m_sessions{};
63
64 public:
66 std::string const& GetEventHubName() { return m_eventHub; }
67
69 Azure::Core::Http::Policies::RetryOptions const& GetRetryOptions()
70 {
71 return m_producerClientOptions.RetryOptions;
72 }
73
75 ProducerClient(ProducerClient const& other) = default;
76
78 ProducerClient& operator=(ProducerClient const& other) = default;
79
81 ProducerClient() = default;
82
90 std::string const& connectionString,
91 std::string const& eventHub,
92 ProducerClientOptions options = {});
93
102 std::string const& fullyQualifiedNamespace,
103 std::string const& eventHub,
104 std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential,
105 ProducerClientOptions options = {});
106
107 ~ProducerClient()
108 {
109 for (auto& sender : m_senders)
110 {
111 sender.second.Close();
112 }
113 m_senders.clear();
114 }
115
122 EventDataBatch const& eventDataBatch,
123 Core::Context const& context = {});
124
130 Models::EventHubProperties GetEventHubProperties(Core::Context const& context = {});
131
139 Models::EventHubPartitionProperties GetPartitionProperties(
140 std::string const& partitionID,
141 Core::Context const& context = {});
142
143 private:
144 Azure::Core::Amqp::_internal::MessageSender GetSender(std::string const& partitionId = "");
145 void CreateSender(std::string const& partitionId = "");
146 };
147}}} // namespace Azure::Messaging::EventHubs
ProducerClient can be used to send events to an Event Hub.
Definition producer_client.hpp:44
std::string const & GetEventHubName()
Definition producer_client.hpp:66
ProducerClient & operator=(ProducerClient const &other)=default
bool SendEventDataBatch(EventDataBatch const &eventDataBatch, Core::Context const &context={})
Proceeds to send and EventDataBatch.
Definition producer_client.cpp:95
ProducerClient(ProducerClient const &other)=default
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 producer_client.cpp:129
Models::EventHubProperties GetEventHubProperties(Core::Context const &context={})
GetEventHubProperties gets properties of an eventHub. This includes data like name,...
Definition producer_client.cpp:117
Azure::Core::Http::Policies::RetryOptions const & GetRetryOptions()
Definition producer_client.hpp:69
Contains options for the ProducerClient creation.
Definition producer_client.hpp:23
Azure::Core::Http::Policies::RetryOptions RetryOptions
RetryOptions controls how often operations are retried from this client and any Receivers and Senders...
Definition producer_client.hpp:31
Azure::Nullable< std::uint64_t > MaxMessageSize
The maximum size of the message that can be sent.
Definition producer_client.hpp:39
std::string Name
The name of the producer client link, used in diagnostics.
Definition producer_client.hpp:35
std::string ApplicationID
Application ID that will be passed to the namespace.
Definition producer_client.hpp:26