Search in sources :

Example 1 with GetRouteInfoRequestHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClusterTestRequestProcessor method getRouteInfoByTopic.

@Override
public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class);
    TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic());
    if (topicRouteData != null) {
        String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic());
        topicRouteData.setOrderTopicConf(orderTopicConf);
    } else {
        try {
            topicRouteData = adminExt.examineTopicRouteInfo(requestHeader.getTopic());
        } catch (Exception e) {
            log.info("get route info by topic from product environment failed. envName={},", productEnvName);
        }
    }
    if (topicRouteData != null) {
        byte[] content = topicRouteData.encode();
        response.setBody(content);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.TOPIC_NOT_EXIST);
    response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 2 with GetRouteInfoRequestHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getDefaultTopicRouteInfoFromNameServer.

public TopicRouteData getDefaultTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader();
    requestHeader.setTopic(topic);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ROUTEINTO_BY_TOPIC, requestHeader);
    // 同步调用namesrv获取topic route info
    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.TOPIC_NOT_EXIST:
            {
                // TODO LOG
                break;
            }
        case ResponseCode.SUCCESS:
            {
                byte[] body = response.getBody();
                if (body != null) {
                    return TopicRouteData.decode(body, TopicRouteData.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 3 with GetRouteInfoRequestHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getTopicRouteInfoFromNameServer.

public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader();
    requestHeader.setTopic(topic);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ROUTEINTO_BY_TOPIC, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.TOPIC_NOT_EXIST:
            {
                if (!topic.equals(MixAll.DEFAULT_TOPIC))
                    log.warn("get Topic [{}] RouteInfoFromNameServer is not exist value", topic);
                break;
            }
        case ResponseCode.SUCCESS:
            {
                byte[] body = response.getBody();
                if (body != null) {
                    return TopicRouteData.decode(body, TopicRouteData.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 4 with GetRouteInfoRequestHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader in project rocketmq by apache.

the class ClusterTestRequestProcessor method getRouteInfoByTopic.

@Override
public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class);
    TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic());
    if (topicRouteData != null) {
        String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic());
        topicRouteData.setOrderTopicConf(orderTopicConf);
    } else {
        try {
            topicRouteData = adminExt.examineTopicRouteInfo(requestHeader.getTopic());
        } catch (Exception e) {
            log.info("get route info by topic from product environment failed. envName={},", productEnvName);
        }
    }
    if (topicRouteData != null) {
        byte[] content = topicRouteData.encode();
        response.setBody(content);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.TOPIC_NOT_EXIST);
    response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 5 with GetRouteInfoRequestHeader

use of org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader in project rocketmq by apache.

the class DefaultRequestProcessor method getRouteInfoByTopic.

public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class);
    TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic());
    if (topicRouteData != null) {
        if (this.namesrvController.getNamesrvConfig().isOrderMessageEnable()) {
            String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic());
            topicRouteData.setOrderTopicConf(orderTopicConf);
        }
        byte[] content = topicRouteData.encode();
        response.setBody(content);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.TOPIC_NOT_EXIST);
    response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Aggregations

GetRouteInfoRequestHeader (org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader)7 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)7 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)7 MQClientException (org.apache.rocketmq.client.exception.MQClientException)5 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2