Ejemplo n.º 1
0
  private RemotingCommand registerMessageFilterClass(
      ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final RegisterMessageFilterClassRequestHeader requestHeader =
        (RegisterMessageFilterClassRequestHeader)
            request.decodeCommandCustomHeader(RegisterMessageFilterClassRequestHeader.class);

    try {
      boolean ok =
          this.filtersrvController
              .getFilterClassManager()
              .registerFilterClass(
                  requestHeader.getConsumerGroup(), //
                  requestHeader.getTopic(), //
                  requestHeader.getClassName(), //
                  requestHeader.getClassCRC(), //
                  request.getBody()); // Body传输的是Java Source,必须UTF-8编码
      if (!ok) {
        throw new Exception("registerFilterClass error");
      }
    } catch (Exception e) {
      response.setCode(ResponseCode.SYSTEM_ERROR);
      response.setRemark(RemotingHelper.exceptionSimpleDesc(e));
      return response;
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
  }
Ejemplo n.º 2
0
  private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request)
      throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    UnlockBatchRequestBody requestBody =
        UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class);

    this.brokerController
        .getRebalanceLockManager()
        .unlockBatch( //
            requestBody.getConsumerGroup(), //
            requestBody.getMqSet(), //
            requestBody.getClientId());

    response.setCode(ResponseCode.SUCCESS_VALUE);
    response.setRemark(null);
    return response;
  }
Ejemplo n.º 3
0
  private RemotingCommand updateAndCreateSubscriptionGroup(
      ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

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

    SubscriptionGroupConfig config =
        RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class);
    if (config != null) {
      this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config);
    }

    response.setCode(ResponseCode.SUCCESS_VALUE);
    response.setRemark(null);
    return response;
  }
Ejemplo n.º 4
0
  public TopicConfigSerializeWrapper getAllTopicConfig(final String addr)
      throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
          InterruptedException, MQBrokerException {
    RemotingCommand request =
        RemotingCommand.createRequestCommand(MQRequestCode.GET_ALL_TOPIC_CONFIG_VALUE, null);

    RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
    assert response != null;
    switch (response.getCode()) {
      case ResponseCode.SUCCESS_VALUE:
        {
          return TopicConfigSerializeWrapper.decode(
              response.getBody(), TopicConfigSerializeWrapper.class);
        }
      default:
        break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
  }
Ejemplo n.º 5
0
  private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request)
      throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    LockBatchRequestBody requestBody =
        LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class);

    Set<MessageQueue> lockOKMQSet =
        this.brokerController
            .getRebalanceLockManager()
            .tryLockBatch( //
                requestBody.getConsumerGroup(), //
                requestBody.getMqSet(), //
                requestBody.getClientId());

    LockBatchResponseBody responseBody = new LockBatchResponseBody();
    responseBody.setLockOKMQSet(lockOKMQSet);

    response.setBody(responseBody.encode());
    response.setCode(ResponseCode.SUCCESS_VALUE);
    response.setRemark(null);
    return response;
  }
Ejemplo n.º 6
0
  private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

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

    byte[] body = request.getBody();
    if (body != null) {
      try {
        String bodyStr = new String(body, MixAll.DEFAULT_CHARSET);
        Properties properties = MixAll.string2Properties(bodyStr);
        if (properties != null) {
          log.info(
              "updateBrokerConfig, new config: "
                  + properties
                  + " client: "
                  + ctx.channel().remoteAddress());
          this.brokerController.updateAllConfig(properties);
        } else {
          log.error("string2Properties error");
          response.setCode(ResponseCode.SYSTEM_ERROR_VALUE);
          response.setRemark("string2Properties error");
          return response;
        }
      } catch (UnsupportedEncodingException e) {
        log.error("", e);
        response.setCode(ResponseCode.SYSTEM_ERROR_VALUE);
        response.setRemark("UnsupportedEncodingException " + e);
        return response;
      }
    }

    response.setCode(ResponseCode.SUCCESS_VALUE);
    response.setRemark(null);
    return response;
  }
Ejemplo n.º 7
0
  public RemotingCommand heartBeat(ChannelHandlerContext ctx, RemotingCommand request) {
    RemotingCommand response = RemotingCommand.createResponseCommand(null);

    HeartbeatData heartbeatData = HeartbeatData.decode(request.getBody(), HeartbeatData.class);

    ClientChannelInfo clientChannelInfo =
        new ClientChannelInfo( //
            ctx.channel(), //
            heartbeatData.getClientID(), //
            request.getLanguage(), //
            request.getVersion() //
            );

    // 注册Consumer
    for (ConsumerData data : heartbeatData.getConsumerDataSet()) {
      SubscriptionGroupConfig subscriptionGroupConfig =
          this.brokerController
              .getSubscriptionGroupManager()
              .findSubscriptionGroupConfig(data.getGroupName());
      if (null != subscriptionGroupConfig) {
        String newTopic = MixAll.getRetryTopic(data.getGroupName());
        this.brokerController
            .getTopicConfigManager()
            .createTopicInSendMessageBackMethod( //
                newTopic, //
                subscriptionGroupConfig.getRetryQueueNums(), //
                PermName.PERM_WRITE | PermName.PERM_READ);
      }

      boolean changed =
          this.brokerController
              .getConsumerManager()
              .registerConsumer( //
                  data.getGroupName(), //
                  clientChannelInfo, //
                  data.getConsumeType(), //
                  data.getMessageModel(), //
                  data.getConsumeFromWhere(), //
                  data.getSubscriptionDataSet() //
                  );

      if (changed) {
        log.info(
            "registerConsumer info changed {} {}", //
            data.toString(), //
            RemotingHelper.parseChannelRemoteAddr(ctx.channel()) //
            );
      }
    }

    // 注册Producer
    for (ProducerData data : heartbeatData.getProducerDataSet()) {
      this.brokerController
          .getProducerManager()
          .registerProducer(data.getGroupName(), clientChannelInfo);
    }

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