com.alibaba.rocketmq.client.Validators Java Examples

The following examples show how to use com.alibaba.rocketmq.client.Validators. 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: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
        throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, timeout);
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #2
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
        throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, timeout);
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #3
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
        throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, null, timeout);
    } catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #4
Source File: DefaultMQPullConsumerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    // check consumerGroup
    Validators.checkGroup(this.defaultMQPullConsumer.getConsumerGroup());

    // consumerGroup
    if (null == this.defaultMQPullConsumer.getConsumerGroup()) {
        throw new MQClientException(
            "consumerGroup is null" //
                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
            null);
    }

    // consumerGroup
    if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) {
        throw new MQClientException(
            "consumerGroup can not equal "//
                    + MixAll.DEFAULT_CONSUMER_GROUP //
                    + ", please specify another one."//
                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
            null);
    }

    // messageModel
    if (null == this.defaultMQPullConsumer.getMessageModel()) {
        throw new MQClientException(
            "messageModel is null" //
                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
            null);
    }

    // allocateMessageQueueStrategy
    if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) {
        throw new MQClientException(
            "allocateMessageQueueStrategy is null" //
                    + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
            null);
    }
}
 
Example #5
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private SendResult sendSelectImpl(//
        Message msg, //
        MessageQueueSelector selector, //
        Object arg, //
        final CommunicationMode communicationMode, //
        final SendCallback sendCallback, final long timeout//
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
    if (topicPublishInfo != null && topicPublishInfo.ok()) {
        MessageQueue mq = null;
        try {
            mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
        }
        catch (Throwable e) {
            throw new MQClientException("select message queue throwed exception.", e);
        }

        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, timeout);
        }
        else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #6
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * KERNEL ONEWAY -------------------------------------------------------
 */
public void sendOneway(Message msg, MessageQueue mq)
        throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ONEWAY, null,
            this.defaultMQProducer.getSendMsgTimeout());
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #7
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public SendResult send(Message msg, MessageQueue mq, long timeout)
        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, timeout);
}
 
Example #8
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag)
        throws MQClientException {
    this.makeSureStateOK();
    Validators.checkTopic(newTopic);

    this.mQClientFactory.getMQAdminImpl().createTopic(key, newTopic, queueNum, topicSysFlag);
}
 
Example #9
Source File: DefaultMQProducerImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    Validators.checkGroup(this.defaultMQProducer.getProducerGroup());

    if (null == this.defaultMQProducer.getProducerGroup()) {
        throw new MQClientException("producerGroup is null", null);
    }

    if (this.defaultMQProducer.getProducerGroup().equals(MixAll.DEFAULT_PRODUCER_GROUP)) {
        throw new MQClientException("producerGroup can not equal " + MixAll.DEFAULT_PRODUCER_GROUP
                + ", please specify another one.",
            null);
    }
}
 
Example #10
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SendResult sendSelectImpl(//
                                  Message msg, //
                                  MessageQueueSelector selector, //
                                  Object arg, //
                                  final CommunicationMode communicationMode, //
                                  final SendCallback sendCallback, final long timeout//
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
    if (topicPublishInfo != null && topicPublishInfo.ok()) {
        MessageQueue mq = null;
        try {
            mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
        } catch (Throwable e) {
            throw new MQClientException("select message queue throwed exception.", e);
        }

        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, null, timeout);
        } else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #11
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * KERNEL ONEWAY -------------------------------------------------------
 */
public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ONEWAY, null, null, this.defaultMQProducer.getSendMsgTimeout());
    } catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #12
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    Validators.checkGroup(this.defaultMQProducer.getProducerGroup());

    if (null == this.defaultMQProducer.getProducerGroup()) {
        throw new MQClientException("producerGroup is null", null);
    }

    if (this.defaultMQProducer.getProducerGroup().equals(MixAll.DEFAULT_PRODUCER_GROUP)) {
        throw new MQClientException("producerGroup can not equal " + MixAll.DEFAULT_PRODUCER_GROUP
                + ", please specify another one.", null);
    }
}
 
