コード例 #1
0
SendResult_ptr DefaultMQProducerImpl::sendKernelImpl(Message_ptr msg, MessageQueue* mq, std::string& communicationMode, bool sendCallback) {
    std::string brokerAddr = this->mQClientFactory->findBrokerAddressInPublish(mq->getBrokerName());
    if (brokerAddr.empty()) {
        // TODO 此处可能对Name Server压力过大,需要调优
        this->mQClientFactory->updateTopicRouteInfoFromNameServer(mq->getTopic());
        this->mQClientFactory->updateTopicRouteInfoFromNameServer(mq->getTopic(), true, this->defaultMQProducer);
        brokerAddr = this->mQClientFactory->findBrokerAddressInPublish(mq->getBrokerName());
    }

    if (!brokerAddr.empty()) {
        std::string prevBody = msg->getBody();
        int sysFlag = 0;

        SendMessageRequestHeader_var requestHeader = new SendMessageRequestHeader();
        requestHeader->setProducerGroup(this->defaultMQProducer->getProducerGroup());
        requestHeader->setTopic(msg->getTopic());
        requestHeader->setDefaultTopic(this->defaultMQProducer->getCreateTopicKey());
        requestHeader->setDefaultTopicQueueNums(this->defaultMQProducer->getDefaultTopicQueueNums());
        requestHeader->setQueueId(mq->getQueueId());
        requestHeader->setSysFlag(sysFlag);
        requestHeader->setBornTimestamp(112233);
        requestHeader->setFlag(msg->getFlag());

        SendResult_var sendResult = new SendResult();
        this->mQClientFactory->getMQClientAPIImpl()->sendMessage(brokerAddr, mq->getBrokerName(), SendMessageRequestHeader_var::Duplicate(requestHeader), 3);
        return SendResult_var::Duplicate(sendResult);
    }
    return NULL;
}
コード例 #2
0
SendResult_ptr DefaultMQProducerImpl::sendDefaultImpl(Message_ptr msg, std::string& communicationMode, bool sendCallback) {
    long beginTimestamp = 0;
    long endTimestamp = beginTimestamp;
    TopicPublishInfo* topicPublishInfo = this->tryToFindTopicPublishInfo(msg->getTopic());
    if (topicPublishInfo->ok()) {
        MessageQueue* mq = NULL;
        SendResult_var sendResult = new SendResult();
        for (int times = 0; times < 3; times++) {
            std::string lastBrokerName;
            if(mq != NULL) {
                lastBrokerName = mq->getBrokerName();
            }
            MessageQueue* tmpmq = topicPublishInfo->selectOneMessageQueue(lastBrokerName);
            if (tmpmq != NULL) {
                mq = tmpmq;
                sendResult = this->sendKernelImpl(msg, mq, communicationMode, sendCallback);
                endTimestamp = 12;
                if(communicationMode == CommunicationMode::SYNC) {
                    if (sendResult->getSendStatus() != SendStatus::SEND_OK) {
                        /*
                        if (this->defaultMQProducer->isRetryAnotherBrokerWhenNotStoreOK()) {
                        	continue;
                        }
                        */
                    }
                    return SendResult_var::Duplicate(sendResult);
                }
            }
            else {
                break;
            }
        }
        return SendResult_var::Duplicate(sendResult);
    }
    return NULL;
}