Search in sources :

Example 1 with RTUnsupportedEncodingException

use of com.ecfront.dew.common.exception.RTUnsupportedEncodingException in project dew by gudaoxuri.

the class RocketClusterMQ method doPublish.

@Override
protected boolean doPublish(String topic, String message, Optional<Map<String, Object>> header, boolean confirm) {
    RocketMQTemplate rocketMQTemplate = rocketAdapter.getRocketMQTemplate();
    Object funResult = null;
    if (confirm) {
        throw new RTUnsupportedEncodingException("Rocket doesn't support confirm mode");
    }
    try {
        Map<String, Object> sendHeader = getMQHeader(topic);
        header.ifPresent(sendHeader::putAll);
        Message<?> msg = MessageBuilder.withPayload(message).copyHeaders(sendHeader).build();
        funResult = sendBeforeFun.invoke(topic, sendHeader);
        rocketMQTemplate.syncSend(topic, msg);
        return true;
    } catch (Exception e) {
        logger.error("[MQ] Rocket publish error.", e);
        sendErrorFun.invoke(e, funResult);
        return false;
    } finally {
        sendFinishFun.invoke(funResult);
    }
}
Also used : RocketMQTemplate(org.apache.rocketmq.spring.core.RocketMQTemplate) RTUnsupportedEncodingException(com.ecfront.dew.common.exception.RTUnsupportedEncodingException) RTUnsupportedEncodingException(com.ecfront.dew.common.exception.RTUnsupportedEncodingException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with RTUnsupportedEncodingException

use of com.ecfront.dew.common.exception.RTUnsupportedEncodingException in project dew by gudaoxuri.

the class RocketClusterMQ method doRequest.

@Override
protected boolean doRequest(String address, String message, Optional<Map<String, Object>> header, boolean confirm) {
    RocketMQTemplate rocketMQTemplate = rocketAdapter.getRocketMQTemplate();
    Object funResult = null;
    if (confirm) {
        throw new RTUnsupportedEncodingException("Rocket doesn't support confirm mode");
    }
    try {
        Map<String, Object> sendHeader = getMQHeader(address);
        header.ifPresent(sendHeader::putAll);
        funResult = sendBeforeFun.invoke(address, sendHeader);
        Message<?> msg = MessageBuilder.withPayload(message).copyHeaders(sendHeader).build();
        rocketMQTemplate.syncSend(address, msg);
        return true;
    } catch (Exception e) {
        logger.error("[MQ] Rocket publish error.", e);
        sendErrorFun.invoke(e, funResult);
        return false;
    } finally {
        sendFinishFun.invoke(funResult);
    }
}
Also used : RocketMQTemplate(org.apache.rocketmq.spring.core.RocketMQTemplate) RTUnsupportedEncodingException(com.ecfront.dew.common.exception.RTUnsupportedEncodingException) RTUnsupportedEncodingException(com.ecfront.dew.common.exception.RTUnsupportedEncodingException) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Aggregations

RTUnsupportedEncodingException (com.ecfront.dew.common.exception.RTUnsupportedEncodingException)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 RocketMQTemplate (org.apache.rocketmq.spring.core.RocketMQTemplate)2