Example #13
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public SendResult send(Message msg, MessageQueue mq, long timeout)
        throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}
 
Example #14
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    Validators.checkGroup(this.defaultMQProducer.getProducerGroup());

    if (null == this.defaultMQProducer.getProducerGroup()) {
        throw new MQClientException("producerGroup is null", null);
    }

    if (this.defaultMQProducer.getProducerGroup().equals(MixAll.DEFAULT_PRODUCER_GROUP)) {
        throw new MQClientException("producerGroup can not equal " + MixAll.DEFAULT_PRODUCER_GROUP + ", please specify another one.",
                null);
    }
}
 
Example #15
Source File: DefaultMQPullConsumerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    // check consumerGroup
    Validators.checkGroup(this.defaultMQPullConsumer.getConsumerGroup());

    // consumerGroup
    if (null == this.defaultMQPullConsumer.getConsumerGroup()) {
        throw new MQClientException("consumerGroup is null" //
                + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // consumerGroup
    if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) {
        throw new MQClientException("consumerGroup can not equal "//
                + MixAll.DEFAULT_CONSUMER_GROUP //
                + ", please specify another one."//
                + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // messageModel
    if (null == this.defaultMQPullConsumer.getMessageModel()) {
        throw new MQClientException("messageModel is null" //
                + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // allocateMessageQueueStrategy
    if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) {
        throw new MQClientException("allocateMessageQueueStrategy is null" //
                + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }
}
 
Example #16
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private SendResult sendSelectImpl(//
        Message msg,//
        MessageQueueSelector selector,//
        Object arg,//
        final CommunicationMode communicationMode,//
        final SendCallback sendCallback, final long timeout//
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
    if (topicPublishInfo != null && topicPublishInfo.ok()) {
        MessageQueue mq = null;
        try {
            mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
        }
        catch (Throwable e) {
            throw new MQClientException("select message queue throwed exception.", e);
        }

        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, timeout);
        }
        else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #17
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * KERNEL ONEWAY -------------------------------------------------------
 */
public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException,
        InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    try {
        this.sendKernelImpl(msg, mq, CommunicationMode.ONEWAY, null,
            this.defaultMQProducer.getSendMsgTimeout());
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
Example #18
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public SendResult send(Message msg, MessageQueue mq, long timeout) throws MQClientException,
        RemotingException, MQBrokerException, InterruptedException {
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    if (!msg.getTopic().equals(mq.getTopic())) {
        throw new MQClientException("message's topic not equal mq's topic", null);
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, timeout);
}
 
Example #19
Source File: DefaultMQProducerImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag)
        throws MQClientException {
    this.makeSureStateOK();
    Validators.checkTopic(newTopic);

    this.mQClientFactory.getMQAdminImpl().createTopic(key, newTopic, queueNum, topicSysFlag);
}
 
Example #20
Source File: DefaultMQPullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private void checkConfig() throws MQClientException {
    // check consumerGroup
    Validators.checkGroup(this.defaultMQPullConsumer.getConsumerGroup());

    // consumerGroup
    if (null == this.defaultMQPullConsumer.getConsumerGroup()) {
        throw new MQClientException(
                "consumerGroup is null" //
                        + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // consumerGroup
    if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) {
        throw new MQClientException(
                "consumerGroup can not equal "//
                        + MixAll.DEFAULT_CONSUMER_GROUP //
                        + ", please specify another one."//
                        + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // messageModel
    if (null == this.defaultMQPullConsumer.getMessageModel()) {
        throw new MQClientException(
                "messageModel is null" //
                        + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // allocateMessageQueueStrategy
    if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) {
        throw new MQClientException(
                "allocateMessageQueueStrategy is null" //
                        + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }

    // allocateMessageQueueStrategy
    if (this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() < this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis()) {
        throw new MQClientException(
                "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" //
                        + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
                null);
    }
}
 
Example #21
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException {
    this.makeSureStateOK();
    Validators.checkTopic(newTopic);

    this.mQClientFactory.getMQAdminImpl().createTopic(key, newTopic, queueNum, topicSysFlag);
}