Search in sources :

Example 1 with MessagingException

use of org.springframework.messaging.MessagingException in project rocketmq-externals by apache.

the class RocketMQTemplate method asyncSend.

/**
 * Same to {@link #asyncSend(String, Message, SendCallback)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message {@link org.springframework.messaging.Message}
 * @param sendCallback {@link SendCallback}
 * @param timeout send timeout with millis
 */
public void asyncSend(String destination, Message<?> message, SendCallback sendCallback, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("asyncSend failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }
    try {
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        producer.send(rocketMsg, sendCallback, timeout);
    } catch (Exception e) {
        log.info("asyncSend failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with MessagingException

use of org.springframework.messaging.MessagingException in project rocketmq-externals by apache.

the class RocketMQTemplate method asyncSendOrderly.

/**
 * Same to {@link #asyncSendOrderly(String, Message, String, SendCallback)} with send timeout specified in
 * addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message {@link org.springframework.messaging.Message}
 * @param hashKey use this key to select queue. for example: orderId, productId ...
 * @param sendCallback {@link SendCallback}
 * @param timeout send timeout with millis
 */
public void asyncSendOrderly(String destination, Message<?> message, String hashKey, SendCallback sendCallback, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("asyncSendOrderly failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }
    try {
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        producer.send(rocketMsg, messageQueueSelector, hashKey, sendCallback, timeout);
    } catch (Exception e) {
        log.info("asyncSendOrderly failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with MessagingException

use of org.springframework.messaging.MessagingException in project rocketmq-externals by apache.

the class RocketMQTemplate method syncSendOrderly.

/**
 * Same to {@link #syncSendOrderly(String, Message, String)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message {@link org.springframework.messaging.Message}
 * @param hashKey use this key to select queue. for example: orderId, productId ...
 * @param timeout send timeout with millis
 * @return {@link SendResult}
 */
public SendResult syncSendOrderly(String destination, Message<?> message, String hashKey, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("syncSendOrderly failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }
    try {
        long now = System.currentTimeMillis();
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        SendResult sendResult = producer.send(rocketMsg, messageQueueSelector, hashKey, timeout);
        long costTime = System.currentTimeMillis() - now;
        log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
        return sendResult;
    } catch (Exception e) {
        log.info("syncSendOrderly failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) SendResult(org.apache.rocketmq.client.producer.SendResult) MessagingException(org.springframework.messaging.MessagingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with MessagingException

use of org.springframework.messaging.MessagingException in project rocketmq-externals by apache.

the class RocketMQTemplate method sendOneWay.

/**
 * Similar to <a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol">UDP</a>, this method won't wait for
 * acknowledgement from broker before return. Obviously, it has maximums throughput yet potentials of message loss.
 *
 * One-way transmission is used for cases requiring moderate reliability, such as log collection.
 *
 * @param destination formats: `topicName:tags`
 * @param message {@link org.springframework.messaging.Message}
 */
public void sendOneWay(String destination, Message<?> message) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("sendOneWay failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }
    try {
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        producer.sendOneway(rocketMsg);
    } catch (Exception e) {
        log.info("sendOneWay failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with MessagingException

use of org.springframework.messaging.MessagingException in project rocketmq-externals by apache.

the class RocketMQTemplate method syncSend.

/**
 * Same to {@link #syncSend(String, Message)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message {@link org.springframework.messaging.Message}
 * @param timeout send timeout with millis
 * @return {@link SendResult}
 */
public SendResult syncSend(String destination, Message<?> message, long timeout) {
    if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
        log.info("syncSend failed. destination:{}, message is null ", destination);
        throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
    }
    try {
        long now = System.currentTimeMillis();
        org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
        SendResult sendResult = producer.send(rocketMsg, timeout);
        long costTime = System.currentTimeMillis() - now;
        log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
        return sendResult;
    } catch (Exception e) {
        log.info("syncSend failed. destination:{}, message:{} ", destination, message);
        throw new MessagingException(e.getMessage(), e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) SendResult(org.apache.rocketmq.client.producer.SendResult) MessagingException(org.springframework.messaging.MessagingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)143 Test (org.junit.Test)60 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 MessageHandlingException (org.springframework.messaging.MessageHandlingException)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8