@@ -48,39 +48,51 @@ void actionConfirmOnThreadPool(
4848 const rmqt::ConfirmResponse& confirmResponse,
4949 const bsl::shared_ptr<ProducerImpl::SharedState>& sharedState)
5050{
51- bslmt::LockGuard<bslmt::Mutex> guard (&(sharedState->mutex ));
51+ rmqp::Producer::ConfirmationCallback callback;
52+ bsl::optional<rmqt::Future<>::Pair> waitForConfirmsFuture;
5253
53- if (!(sharedState->isValid )) {
54- BALL_LOG_ERROR << " Received publisher confirmation for message "
55- << message.guid () << " after closing the producer" ;
56- return ;
57- }
54+ {
55+ bslmt::LockGuard<bslmt::Mutex> guard (&(sharedState->mutex ));
5856
59- ProducerImpl::CallbackMap::iterator it =
60- sharedState->callbackMap .find (message.guid ());
61-
62- if (it == sharedState->callbackMap .end ()) {
63- BALL_LOG_FATAL
64- << " Failed to find Producer callback to invoke for message: "
65- << message.guid ()
66- << " . Received duplicate confirm? The outstanding "
67- " message limit will likely be affected for the lifetime of this "
68- " Producer instance." ;
69- return ;
70- }
57+ if (!(sharedState->isValid )) {
58+ BALL_LOG_ERROR << " Received publisher confirmation for message "
59+ << message.guid () << " after closing the producer" ;
60+ return ;
61+ }
62+
63+ ProducerImpl::CallbackMap::iterator it =
64+ sharedState->callbackMap .find (message.guid ());
65+
66+ if (it == sharedState->callbackMap .end ()) {
67+ BALL_LOG_ERROR
68+ << " Failed to find Producer callback to invoke for message: "
69+ << message.guid ()
70+ << " . Received duplicate confirm? The outstanding "
71+ " message limit will likely be affected for the lifetime of "
72+ " this "
73+ " Producer instance." ;
74+ return ;
75+ }
76+
77+ BALL_LOG_TRACE << confirmResponse << " for " << message;
78+
79+ callback.swap (it->second );
7180
72- BALL_LOG_TRACE << confirmResponse << " for " << message ;
81+ sharedState-> callbackMap . erase (it) ;
7382
74- sharedState->outstandingMessagesCap .post ();
83+ sharedState->outstandingMessagesCap .post ();
7584
76- it->second (message, routingKey, confirmResponse);
85+ if (sharedState->callbackMap .size () == 0 &&
86+ sharedState->waitForConfirmsFuture ) {
87+ waitForConfirmsFuture = sharedState->waitForConfirmsFuture ;
88+ sharedState->waitForConfirmsFuture .reset ();
89+ }
90+ }
7791
78- sharedState-> callbackMap . erase (it );
92+ callback (message, routingKey, confirmResponse );
7993
80- if (sharedState->callbackMap .size () == 0 &&
81- sharedState->waitForConfirmsFuture ) {
82- sharedState->waitForConfirmsFuture ->first (rmqt::Result<>());
83- sharedState->waitForConfirmsFuture .reset ();
94+ if (waitForConfirmsFuture) {
95+ waitForConfirmsFuture->first (rmqt::Result<>());
8496 }
8597}
8698
@@ -98,7 +110,7 @@ void handleConfirmOnEventLoop(
98110 sharedState));
99111
100112 if (rc != 0 ) {
101- BALL_LOG_FATAL
113+ BALL_LOG_ERROR
102114 << " Couldn't enqueue thread pool job for message confirm: "
103115 << message.guid () << " (return code " << rc
104116 << " ). Application will NEVER be informed of confirm" ;
0 commit comments