org.apache.rocketmq.client.Validators Java Examples

The following examples show how to use org.apache.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 rocketmq with Apache License 2.0 6 votes vote down vote up
public SendResult send(Message msg, MessageQueue mq, long timeout)
    throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    long beginStartTime = System.currentTimeMillis();
    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);
    }

    long costTime = System.currentTimeMillis() - beginStartTime;
    if (timeout < costTime) {
        throw new RemotingTooMuchRequestException("call timeout");
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}
 
Example #2
Source File: DefaultMQProducerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public SendResult send(Message msg, MessageQueue mq, long timeout)
    throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    long beginStartTime = System.currentTimeMillis();
    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);
    }

    long costTime = System.currentTimeMillis() - beginStartTime;
    if (timeout < costTime) {
        throw new RemotingTooMuchRequestException("call timeout");
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}
 
Example #3
Source File: DefaultMQProducerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 专门选取某一个队列同步发送
 * @param msg msg
 * @param mq mq
 * @param timeout timeout
 * @return ;
 * @throws MQClientException ;
 * @throws RemotingException ;
 * @throws MQBrokerException ;
 * @throws InterruptedException ;
 */
public SendResult send(Message msg, MessageQueue mq, long timeout)
    throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    long beginStartTime = System.currentTimeMillis();
    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);
    }

    long costTime = System.currentTimeMillis() - beginStartTime;
    if (timeout < costTime) {
        throw new RemotingTooMuchRequestException("call timeout");
    }

    return this.sendKernelImpl(msg, mq, CommunicationMode.SYNC, null, null, timeout);
}
 
Example #4
Source File: DefaultMQProducer.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private MessageBatch batch(Collection<Message> msgs) throws MQClientException {
    MessageBatch msgBatch;
    try {
        msgBatch = MessageBatch.generateFromList(msgs);
        for (Message message : msgBatch) {
            Validators.checkMessage(message, this);
            MessageClientIDSetter.setUniqID(message);
            message.setTopic(withNamespace(message.getTopic()));
        }
        msgBatch.setBody(msgBatch.encode());
    } catch (Exception e) {
        throw new MQClientException("Failed to initiate the MessageBatch", e);
    }
    msgBatch.setTopic(withNamespace(msgBatch.getTopic()));
    return msgBatch;
}
 
Example #5
Source File: DefaultMQProducerImpl.java    From rocketmq_trans_message 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 #6
Source File: DefaultLitePullConsumerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private void checkConfig() throws MQClientException {
    // Check consumerGroup
    Validators.checkGroup(this.defaultLitePullConsumer.getConsumerGroup());

    // Check consumerGroup name is not equal default consumer group name.
    if (this.defaultLitePullConsumer.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);
    }

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

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

    if (this.defaultLitePullConsumer.getConsumerTimeoutMillisWhenSuspend() < this.defaultLitePullConsumer.getBrokerSuspendMaxTimeMillis()) {
        throw new MQClientException(
            "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis"
                + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
            null);
    }
}
 
Example #7
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 {
    long beginStartTime = System.currentTimeMillis();
    this.makeSureStateOK();
    Validators.checkMessage(msg, this.defaultMQProducer);

    TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
    if (topicPublishInfo != null && topicPublishInfo.ok()) {
        MessageQueue mq = null;
        try {
            List<MessageQueue> messageQueueList =
                mQClientFactory.getMQAdminImpl().parsePublishMessageQueues(topicPublishInfo.getMessageQueueList());
            Message userMessage = MessageAccessor.cloneMessage(msg);
            String userTopic = NamespaceUtil.withoutNamespace(userMessage.getTopic(), mQClientFactory.getClientConfig().getNamespace());
            userMessage.setTopic(userTopic);

            mq = mQClientFactory.getClientConfig().queueWithNamespace(selector.select(messageQueueList, userMessage, arg));
        } catch (Throwable e) {
            throw new MQClientException("select message queue throwed exception.", e);
        }

        long costTime = System.currentTimeMillis() - beginStartTime;
        if (timeout < costTime) {
            throw new RemotingTooMuchRequestException("sendSelectImpl call timeout");
        }
        if (mq != null) {
            return this.sendKernelImpl(msg, mq, communicationMode, sendCallback, null, timeout - costTime);
        } else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    validateNameServerSetting();
    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
Example #8
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("unknown exception", e);
    }
}
 
