RMQ - RabbitMQ C++ Library
rmqa_connectionmonitor.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#ifndef INCLUDED_RMQA_CONNECTIONMONITOR
17#define INCLUDED_RMQA_CONNECTIONMONITOR
18
19#include <rmqamqp_channelcontainer.h>
20#include <rmqamqp_connection.h>
21#include <rmqamqp_connectionmonitor.h>
22#include <rmqamqp_messagestore.h>
23#include <rmqio_task.h>
24#include <rmqt_future.h>
25#include <rmqt_message.h>
26
27#include <bsl_functional.h>
28#include <bsls_timeinterval.h>
29
30#include <bsl_list.h>
31#include <bsl_memory.h>
32#include <bsl_utility.h>
33#include <bsl_vector.h>
34
35namespace BloombergLP {
36namespace rmqa {
37
38class ConnectionMonitor : public rmqamqp::ConnectionMonitor,
39 public rmqio::Task {
40 public:
41 typedef bsl::function<void(
42 const rmqamqp::MessageStore<rmqt::Message>::Entry&)>
43 HungMessageCallback;
44
45 explicit ConnectionMonitor(
46 const bsls::TimeInterval& messageProcessingTimeout,
47 const HungMessageCallback& callback = HungMessageCallback());
48
49 void
50 addConnection(const bsl::weak_ptr<rmqamqp::ChannelContainer>& connection)
51 BSLS_KEYWORD_OVERRIDE;
52
53 void run() BSLS_KEYWORD_OVERRIDE;
54
56 typedef bsl::pair<bsl::string, bsl::vector<bsl::string> >
57 ConnectionChannelsInfo;
58
59 bsl::vector<ConnectionChannelsInfo> aliveConnectionChannelInfo;
60 };
61
64 bsl::shared_ptr<AliveConnectionInfo> fetchAliveConnectionInfo();
65
66 private:
67 void processHungMessages(
68 const rmqamqp::MessageStore<rmqt::Message>::MessageList& hungMessages);
69 bsls::TimeInterval d_messageProcessingTimeout;
70 HungMessageCallback d_callback;
71 bsl::list<bsl::weak_ptr<rmqamqp::ChannelContainer> > d_connections;
72};
73
74} // namespace rmqa
75} // namespace BloombergLP
76
77#endif
Definition: rmqa_connectionmonitor.h:39
bsl::shared_ptr< AliveConnectionInfo > fetchAliveConnectionInfo()
Definition: rmqa_connectionmonitor.cpp:115
Definition: rmqa_connectionmonitor.h:55