21
21
import java .io .UnsupportedEncodingException ;
22
22
import java .net .InetSocketAddress ;
23
23
import java .net .SocketAddress ;
24
+ import java .net .UnknownHostException ;
24
25
import java .util .HashMap ;
25
26
import java .util .HashSet ;
26
27
import java .util .Iterator ;
45
46
import com .alibaba .rocketmq .common .admin .TopicOffset ;
46
47
import com .alibaba .rocketmq .common .admin .TopicStatsTable ;
47
48
import com .alibaba .rocketmq .common .constant .LoggerName ;
49
+ import com .alibaba .rocketmq .common .message .MessageDecoder ;
50
+ import com .alibaba .rocketmq .common .message .MessageId ;
48
51
import com .alibaba .rocketmq .common .message .MessageQueue ;
49
52
import com .alibaba .rocketmq .common .protocol .RequestCode ;
50
53
import com .alibaba .rocketmq .common .protocol .ResponseCode ;
90
93
import com .alibaba .rocketmq .common .protocol .header .filtersrv .RegisterFilterServerResponseHeader ;
91
94
import com .alibaba .rocketmq .common .protocol .heartbeat .SubscriptionData ;
92
95
import com .alibaba .rocketmq .common .subscription .SubscriptionGroupConfig ;
93
- import com .alibaba .rocketmq .remoting .CommandCustomHeader ;
94
96
import com .alibaba .rocketmq .remoting .common .RemotingHelper ;
95
97
import com .alibaba .rocketmq .remoting .exception .RemotingCommandException ;
96
98
import com .alibaba .rocketmq .remoting .netty .NettyRequestProcessor ;
97
99
import com .alibaba .rocketmq .remoting .protocol .RemotingCommand ;
98
100
import com .alibaba .rocketmq .remoting .protocol .RemotingSerializable ;
99
101
import com .alibaba .rocketmq .store .DefaultMessageStore ;
102
+ import com .alibaba .rocketmq .store .SelectMapedBufferResult ;
100
103
101
104
102
105
/**
@@ -231,7 +234,7 @@ public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand
231
234
232
235
private RemotingCommand callConsumer (//
233
236
final int requestCode ,//
234
- final CommandCustomHeader requestHeader , //
237
+ final RemotingCommand request , //
235
238
final String consumerGroup ,//
236
239
final String clientId ) throws RemotingCommandException {
237
240
final RemotingCommand response = RemotingCommand .createResponseCommand (null );
@@ -254,7 +257,10 @@ private RemotingCommand callConsumer(//
254
257
}
255
258
256
259
try {
257
- RemotingCommand newRequest = RemotingCommand .createRequestCommand (requestCode , requestHeader );
260
+ RemotingCommand newRequest = RemotingCommand .createRequestCommand (requestCode , null );
261
+ newRequest .setExtFields (request .getExtFields ());
262
+ newRequest .setBody (request .getBody ());
263
+
258
264
RemotingCommand consumerResponse =
259
265
this .brokerController .getBroker2Client ().callClient (clientChannelInfo .getChannel (),
260
266
newRequest );
@@ -274,7 +280,27 @@ private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, Remoti
274
280
final ConsumeMessageDirectlyResultRequestHeader requestHeader =
275
281
(ConsumeMessageDirectlyResultRequestHeader ) request
276
282
.decodeCommandCustomHeader (ConsumeMessageDirectlyResultRequestHeader .class );
277
- return this .callConsumer (RequestCode .CONSUME_MESSAGE_DIRECTLY , requestHeader ,
283
+
284
+ request .getExtFields ().put ("brokerName" , this .brokerController .getBrokerConfig ().getBrokerName ());
285
+ SelectMapedBufferResult selectMapedBufferResult = null ;
286
+ try {
287
+ MessageId messageId = MessageDecoder .decodeMessageId (requestHeader .getMsgId ());
288
+ selectMapedBufferResult =
289
+ this .brokerController .getMessageStore ().selectOneMessageByOffset (messageId .getOffset ());
290
+
291
+ byte [] body = new byte [selectMapedBufferResult .getSize ()];
292
+ selectMapedBufferResult .getByteBuffer ().get (body );
293
+ request .setBody (body );
294
+ }
295
+ catch (UnknownHostException e ) {
296
+ }
297
+ finally {
298
+ if (selectMapedBufferResult != null ) {
299
+ selectMapedBufferResult .release ();
300
+ }
301
+ }
302
+
303
+ return this .callConsumer (RequestCode .CONSUME_MESSAGE_DIRECTLY , request ,
278
304
requestHeader .getConsumerGroup (), requestHeader .getClientId ());
279
305
}
280
306
@@ -288,7 +314,7 @@ private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, Remoti
288
314
(GetConsumerRunningInfoRequestHeader ) request
289
315
.decodeCommandCustomHeader (GetConsumerRunningInfoRequestHeader .class );
290
316
291
- return this .callConsumer (RequestCode .GET_CONSUMER_RUNNING_INFO , requestHeader ,
317
+ return this .callConsumer (RequestCode .GET_CONSUMER_RUNNING_INFO , request ,
292
318
requestHeader .getConsumerGroup (), requestHeader .getClientId ());
293
319
}
294
320
0 commit comments