RMQ - RabbitMQ C++ Library
rmqa_vhostimpl.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_vhostimpl.h
17#ifndef INCLUDED_RMQA_VHOSTIMPL
18#define INCLUDED_RMQA_VHOSTIMPL
19
20#include <rmqp_connection.h>
21#include <rmqp_consumer.h>
22#include <rmqp_producer.h>
23#include <rmqt_topology.h>
24
25#include <bsl_functional.h>
26#include <bslma_managedptr.h>
27#include <bslmt_mutex.h>
28
29namespace BloombergLP {
30namespace rmqa {
31
33
35 public:
36 typedef bsl::function<rmqt::Future<rmqp::Connection>(
37 const bsl::string& suffix)>
38 ConnectionMaker;
39
40 explicit VHostImpl(const ConnectionMaker& connectionMaker);
41
43 createProducer(const rmqt::Topology& topology,
44 rmqt::ExchangeHandle exchange,
45 uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE;
46
48 createConsumer(const rmqt::Topology& topology,
49 rmqt::QueueHandle queue,
50 const rmqp::Consumer::ConsumerFunc& onMessage,
51 const rmqt::ConsumerConfig& config) BSLS_KEYWORD_OVERRIDE;
52
54 createProducerAsync(const rmqt::Topology& topology,
55 rmqt::ExchangeHandle exchange,
56 uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE;
57
58 rmqt::Future<rmqp::Consumer> createConsumerAsync(
59 const rmqt::Topology& topology,
60 rmqt::QueueHandle queue,
61 const rmqp::Consumer::ConsumerFunc& onMessage,
62 const rmqt::ConsumerConfig& config) BSLS_KEYWORD_OVERRIDE;
63
64 void close() BSLS_KEYWORD_OVERRIDE;
65
66 private:
67 ConnectionMaker d_newConnection;
68 bslmt::Mutex d_connectionMutex;
69 bslma::ManagedPtr<rmqt::Future<rmqp::Connection> > d_consumerFuture;
70 bslma::ManagedPtr<rmqt::Future<rmqp::Connection> > d_producerFuture;
71
72 private:
73 VHostImpl(const VHostImpl&) BSLS_KEYWORD_DELETED;
74 VHostImpl& operator=(const VHostImpl&) BSLS_KEYWORD_DELETED;
75};
76} // namespace rmqa
77} // namespace BloombergLP
78
79#endif
A RabbitMQ VHost Implementation of the rmqp::Connection interface.
Definition: rmqa_vhostimpl.h:34
rmqt::Result< rmqp::Producer > createProducer(const rmqt::Topology &topology, rmqt::ExchangeHandle exchange, uint16_t maxOutstandingConfirms) BSLS_KEYWORD_OVERRIDE
Definition: rmqa_vhostimpl.cpp:71
void close() BSLS_KEYWORD_OVERRIDE
Flush all data pending and then close the connection. Close the connection and invalidates all consum...
Definition: rmqa_vhostimpl.cpp:135
rmqt::Result< rmqp::Consumer > createConsumer(const rmqt::Topology &topology, rmqt::QueueHandle queue, const rmqp::Consumer::ConsumerFunc &onMessage, const rmqt::ConsumerConfig &config) BSLS_KEYWORD_OVERRIDE
Create an asynchronous consumer using the provided Topology.
Definition: rmqa_vhostimpl.cpp:80
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