@@ -19,15 +19,19 @@ use std::collections::HashSet;
19
19
20
20
use rocketmq_common:: common:: consumer:: consume_from_where:: ConsumeFromWhere ;
21
21
use rocketmq_common:: common:: message:: message_queue:: MessageQueue ;
22
+ use rocketmq_common:: WeakCellWrapper ;
22
23
use rocketmq_remoting:: protocol:: body:: consumer_running_info:: ConsumerRunningInfo ;
23
24
use rocketmq_remoting:: protocol:: heartbeat:: consume_type:: ConsumeType ;
24
25
use rocketmq_remoting:: protocol:: heartbeat:: message_model:: MessageModel ;
25
26
use rocketmq_remoting:: protocol:: heartbeat:: subscription_data:: SubscriptionData ;
26
27
28
+ use crate :: consumer:: consumer_impl:: default_mq_push_consumer_impl:: DefaultMQPushConsumerImpl ;
29
+ use crate :: consumer:: consumer_impl:: pop_request:: PopRequest ;
30
+ use crate :: consumer:: consumer_impl:: pull_request:: PullRequest ;
27
31
use crate :: Result ;
28
32
#[ trait_variant:: make( MQConsumerInner : Send ) ]
29
33
pub trait MQConsumerInnerLocal : MQConsumerInnerAny + Sync + ' static {
30
- fn group_name ( & self ) -> & str ;
34
+ fn group_name ( & self ) -> String ;
31
35
32
36
fn message_model ( & self ) -> MessageModel ;
33
37
@@ -67,3 +71,152 @@ impl<T: MQConsumerInner> MQConsumerInnerAny for T {
67
71
self
68
72
}
69
73
}
74
+
75
+ #[ derive( Clone ) ]
76
+ pub ( crate ) struct MQConsumerInnerImpl {
77
+ pub ( crate ) default_mqpush_consumer_impl : Option < WeakCellWrapper < DefaultMQPushConsumerImpl > > ,
78
+ }
79
+
80
+ impl MQConsumerInnerImpl {
81
+ pub ( crate ) async fn pop_message ( & mut self , pop_request : PopRequest ) {
82
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
83
+ if let Some ( mut default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
84
+ default_mqpush_consumer_impl. pop_message ( pop_request) . await ;
85
+ }
86
+ }
87
+ }
88
+
89
+ pub ( crate ) async fn pull_message ( & mut self , pull_request : PullRequest ) {
90
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
91
+ if let Some ( mut default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
92
+ default_mqpush_consumer_impl
93
+ . pull_message ( pull_request)
94
+ . await ;
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ impl MQConsumerInner for MQConsumerInnerImpl {
101
+ fn group_name ( & self ) -> String {
102
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
103
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
104
+ return MQConsumerInner :: group_name ( default_mqpush_consumer_impl. as_ref ( ) ) ;
105
+ }
106
+ }
107
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
108
+ }
109
+
110
+ fn message_model ( & self ) -> MessageModel {
111
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
112
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
113
+ return MQConsumerInner :: message_model ( default_mqpush_consumer_impl. as_ref ( ) ) ;
114
+ }
115
+ }
116
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
117
+ }
118
+
119
+ fn consume_type ( & self ) -> ConsumeType {
120
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
121
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
122
+ return MQConsumerInner :: consume_type ( default_mqpush_consumer_impl. as_ref ( ) ) ;
123
+ }
124
+ }
125
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
126
+ }
127
+
128
+ fn consume_from_where ( & self ) -> ConsumeFromWhere {
129
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
130
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
131
+ return MQConsumerInner :: consume_from_where ( default_mqpush_consumer_impl. as_ref ( ) ) ;
132
+ }
133
+ }
134
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
135
+ }
136
+
137
+ fn subscriptions ( & self ) -> HashSet < SubscriptionData > {
138
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
139
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
140
+ return MQConsumerInner :: subscriptions ( default_mqpush_consumer_impl. as_ref ( ) ) ;
141
+ }
142
+ }
143
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
144
+ }
145
+
146
+ fn do_rebalance ( & self ) {
147
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
148
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
149
+ return MQConsumerInner :: do_rebalance ( default_mqpush_consumer_impl. as_ref ( ) ) ;
150
+ }
151
+ }
152
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
153
+ }
154
+
155
+ async fn try_rebalance ( & self ) -> Result < bool > {
156
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
157
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
158
+ return MQConsumerInner :: try_rebalance ( default_mqpush_consumer_impl. as_ref ( ) ) . await ;
159
+ }
160
+ }
161
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
162
+ }
163
+
164
+ async fn persist_consumer_offset ( & self ) {
165
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
166
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
167
+ return MQConsumerInner :: persist_consumer_offset (
168
+ default_mqpush_consumer_impl. as_ref ( ) ,
169
+ )
170
+ . await ;
171
+ }
172
+ }
173
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
174
+ }
175
+
176
+ async fn update_topic_subscribe_info ( & mut self , topic : & str , info : & HashSet < MessageQueue > ) {
177
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
178
+ if let Some ( mut default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
179
+ return MQConsumerInner :: update_topic_subscribe_info (
180
+ default_mqpush_consumer_impl. as_mut ( ) ,
181
+ topic,
182
+ info,
183
+ )
184
+ . await ;
185
+ }
186
+ }
187
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
188
+ }
189
+
190
+ async fn is_subscribe_topic_need_update ( & self , topic : & str ) -> bool {
191
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
192
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
193
+ return MQConsumerInner :: is_subscribe_topic_need_update (
194
+ default_mqpush_consumer_impl. as_ref ( ) ,
195
+ topic,
196
+ )
197
+ . await ;
198
+ }
199
+ }
200
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
201
+ }
202
+
203
+ fn is_unit_mode ( & self ) -> bool {
204
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
205
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
206
+ return MQConsumerInner :: is_unit_mode ( default_mqpush_consumer_impl. as_ref ( ) ) ;
207
+ }
208
+ }
209
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
210
+ }
211
+
212
+ fn consumer_running_info ( & self ) -> ConsumerRunningInfo {
213
+ if let Some ( ref default_mqpush_consumer_impl) = self . default_mqpush_consumer_impl {
214
+ if let Some ( default_mqpush_consumer_impl) = default_mqpush_consumer_impl. upgrade ( ) {
215
+ return MQConsumerInner :: consumer_running_info (
216
+ default_mqpush_consumer_impl. as_ref ( ) ,
217
+ ) ;
218
+ }
219
+ }
220
+ panic ! ( "default_mqpush_consumer_impl is None" ) ;
221
+ }
222
+ }
0 commit comments