org.apache.rocketmq.remoting.protocol.RemotingCommand Java Examples

The following examples show how to use org.apache.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: Broker2Client.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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. group={}, error={}", consumerGroup, e.toString());
    }
}
 
Example #2
Source File: DeFiPullMessageProcessor.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
private void handleProcessResult(final PullMessageRequestHeader requestHeader, final RemotingCommand response) {
    if (response != null) {
        switch (response.getCode()) {
            case SUBSCRIPTION_GROUP_NOT_EXIST:
            case NO_PERMISSION:
            case SUBSCRIPTION_NOT_EXIST:
            case SUBSCRIPTION_NOT_LATEST:
                response.setCode(PULL_NOT_FOUND);
                final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.readCustomHeader();
                responseHeader.setMinOffset(this.deFiBrokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()));
                responseHeader.setMaxOffset(this.deFiBrokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()));
                responseHeader.setNextBeginOffset(requestHeader.getQueueOffset());
                responseHeader.setSuggestWhichBrokerId(MixAll.MASTER_ID);
                break;
        }
    }
}
 
Example #3
Source File: DefaultRequestProcessorTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_GetKVConfigReturnNotNull() throws RemotingCommandException {
    namesrvController.getKvConfigManager().putKVConfig("namespace", "key", "value");

    GetKVConfigRequestHeader header = new GetKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KV_CONFIG,
        header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");

    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response
        .readCustomHeader();

    assertThat(responseHeader.getValue()).isEqualTo("value");
}
 
Example #4
Source File: MQClientAPIImplTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatePlainAccessConfig_Exception() throws InterruptedException, RemotingException, MQBrokerException {

    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createErrorResponse4UpdateAclConfig(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    PlainAccessConfig config = createUpdateAclConfig();
    try {
        mqClientAPI.createPlainAccessConfig(brokerAddr, config, 3 * 1000);
    } catch (MQClientException ex) {
        assertThat(ex.getResponseCode()).isEqualTo(209);
        assertThat(ex.getErrorMessage()).isEqualTo("corresponding to accessConfig has been updated failed");
    }
}
 
Example #5
Source File: ClientRemotingProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: AbstractSendMessageProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
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.MAX_BODY_SIZE) {
        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 #7
Source File: AbstractSendMessageProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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.MAX_BODY_SIZE) {
        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 #8
Source File: NettyRemotingClient.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: ConsumerManageProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request)
    throws RemotingCommandException {
    switch (request.getCode()) {
        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 #10
Source File: DefaultRequestProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
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 #11
Source File: SendMessageProcessor.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Override
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    SendMessageContext mqtraceContext;
    switch (request.getCode()) {
        case RequestCode.CONSUMER_SEND_MSG_BACK:
            return this.consumerSendMsgBack(ctx, request);
        default:
            SendMessageRequestHeader requestHeader = parseRequestHeader(request);
            if (requestHeader == null) {
                return null;
            }

            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 #12
Source File: DefaultRequestProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand getKVListByNamespace(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetKVListByNamespaceRequestHeader requestHeader =
        (GetKVListByNamespaceRequestHeader) request.decodeCommandCustomHeader(GetKVListByNamespaceRequestHeader.class);

    byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(
        requestHeader.getNamespace());
    if (null != jsonValue) {
        response.setBody(jsonValue);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }

    response.setCode(ResponseCode.QUERY_NOT_FOUND);
    response.setRemark("No config item, Namespace: " + requestHeader.getNamespace());
    return response;
}
 
Example #13
Source File: MQClientAPIImplTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #14
Source File: DefaultRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_GetKVConfigReturnNull() throws RemotingCommandException {
    GetKVConfigRequestHeader header = new GetKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_KV_CONFIG,
        header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");

    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.QUERY_NOT_FOUND);
    assertThat(response.getRemark()).isEqualTo("No config item, Namespace: namespace Key: key");

    GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response
        .readCustomHeader();

    assertThat(responseHeader.getValue()).isNull();
}
 
Example #15
Source File: MQClientAPIImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private synchronized RemotingCommand deleteTopic(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    DeleteTopicRequestHeader requestHeader =
        (DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class);

    log.info("deleteTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

    String topic = requestHeader.getTopic();
    if (!TopicValidator.validateTopic(topic, response)) {
        return response;
    }
    if (TopicValidator.isSystemTopic(topic, response)) {
        return response;
    }

    this.brokerController.getTopicConfigManager().deleteTopicConfig(topic);
    this.brokerController.getMessageStore()
        .cleanUnusedTopic(this.brokerController.getTopicConfigManager().getTopicConfigTable().keySet());
    if (this.brokerController.getBrokerConfig().isAutoDeleteUnusedStats()) {
        this.brokerController.getBrokerStatsManager().onTopicDeleted(requestHeader.getTopic());
    }
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #17
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
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(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), 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 #18
Source File: DefaultRequestProcessorTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_DeleteKVConfig() throws RemotingCommandException {
    namesrvController.getKvConfigManager().putKVConfig("namespace", "key", "value");

    DeleteKVConfigRequestHeader header = new DeleteKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.DELETE_KV_CONFIG,
        header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");

    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    assertThat(namesrvController.getKvConfigManager().getKVConfig("namespace", "key"))
        .isNull();
}
 
Example #19
Source File: DefaultRequestProcessor.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private RemotingCommand getConfig(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    String content = this.namesrvController.getConfiguration().getAllConfigsFormatString();
    if (content != null && content.length() > 0) {
        try {
            response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            log.error("getConfig error, ", e);
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("UnsupportedEncodingException " + e);
            return response;
        }
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #20
Source File: RemotingServerTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeAsync() throws InterruptedException, RemotingConnectException,
    RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException {

    final CountDownLatch latch = new CountDownLatch(1);
    RemotingCommand request = RemotingCommand.createRequestCommand(0, null);
    request.setRemark("messi");
    remotingClient.invokeAsync("localhost:8888", request, 1000 * 3, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            latch.countDown();
            assertTrue(responseFuture != null);
            assertThat(responseFuture.getResponseCommand().getLanguage()).isEqualTo(LanguageCode.JAVA);
            assertThat(responseFuture.getResponseCommand().getExtFields()).hasSize(2);
        }
    });
    latch.await();
}
 
Example #21
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: DefaultRequestProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public RemotingCommand putKVConfig(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final PutKVConfigRequestHeader requestHeader =
        (PutKVConfigRequestHeader) request.decodeCommandCustomHeader(PutKVConfigRequestHeader.class);

    this.namesrvController.getKvConfigManager().putKVConfig(
        requestHeader.getNamespace(),
        requestHeader.getKey(),
        requestHeader.getValue()
    );

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #23
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_PutKVConfig() throws RemotingCommandException {
    PutKVConfigRequestHeader header = new PutKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PUT_KV_CONFIG,
        header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");
    request.addExtField("value", "value");

    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    assertThat(namesrvController.getKvConfigManager().getKVConfig("namespace", "key"))
        .isEqualTo("value");
}
 
Example #24
Source File: AdminBrokerProcessor.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 获取最大的偏移量
 * @param ctx ctx
 * @param request request
 * @return ;
 * @throws RemotingCommandException ;
 */
private RemotingCommand getMaxOffset(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {

    final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class);
    final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader();
    final GetMaxOffsetRequestHeader requestHeader =
        (GetMaxOffsetRequestHeader) request.decodeCommandCustomHeader(GetMaxOffsetRequestHeader.class);

    long offset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId());

    responseHeader.setOffset(offset);

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #25
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public boolean cleanUnusedTopicByAddr(final String addr,
    long timeoutMillis) throws MQClientException, RemotingConnectException,
    RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_UNUSED_TOPIC, null);

    String acturallyAddr = getActurallyBrokerAddr(addr);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), acturallyAddr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return true;
        }
        default:
            break;
    }

    throw new MQClientException(response.getCode(), response.getRemark());
}
 
