com.alibaba.rocketmq.remoting.protocol.RemotingCommand Java Examples
The following examples show how to use
com.alibaba.rocketmq.remoting.protocol.RemotingCommand.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendMessageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: return this.consumerSendMsgBack(ctx, request); default: SendMessageRequestHeader requestHeader = parseRequestHeader(request); if (requestHeader == null) { return null; } // 消息轨迹:记录到达 broker 的消息 mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); // 消息轨迹:记录发送成功的消息 this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #2
Source File: ClientManageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.HEART_BEAT: return this.heartBeat(ctx, request); case RequestCode.UNREGISTER_CLIENT: return this.unregisterClient(ctx, request); case RequestCode.GET_CONSUMER_LIST_BY_GROUP: return this.getConsumerListByGroup(ctx, request); case RequestCode.UPDATE_CONSUMER_OFFSET: return this.updateConsumerOffset(ctx, request); case RequestCode.QUERY_CONSUMER_OFFSET: return this.queryConsumerOffset(ctx, request); default: break; } return null; }
Example #3
Source File: SyncInvokeTest.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Test public void test_RPC_Sync() throws Exception { RemotingServer server = NettyRPCTest.createRemotingServer(); RemotingClient client = NettyRPCTest.createRemotingClient(); for (int i = 0; i < 100; i++) { try { RemotingCommand request = RemotingCommand.createRequestCommand(0, null); RemotingCommand response = client.invokeSync("localhost:8888", request, 1000 * 3); System.out.println(i + "\t" + "invoke result = " + response); assertTrue(response != null); } catch (Exception e) { e.printStackTrace(); throw e; } } client.shutdown(); server.shutdown(); System.out.println("-----------------------------------------------------------------"); }
Example #4
Source File: ClientRemotingProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody())); ConsumeMessageDirectlyResult result = this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName()); if (null != result) { response.setCode(ResponseCode.SUCCESS); response.setBody(result.encode()); } else { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup())); } return response; }
Example #5
Source File: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_CONNECTION_LIST, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumerConnection consumerConnection = ConsumerConnection.decode(response.getBody(), ConsumerConnection.class); return consumerConnection; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #6
Source File: ClientRemotingProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.CHECK_TRANSACTION_STATE: return this.checkTransactionState(ctx, request); case RequestCode.NOTIFY_CONSUMER_IDS_CHANGED: return this.notifyConsumerIdsChanged(ctx, request); case RequestCode.RESET_CONSUMER_CLIENT_OFFSET: return this.resetOffset(ctx, request); case RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT: return this.getConsumeStatus(ctx, request); case RequestCode.GET_CONSUMER_RUNNING_INFO: return this.getConsumerRunningInfo(ctx, request); case RequestCode.CONSUME_MESSAGE_DIRECTLY: return this.consumeMessageDirectly(ctx, request); default: break; } return null; }
Example #7
Source File: DefaultRequestProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws Exception { if (log.isDebugEnabled()) { log.debug("receive request, {} {} {}",// request.getCode(), // RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // request); } switch (request.getCode()) { case RequestCode.REGISTER_MESSAGE_FILTER_CLASS: return registerMessageFilterClass(ctx, request); case RequestCode.PULL_MESSAGE: return pullMessageForward(ctx, request); } return null; }
Example #8
Source File: NettyRPCTest.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Test public void test_RPC_Oneway() throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException { RemotingServer server = createRemotingServer(); RemotingClient client = createRemotingClient(); for (int i = 0; i < 100; i++) { RemotingCommand request = RemotingCommand.createRequestCommand(0, null); request.setRemark(String.valueOf(i)); client.invokeOneway("localhost:8888", request, 1000 * 3); } client.shutdown(); server.shutdown(); System.out.println("-----------------------------------------------------------------"); }
Example #9
Source File: Broker2Client.java From rocketmq with Apache License 2.0 | 6 votes |
public void notifyConsumerIdsChanged(// final Channel channel,// final String consumerGroup// ) { if (null == consumerGroup) { log.error("notifyConsumerIdsChanged consumerGroup is null"); return; } NotifyConsumerIdsChangedRequestHeader requestHeader = new NotifyConsumerIdsChangedRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader); try { this.brokerController.getRemotingServer().invokeOneway(channel, request, 10); } catch (Exception e) { log.error("notifyConsumerIdsChanged exception, " + consumerGroup, e); } }
Example #10
Source File: SendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext = null; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: //客户端消费失败,重新打回的消息 return this.consumerSendMsgBack(ctx, request); default: //其他消息 SendMessageRequestHeader requestHeader = parseRequestHeader(request); //客户端producer发送的SEND_MESSAGE 等消息都在这里面解析 if (requestHeader == null) { return null; } mqtraceContext = buildMsgContext(ctx, requestHeader); this.executeSendMessageHookBefore(ctx, request, mqtraceContext); //消息处理 把接收的晓得写入commitlog等也是在这里面 final RemotingCommand response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); this.executeSendMessageHookAfter(response, mqtraceContext); return response; } }
Example #11
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class); return consumeStats; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #12
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_CONNECTION_LIST, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumerConnection consumerConnection = ConsumerConnection.decode(response.getBody(), ConsumerConnection.class); return consumerConnection; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #13
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public KVTable getBrokerRuntimeInfo(final String addr, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return KVTable.decode(response.getBody(), KVTable.class); } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #14
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public GroupList queryTopicConsumeByWho(final String addr, final String topic, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { QueryTopicConsumeByWhoRequestHeader requestHeader = new QueryTopicConsumeByWhoRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_TOPIC_CONSUME_BY_WHO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { GroupList groupList = GroupList.decode(response.getBody(), GroupList.class); return groupList; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #15
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public List<QueueTimeSpan> queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader(); requestHeader.setTopic(topic); requestHeader.setGroup(group); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUME_TIME_SPAN, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { QueryConsumeTimeSpanBody consumeTimeSpanBody = GroupList.decode(response.getBody(), QueryConsumeTimeSpanBody.class); return consumeTimeSpanBody.getConsumeTimeSpanSet(); } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #16
Source File: NettyRPCTest.java From rocketmq with Apache License 2.0 | 6 votes |
@Test public void test_RPC_Sync() throws InterruptedException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException { RemotingServer server = createRemotingServer(); RemotingClient client = createRemotingClient(); for (int i = 0; i < 100; i++) { TestRequestHeader requestHeader = new TestRequestHeader(); requestHeader.setCount(i); requestHeader.setMessageTitle("HelloMessageTitle"); RemotingCommand request = RemotingCommand.createRequestCommand(0, requestHeader); RemotingCommand response = client.invokeSync("localhost:8888", request, 1000 * 3000); System.out.println("invoke result = " + response); assertTrue(response != null); } client.shutdown(); server.shutdown(); System.out.println("-----------------------------------------------------------------"); }
Example #17
Source File: DefaultRequestProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(WipeWritePermOfBrokerResponseHeader.class); final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader) response.readCustomHeader(); final WipeWritePermOfBrokerRequestHeader requestHeader = (WipeWritePermOfBrokerRequestHeader) request .decodeCommandCustomHeader(WipeWritePermOfBrokerRequestHeader.class); int wipeTopicCnt = this.namesrvController.getRouteInfoManager() .wipeWritePermOfBrokerByLock(requestHeader.getBrokerName()); log.info("wipe write perm of broker[{}], client: {}, {}", // requestHeader.getBrokerName(), // RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // wipeTopicCnt); responseHeader.setWipeTopicCount(wipeTopicCnt); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #18
Source File: DefaultRequestProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(WipeWritePermOfBrokerResponseHeader.class); final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader) response.readCustomHeader(); final WipeWritePermOfBrokerRequestHeader requestHeader = (WipeWritePermOfBrokerRequestHeader) request.decodeCommandCustomHeader(WipeWritePermOfBrokerRequestHeader.class); int wipeTopicCnt = this.namesrvController.getRouteInfoManager().wipeWritePermOfBrokerByLock(requestHeader.getBrokerName()); log.info("wipe write perm of broker[{}], client: {}, {}", // requestHeader.getBrokerName(), // RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // wipeTopicCnt); responseHeader.setWipeTopicCount(wipeTopicCnt); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #19
Source File: DefaultRequestProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
public RemotingCommand getKVConfigByValue(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class); final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader(); final GetKVConfigRequestHeader requestHeader = (GetKVConfigRequestHeader) request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class); String value = this.namesrvController.getKvConfigManager().getKVConfigByValue(// requestHeader.getNamespace(), // requestHeader.getKey()// ); if (value != null) { responseHeader.setValue(value); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.QUERY_NOT_FOUND); response.setRemark( "No config item, Namespace: " + requestHeader.getNamespace() + " Key: " + requestHeader.getKey()); return response; }
Example #20
Source File: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
public void unlockBatchMQ(// final String addr, // final UnlockBatchRequestBody requestBody, // final long timeoutMillis, // final boolean oneway// ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null); request.setBody(requestBody.encode()); if (oneway) { this.remotingClient.invokeOneway(addr, request, timeoutMillis); } else { RemotingCommand response = this.remotingClient .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); } }
Example #21
Source File: DefaultRequestProcessor.java From rocketmq with Apache License 2.0 | 6 votes |
public RemotingCommand getKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class); final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader(); final GetKVConfigRequestHeader requestHeader = (GetKVConfigRequestHeader) request.decodeCommandCustomHeader(GetKVConfigRequestHeader.class); String value = this.namesrvController.getKvConfigManager().getKVConfig(// requestHeader.getNamespace(),// requestHeader.getKey()// ); if (value != null) { responseHeader.setValue(value); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; } response.setCode(ResponseCode.QUERY_NOT_FOUND); response.setRemark("No config item, Namespace: " + requestHeader.getNamespace() + " Key: " + requestHeader.getKey()); return response; }
Example #22
Source File: AbstractSendMessageProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
protected RemotingCommand msgContentCheck(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, RemotingCommand request, final RemotingCommand response) { if (requestHeader.getTopic().length() > Byte.MAX_VALUE) { log.warn("putMessage message topic length too long " + requestHeader.getTopic().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (requestHeader.getProperties() != null && requestHeader.getProperties().length() > Short.MAX_VALUE) { log.warn("putMessage message properties length too long " + requestHeader.getProperties().length()); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } if (request.getBody().length > DBMsgConstants.maxBodySize) { log.warn(" topic {} msg body size {} from {}", requestHeader.getTopic(), request.getBody().length, ChannelUtil.getRemoteIp(ctx.channel())); response.setRemark("msg body must be less 64KB"); response.setCode(ResponseCode.MESSAGE_ILLEGAL); return response; } return response; }
Example #23
Source File: NettyRPCTest.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Test public void test_RPC_Sync() throws InterruptedException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException { RemotingServer server = createRemotingServer(); RemotingClient client = createRemotingClient(); for (int i = 0; i < 100; i++) { TestRequestHeader requestHeader = new TestRequestHeader(); requestHeader.setCount(i); requestHeader.setMessageTitle("HelloMessageTitle"); RemotingCommand request = RemotingCommand.createRequestCommand(0, requestHeader); RemotingCommand response = client.invokeSync("localhost:8888", request, 1000 * 3000); System.out.println("invoke result = " + response); assertTrue(response != null); } client.shutdown(); server.shutdown(); System.out.println("-----------------------------------------------------------------"); }
Example #24
Source File: Broker2Client.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public void notifyConsumerIdsChanged(// final Channel channel,// final String consumerGroup// ) { if (null == consumerGroup) { log.error("notifyConsumerIdsChanged consumerGroup is null"); return; } NotifyConsumerIdsChangedRequestHeader requestHeader = new NotifyConsumerIdsChangedRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader); try { this.brokerController.getRemotingServer().invokeOneway(channel, request, 10); } catch (Exception e) { log.error("notifyConsumerIdsChanged exception, " + consumerGroup, e); } }
Example #25
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
/** * 更新Consumer Offset(单向) * * @param addr * @param requestHeader * @param timeoutMillis * @throws RemotingConnectException * @throws RemotingTooMuchRequestException * @throws RemotingTimeoutException * @throws RemotingSendRequestException * @throws InterruptedException */ public void updateConsumerOffsetOneway(final String addr, final UpdateConsumerOffsetRequestHeader requestHeader, final long timeoutMillis) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException, InterruptedException { if (!UtilAll.isBlank(projectGroupPrefix)) { requestHeader.setConsumerGroup( VirtualEnvUtil.buildWithProjectGroup(requestHeader.getConsumerGroup(), projectGroupPrefix)); requestHeader .setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(), projectGroupPrefix)); } RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader); this.remotingClient.invokeOneway(addr, request, timeoutMillis); }
Example #26
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
/** * 向Filter Server注册Class * * @param addr * @param consumerGroup * @param topic * @param className * @param classCRC * @param classBody * @param timeoutMillis * @throws RemotingConnectException * @throws RemotingSendRequestException * @throws RemotingTimeoutException * @throws InterruptedException * @throws MQBrokerException */ public void registerMessageFilterClass(final String addr, final String consumerGroup, final String topic, final String className, final int classCRC, final byte[] classBody, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RegisterMessageFilterClassRequestHeader requestHeader = new RegisterMessageFilterClassRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); requestHeader.setClassName(className); requestHeader.setTopic(topic); requestHeader.setClassCRC(classCRC); RemotingCommand request = RemotingCommand .createRequestCommand(RequestCode.REGISTER_MESSAGE_FILTER_CLASS, requestHeader); request.setBody(classBody); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { return; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #27
Source File: ClientManageProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.HEART_BEAT: return this.heartBeat(ctx, request); case RequestCode.UNREGISTER_CLIENT: return this.unregisterClient(ctx, request); case RequestCode.GET_CONSUMER_LIST_BY_GROUP: return this.getConsumerListByGroup(ctx, request); // 更新Consumer Offset case RequestCode.UPDATE_CONSUMER_OFFSET: return this.updateConsumerOffset(ctx, request); case RequestCode.QUERY_CONSUMER_OFFSET: return this.queryConsumerOffset(ctx, request); default: break; } return null; }
Example #28
Source File: NettyRemotingClient.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public void invokeOneway(String addr, RemotingCommand request, long timeoutMillis) throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException { final Channel channel = this.getAndCreateChannel(addr); if (channel != null && channel.isActive()) { try { if (this.rpcHook != null) { this.rpcHook.doBeforeRequest(addr, request); } this.invokeOnewayImpl(channel, request, timeoutMillis); } catch (RemotingSendRequestException e) { log.warn("invokeOneway: send request exception, so close the channel[{}]", addr); this.closeChannel(addr, channel); throw e; } } else { this.closeChannel(addr, channel); throw new RemotingConnectException(addr); } }
Example #29
Source File: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
public Set<MessageQueue> lockBatchMQ(// final String addr, // final LockBatchRequestBody requestBody, // final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null); request.setBody(requestBody.encode()); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { LockBatchResponseBody responseBody = LockBatchResponseBody.decode(response.getBody(), LockBatchResponseBody.class); Set<MessageQueue> messageQueues = responseBody.getLockOKMQSet(); return messageQueues; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #30
Source File: Broker2Client.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
/** * Broker主动通知Consumer,Id列表发生变化,Oneway */ public void notifyConsumerIdsChanged(// final Channel channel, // final String consumerGroup// ) { if (null == consumerGroup) { log.error("notifyConsumerIdsChanged consumerGroup is null"); return; } NotifyConsumerIdsChangedRequestHeader requestHeader = new NotifyConsumerIdsChangedRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, requestHeader); try { this.brokerController.getRemotingServer().invokeOneway(channel, request, 10); } catch (Exception e) { log.error("notifyConsumerIdsChanged exception, " + consumerGroup, e); } }