Java Code Examples for org.apache.rocketmq.client.impl.producer.TopicPublishInfo#ok()

The following examples show how to use org.apache.rocketmq.client.impl.producer.TopicPublishInfo#ok() . 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: BatchMQProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector)
    throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic());
    if (topicInfo == null || !topicInfo.ok()) { //new topic
        sendSingleMessage(request);
        return;
    }

    MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request);
    request.setMessageQueue(mq);

    requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> {
        Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>();
        addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker());
        return q;
    }).add(request);
}
 
Example 2
Source File: RmqSender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static TopicPublishInfo tryToFindTopicPublishInfo(DefaultMQProducer producer, final String topic) {
    TopicPublishInfo topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);

    if (null == topicPublishInfo || !topicPublishInfo.ok()) {
        producer.getDefaultMQProducerImpl().getmQClientFactory().updateTopicRouteInfoFromNameServer(topic);
        topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);
    }

    if (topicPublishInfo != null && (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok())) {
        return topicPublishInfo;
    } else {
        producer.getDefaultMQProducerImpl().getmQClientFactory()
                .updateTopicRouteInfoFromNameServer(topic, true, producer);
        topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);
        return topicPublishInfo;
    }
}
 
Example 3
Source File: MQAdminImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 根据topic获取Publish的消息的队列详情
 * @param topic topic
 * @return ;
 * @throws MQClientException ;
 */
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 4
Source File: BatchMQProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void send(CarreraRequest request, MessageQueueSelector messageQueueSelector)
    throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicPublishInfo topicInfo = clusterProducer.getRocketMQProducerByIndex(0).getDefaultMQProducerImpl().getTopicPublishInfoTable().get(request.getTopic());
    if (topicInfo == null || !topicInfo.ok()) { //new topic
        sendSingleMessage(request);
        return;
    }

    MessageQueue mq = messageQueueSelector.select(topicInfo.getMessageQueueList(), null, request);
    request.setMessageQueue(mq);

    requestQMap.computeIfAbsent(mq.getBrokerName(), _name -> {
        Deque<CarreraRequest> q = new ConcurrentLinkedDeque<>();
        addRequestQueue(q, _name, config.getMaxEncodeWorkerForEachBroker());
        return q;
    }).add(request);
}
 
Example 5
Source File: RmqSender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static TopicPublishInfo tryToFindTopicPublishInfo(DefaultMQProducer producer, final String topic) {
    TopicPublishInfo topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);

    if (null == topicPublishInfo || !topicPublishInfo.ok()) {
        producer.getDefaultMQProducerImpl().getmQClientFactory().updateTopicRouteInfoFromNameServer(topic);
        topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);
    }

    if (topicPublishInfo != null && (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok())) {
        return topicPublishInfo;
    } else {
        producer.getDefaultMQProducerImpl().getmQClientFactory()
                .updateTopicRouteInfoFromNameServer(topic, true, producer);
        topicPublishInfo = producer.getDefaultMQProducerImpl().getTopicPublishInfoTable().get(topic);
        return topicPublishInfo;
    }
}
 
Example 6
Source File: MQAdminImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 7
Source File: MQAdminImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 8
Source File: MQAdminImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 9
Source File: MQAdminImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 10
Source File: MQAdminImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 11
Source File: MQAdminImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return topicPublishInfo.getMessageQueueList();
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 12
Source File: AsyncTraceDispatcher.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private Set<String> tryGetMessageQueueBrokerSet(DefaultMQProducerImpl producer, String topic) {
    Set<String> brokerSet = new HashSet<String>();
    TopicPublishInfo topicPublishInfo = producer.getTopicPublishInfoTable().get(topic);
    if (null == topicPublishInfo || !topicPublishInfo.ok()) {
        producer.getTopicPublishInfoTable().putIfAbsent(topic, new TopicPublishInfo());
        producer.getmQClientFactory().updateTopicRouteInfoFromNameServer(topic);
        topicPublishInfo = producer.getTopicPublishInfoTable().get(topic);
    }
    if (topicPublishInfo.isHaveTopicRouterInfo() || topicPublishInfo.ok()) {
        for (MessageQueue queue : topicPublishInfo.getMessageQueueList()) {
            brokerSet.add(queue.getBrokerName());
        }
    }
    return brokerSet;
}
 
Example 13
Source File: MQAdminImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public List<MessageQueue> fetchPublishMessageQueues(String topic) throws MQClientException {
    try {
        TopicRouteData topicRouteData = this.mQClientFactory.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis);
        if (topicRouteData != null) {
            TopicPublishInfo topicPublishInfo = MQClientInstance.topicRouteData2TopicPublishInfo(topic, topicRouteData);
            if (topicPublishInfo != null && topicPublishInfo.ok()) {
                return parsePublishMessageQueues(topicPublishInfo.getMessageQueueList());
            }
        }
    } catch (Exception e) {
        throw new MQClientException("Can not find Message Queue for this topic, " + topic, e);
    }

    throw new MQClientException("Unknow why, Can not find Message Queue for this topic, " + topic, null);
}
 