Example #26
Source File: ClientRemotingProcessor.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final CheckTransactionStateRequestHeader requestHeader =
        (CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class);
    final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());
    final MessageExt messageExt = MessageDecoder.decode(byteBuffer);
    if (messageExt != null) {
        final String group = messageExt.getProperty(MessageConst.PROPERTY_PRODUCER_GROUP);
        if (group != null) {
            MQProducerInner producer = this.mqClientFactory.selectProducer(group);
            if (producer != null) {
                final String addr = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
                producer.checkTransactionState(addr, messageExt, requestHeader);
            } else {
                log.debug("checkTransactionState, pick producer by group[{}] failed", group);
            }
        } else {
            log.warn("checkTransactionState, pick producer group failed");
        }
    } else {
        log.warn("checkTransactionState, decode message failed");
    }

    return null;
}
 
Example #27
Source File: DefaultRequestProcessorTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_PutKVConfig() throws RemotingCommandException {
    PutKVConfigRequestHeader header = new PutKVConfigRequestHeader();
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PUT_KV_CONFIG,
        header);
    request.addExtField("namespace", "namespace");
    request.addExtField("key", "key");
    request.addExtField("value", "value");

    RemotingCommand response = defaultRequestProcessor.processRequest(null, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    assertThat(namesrvController.getKvConfigManager().getKVConfig("namespace", "key"))
        .isEqualTo("value");
}
 
Example #28
Source File: BrokerStartup.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static BrokerController start(BrokerController controller) {
    try {

        controller.start();

        String tip = "The broker[" + controller.getBrokerConfig().getBrokerName() + ", "
            + controller.getBrokerAddr() + "] boot success. serializeType=" + RemotingCommand.getSerializeTypeConfigInThisServer();

        if (null != controller.getBrokerConfig().getNamesrvAddr()) {
            tip += " and name server is " + controller.getBrokerConfig().getNamesrvAddr();
        }

        log.info(tip);
        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }

    return null;
}
 
Example #29
Source File: MQProtosHelper.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static boolean registerBrokerToNameServer(final String nsaddr, final String brokerAddr,
    final long timeoutMillis) {
    RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader();
    requestHeader.setBrokerAddr(brokerAddr);

    RemotingCommand request =
        RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader);

    try {
        RemotingCommand response = RemotingHelper.invokeSync(nsaddr, request, timeoutMillis);
        if (response != null) {
            return ResponseCode.SUCCESS == response.getCode();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
Example #30
Source File: AdminBrokerProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
private RemotingCommand getAllDelayOffset(ChannelHandlerContext ctx, RemotingCommand request) {
        final RemotingCommand response = RemotingCommand.createResponseCommand(null);

//        消息编码=》
        String content = ((DefaultMessageStore) this.brokerController.getMessageStore()).getScheduleMessageService().encode();
        if (content != null && content.length() > 0) {
            try {
                response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
            } catch (UnsupportedEncodingException e) {
                log.error("get all delay offset from master error.", e);

                response.setCode(ResponseCode.SYSTEM_ERROR);
                response.setRemark("UnsupportedEncodingException " + e);
                return response;
            }
        } else {
            log.error("No delay offset in this broker, client: {} ", ctx.channel().remoteAddress());
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("No delay offset in this broker");
            return response;
        }

        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);

        return response;
    }