RMQ - RabbitMQ C++ Library
rmqa_connectionimpl.h
1// Copyright 2020-2023 Bloomberg Finance L.P.
2// SPDX-License-Identifier: Apache-2.0
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// http://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// rmqa_connectionimpl.h
17#ifndef INCLUDED_RMQA_CONNECTIONIMPL
18#define INCLUDED_RMQA_CONNECTIONIMPL
19
20#include <rmqa_consumer.h>
21#include <rmqa_consumerimpl.h>
22#include <rmqa_producerimpl.h>
23
24#include <rmqamqp_connection.h>
25
26#include <rmqio_eventloop.h>
27#include <rmqio_resolver.h>
28
29#include <rmqp_connection.h>
30#include <rmqp_consumer.h>
31#include <rmqp_producer.h>
32
33#include <rmqt_credentials.h>
34#include <rmqt_endpoint.h>
35#include <rmqt_future.h>
36#include <rmqt_properties.h>
37#include <rmqt_result.h>
38
39#include <bdlmt_threadpool.h>
40#include <bslma_managedptr.h>
41#include <bsls_keyword.h>
42
43#include <bsl_functional.h>
44#include <bsl_memory.h>
45#include <bsl_string.h>
46
47//@PURPOSE: Provide a RabbitMQ Connection API
48//
49//@CLASSES:
50// rmqa::ConnectionImpl: Implementation of rmqp::Connection
51
52namespace BloombergLP {
53namespace rmqa {
54
56 public bsl::enable_shared_from_this<ConnectionImpl> {
57 public:
58 static bsl::shared_ptr<rmqa::ConnectionImpl>
59 make(const bsl::shared_ptr<rmqamqp::Connection>& amqpConn,
60 rmqio::EventLoop& eventLoop,
61 bdlmt::ThreadPool& threadpool,
62 const rmqt::ErrorCallback& errorCb,
63 const bsl::shared_ptr<rmqt::Endpoint>& endpoint,
64 const rmqt::Tunables& tunables,
65 const bsl::shared_ptr<rmqa::ConsumerImpl::Factory>& consumerFactory,
66 const bsl::shared_ptr<rmqa::ProducerImpl::Factory>& producerFactory);
67
68 void close() BSLS_KEYWORD_OVERRIDE;
69
71 createProducer(const rmqt::Topology& topology,
72 rmqt::ExchangeHandle exchange,
73 uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE;
74
76 const rmqt::Topology& topology,
77 rmqt::QueueHandle queue,
78 const rmqp::Consumer::ConsumerFunc& onMessage,
79 const rmqt::ConsumerConfig& consumerConfig) BSLS_KEYWORD_OVERRIDE;
80
82 createProducerAsync(const rmqt::Topology& topology,
83 rmqt::ExchangeHandle exchange,
84 uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE;
85
86 rmqt::Future<rmqp::Consumer> createConsumerAsync(
87 const rmqt::Topology& topology,
88 rmqt::QueueHandle queue,
89 const rmqp::Consumer::ConsumerFunc& onMessage,
90 const rmqt::ConsumerConfig& consumerConfig) BSLS_KEYWORD_OVERRIDE;
91
92 ~ConnectionImpl() BSLS_KEYWORD_OVERRIDE;
93
94 private:
96 const bsl::shared_ptr<rmqamqp::Connection>& amqpConn,
97 rmqio::EventLoop& loop,
98 bdlmt::ThreadPool& threadPool,
99 const rmqt::ErrorCallback& errorCb,
100 const bsl::shared_ptr<rmqt::Endpoint>& endpoint,
101 const rmqt::Tunables& tunables,
102 const bsl::shared_ptr<rmqa::ConsumerImpl::Factory>& consumerFactory,
103 const bsl::shared_ptr<rmqa::ProducerImpl::Factory>& producerFactory);
104
105 void ready(bool success = true);
106 void doClose();
107
108 void closeImpl();
109
110 rmqt::Tunables d_tunables;
111 bsl::shared_ptr<rmqamqp::Connection> d_connection;
112 bdlmt::ThreadPool& d_threadPool;
113 rmqio::EventLoop& d_eventLoop;
114 rmqt::ErrorCallback d_onError;
115 bsl::shared_ptr<rmqt::Endpoint> d_endpoint;
117 bsl::shared_ptr<rmqa::ConsumerImpl::Factory> d_consumerFactory;
118 bsl::shared_ptr<rmqa::ProducerImpl::Factory> d_producerFactory;
119};
120
121} // namespace rmqa
122} // namespace BloombergLP
123
124#endif // ! INCLUDED_RMQA_CONNECTION
Definition: rmqa_connectionimpl.h:56
void close() BSLS_KEYWORD_OVERRIDE
Flush all data pending and then close the connection. Close the connection and invalidates all consum...
Definition: rmqa_connectionimpl.cpp:178
rmqt::Result< rmqp::Producer > createProducer(const rmqt::Topology &topology, rmqt::ExchangeHandle exchange, uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE
Definition: rmqa_connectionimpl.cpp:233
rmqt::Result< rmqp::Consumer > createConsumer(const rmqt::Topology &topology, rmqt::QueueHandle queue, const rmqp::Consumer::ConsumerFunc &onMessage, const rmqt::ConsumerConfig &consumerConfig) BSLS_KEYWORD_OVERRIDE
Create an asynchronous consumer using the provided Topology.
Definition: rmqa_connectionimpl.cpp:242
Provide a RabbitMQ Connection API.
Definition: rmqp_connection.h:42
bsl::function< void(rmqp::MessageGuard &)> ConsumerFunc
Callback function used to receive messages.
Definition: rmqp_consumer.h:48
Class for passing arguments to Consumer.
Definition: rmqt_consumerconfig.h:42
An async-style Future/Promise object.
Definition: rmqt_future.h:108
A result of an operation.
Definition: rmqt_result.h:37
Definition: rmqt_topology.h:32