Example #9
Source File: DefaultMQProducerImpl.java    From rocketmq 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);
    Validators.isSystemTopic(newTopic);

    this.mQClientFactory.getMQAdminImpl().createTopic(key, newTopic, queueNum, topicSysFlag);
}
 
Example #10
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 #11
Source File: DefaultMQProducerImpl.java    From rocketmq_trans_message 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 #12
Source File: DefaultMQProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
private MessageBatch batch(Collection<Message> msgs) throws MQClientException {
    MessageBatch msgBatch;
    try {
        msgBatch = MessageBatch.generateFromList(msgs);
        for (Message message : msgBatch) {
            Validators.checkMessage(message, this);
            MessageClientIDSetter.setUniqID(message);
        }
        msgBatch.setBody(msgBatch.encode());
    } catch (Exception e) {
        throw new MQClientException("Failed to initiate the MessageBatch", e);
    }
    return msgBatch;
}
 
Example #13
Source File: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating 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("unknown exception", e);
    }
}
 
Example #14
Source File: DefaultMQProducerImpl.java    From DDMQ 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: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating 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 #16
Source File: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating 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 #17
Source File: DefaultMQProducerImpl.java    From rocketmq_trans_message 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 #18
Source File: DefaultMQProducerImpl.java    From rocketmq_trans_message 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("unknown exception", e);
    }
}
 
Example #19
Source File: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating 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 #20
Source File: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating 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("unknown exception", e);
    }
}
 
Example #21
Source File: SequenceProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example #22
Source File: RocketMQTopicProvisioner.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
private void checkTopic(String topic) {
	try {
		Validators.checkTopic(topic);
	}
	catch (MQClientException e) {
		throw new AssertionError(e);
	}
}
 
Example #23
Source File: RmqSender.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void send(DefaultMQProducer producer,
                        Message msg,
                        MessageQueue mq,
                        SendCallback sendCallback,
                        long timeout)
        throws MQBrokerException, MQClientException, RemotingException, InterruptedException {
    Validators.checkMessage(msg, producer);
    producer.getDefaultMQProducerImpl().sendKernelImpl(msg, mq, CommunicationMode.ASYNC, sendCallback, null, timeout);
}
 
Example #24
Source File: DefaultMQProducerImpl.java    From DDMQ 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 #25
Source File: DefaultMQProducerImpl.java    From DDMQ 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("unknown exception", e);
    }
}
 
Example #26
Source File: DefaultMQProducerImpl.java    From DDMQ 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("unknown exception", e);
    }
}
 
Example #27
Source File: DefaultMQProducerImpl.java    From DDMQ 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 #28
Source File: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}
 
Example #29
Source File: DefaultMQProducer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private MessageBatch batch(Collection<Message> msgs) throws MQClientException {
    MessageBatch msgBatch;
    try {
        msgBatch = MessageBatch.generateFromList(msgs);
        for (Message message : msgBatch) {
            Validators.checkMessage(message, null);
            MessageClientIDSetter.setUniqID(message);
        }
        msgBatch.setBody(msgBatch.encode());
    } catch (Exception e) {
        throw new MQClientException("Failed to initiate the MessageBatch", e);
    }
    return msgBatch;
}
 
Example #30
Source File: SequenceProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void send(final Message message) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = OMSUtil.msgConvert((BytesMessage) message);
    try {
        Validators.checkMessage(rmqMessage, this.rocketmqProducer);
    } catch (MQClientException e) {
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
    msgCacheQueue.add(message);
}