Search in sources :

Example 61 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientInstanceTest method testTopicRouteData2TopicPublishInfo.

@Test
public void testTopicRouteData2TopicPublishInfo() {
    TopicRouteData topicRouteData = new TopicRouteData();
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);
    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
    assertThat(topicPublishInfo.isHaveTopicRouterInfo()).isFalse();
    assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4);
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) TopicPublishInfo(org.apache.rocketmq.client.impl.producer.TopicPublishInfo) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 62 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

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)

Example 63 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClusterTestRequestProcessorTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException, RemotingException, MQClientException, InterruptedException {
    NamesrvController namesrvController = new NamesrvController(new NamesrvConfig(), new NettyServerConfig());
    clusterTestProcessor = new ClusterTestRequestProcessor(namesrvController, "default-producer");
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    ctx = mock(ChannelHandlerContext.class);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = ClusterTestRequestProcessor.class.getDeclaredField("adminExt");
    field.setAccessible(true);
    field.set(clusterTestProcessor, defaultMQAdminExt);
    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NamesrvController(org.apache.rocketmq.namesrv.NamesrvController) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) Field(java.lang.reflect.Field) NamesrvConfig(org.apache.rocketmq.common.namesrv.NamesrvConfig) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) Before(org.junit.Before)

Example 64 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQPushConsumerImpl method queryConsumeTimeSpan.

public List<QueueTimeSpan> queryConsumeTimeSpan(final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    List<QueueTimeSpan> queueTimeSpan = new ArrayList<QueueTimeSpan>();
    TopicRouteData routeData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, 3000);
    for (BrokerData brokerData : routeData.getBrokerDatas()) {
        String addr = brokerData.selectBrokerAddr();
        queueTimeSpan.addAll(this.mQClientFactory.getMQClientAPIImpl().queryConsumeTimeSpan(addr, topic, groupName(), 3000));
    }
    return queueTimeSpan;
}
Also used : QueueTimeSpan(org.apache.rocketmq.common.protocol.body.QueueTimeSpan) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ArrayList(java.util.ArrayList) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 65 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method getTopicClusterList.

@Override
public Set<String> getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException {
    Set<String> clusterSet = new HashSet<String>();
    ClusterInfo clusterInfo = examineBrokerClusterInfo();
    TopicRouteData topicRouteData = examineTopicRouteInfo(topic);
    BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
    String brokerName = brokerData.getBrokerName();
    Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Set<String>> next = it.next();
        if (next.getValue().contains(brokerName)) {
            clusterSet.add(next.getKey());
        }
    }
    return clusterSet;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) Entry(java.util.Map.Entry) Set(java.util.Set) HashSet(java.util.HashSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Aggregations

TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)92 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)65 ArrayList (java.util.ArrayList)25 MQClientException (org.apache.rocketmq.client.exception.MQClientException)25 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)25 HashMap (java.util.HashMap)22 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)20 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 List (java.util.List)16 HashSet (java.util.HashSet)13 Entry (java.util.Map.Entry)12 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)12 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)11 Field (java.lang.reflect.Field)10 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExtImpl (org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl)10