Example 14
Source File: CarreraRequestForRMQBatch.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
private boolean classifyMessage() {
    Map<String, MessageQueue> defaultMsgQueue = new HashMap<>();

    for (Message message : messageList) {
        if (brokerCluster == null) {
            onFinish(ProxySendResult.FAIL_TOPIC_NOT_ALLOWED);
            return false;
        }

        CarreraMessage carreraMessage = new CarreraMessage(message);
        if (message.getPartitionId() < -1 && defaultMsgQueue.containsKey(message.getTopic())) {
            carreraMessage.setMessageQueue(defaultMsgQueue.get(message.getTopic()));
        } else {
            RmqClusterProducer producer = (RmqClusterProducer) producerPool.getProducer(brokerCluster);
            if (producer == null) {
                onFinish(ProxySendResult.FAIL_NO_PRODUCER_FOR_CLUSTER);
                return false;
            }

            TopicPublishInfo topicInfo = RmqSender.tryToFindTopicPublishInfo(producer.pickRocketMQProducer(), message.topic);
            if (topicInfo == null || !topicInfo.ok()) {
                LOGGER.error("get topic info failed, topic={}", message.topic);
                onFinish(ProxySendResult.FAIL_UNKNOWN);
                return false;
            }

            if (CollectionUtils.isEmpty(topicInfo.getMessageQueueList())) {
                LOGGER.error("message queue list is null or empty");
                onFinish(ProxySendResult.FAIL_UNKNOWN);
                return false;
            }

            MessageQueue mq = RmqSender.select(carreraMessage, topicInfo);
            carreraMessage.setMessageQueue(mq);
            if (message.getPartitionId() < -1 && !defaultMsgQueue.containsKey(message.getTopic())) {
                defaultMsgQueue.put(message.getTopic(), mq);
            }
        }

        requestMap.computeIfAbsent(carreraMessage.getMessageQueue().getBrokerName(), _name -> new ArrayList<>()).add(carreraMessage);
    }

    LOGGER.info("topic:{}, firs msg key:{}, message count:{}, will send to broker:{}", getTopic(), getKey(), messageList.size(), requestMap.keySet());
    isClassified = true;
    return true;
}
 
Example 15
Source File: CarreraRequestForRMQBatch.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
private boolean classifyMessage() {
    Map<String, MessageQueue> defaultMsgQueue = new HashMap<>();

    for (Message message : messageList) {
        if (brokerCluster == null) {
            onFinish(ProxySendResult.FAIL_TOPIC_NOT_ALLOWED);
            return false;
        }

        CarreraMessage carreraMessage = new CarreraMessage(message);
        if (message.getPartitionId() < -1 && defaultMsgQueue.containsKey(message.getTopic())) {
            carreraMessage.setMessageQueue(defaultMsgQueue.get(message.getTopic()));
        } else {
            RmqClusterProducer producer = (RmqClusterProducer) producerPool.getProducer(brokerCluster);
            if (producer == null) {
                onFinish(ProxySendResult.FAIL_NO_PRODUCER_FOR_CLUSTER);
                return false;
            }

            TopicPublishInfo topicInfo = RmqSender.tryToFindTopicPublishInfo(producer.pickRocketMQProducer(), message.topic);
            if (topicInfo == null || !topicInfo.ok()) {
                LOGGER.error("get topic info failed, topic={}", message.topic);
                onFinish(ProxySendResult.FAIL_UNKNOWN);
                return false;
            }

            if (CollectionUtils.isEmpty(topicInfo.getMessageQueueList())) {
                LOGGER.error("message queue list is null or empty");
                onFinish(ProxySendResult.FAIL_UNKNOWN);
                return false;
            }

            MessageQueue mq = RmqSender.select(carreraMessage, topicInfo);
            carreraMessage.setMessageQueue(mq);
            if (message.getPartitionId() < -1 && !defaultMsgQueue.containsKey(message.getTopic())) {
                defaultMsgQueue.put(message.getTopic(), mq);
            }
        }

        requestMap.computeIfAbsent(carreraMessage.getMessageQueue().getBrokerName(), _name -> new ArrayList<>()).add(carreraMessage);
    }

    LOGGER.info("topic:{}, firs msg key:{}, message count:{}, will send to broker:{}", getTopic(), getKey(), messageList.size(), requestMap.keySet());
    isClassified = true;
    return true;
}