io.openmessaging.exception.OMSMessageFormatException Java Examples

The following examples show how to use io.openmessaging.exception.OMSMessageFormatException. 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: AbstractOMSProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                MQBrokerException brokerException = (MQBrokerException) e.getCause();
                return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                    topic, msgId, brokerException.getErrorMessage()), e);
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #2
Source File: ExceptionConverter.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
public static OMSRuntimeException convertProduceException(Throwable cause) {
    if (cause instanceof ClientException) {
        ClientException clientException = (ClientException) cause;
        if (clientException.getCause() instanceof TransportException.RequestTimeoutException) {
            return new OMSTimeOutException(JoyQueueCode.CN_REQUEST_TIMEOUT.getCode(), clientException.getMessage(), cause);
        }
        JoyQueueCode joyQueueCode = JoyQueueCode.valueOf(clientException.getCode());
        if (joyQueueCode.equals(JoyQueueCode.FW_TOPIC_NOT_EXIST) || joyQueueCode.equals(JoyQueueCode.FW_PRODUCER_NOT_EXISTS)) {
            return new OMSSecurityException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        if (joyQueueCode.equals(JoyQueueCode.CN_PARAM_ERROR)) {
            return new OMSMessageFormatException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        if (joyQueueCode.equals(JoyQueueCode.CN_SERVICE_NOT_AVAILABLE)) {
            return new OMSDestinationException(joyQueueCode.getCode(), clientException.getMessage(), cause);
        }
        return new OMSRuntimeException(clientException.getCode(), clientException.getMessage(), cause);
    } else {
        return convertRuntimeException(cause);
    }
}
 
Example #3
Source File: AbstractOMSProducer.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                MQBrokerException brokerException = (MQBrokerException) e.getCause();
                return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                    topic, msgId, brokerException.getErrorMessage()), e);
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #4
Source File: AbstractOMSProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                MQBrokerException brokerException = (MQBrokerException) e.getCause();
                return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                    topic, msgId, brokerException.getErrorMessage()), e);
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #5
Source File: AbstractOMSProducer.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                if (e.getCause() instanceof MQBrokerException) {
                    MQBrokerException brokerException = (MQBrokerException) e.getCause();
                    return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                        topic, msgId, brokerException.getErrorMessage()), e);
                }

                if (e.getCause() instanceof RemotingConnectException) {
                    RemotingConnectException connectException = (RemotingConnectException)e.getCause();
                    return new OMSRuntimeException("-1",
                        String.format("Network connection experiences failures. Topic=%s, msgId=%s, %s",
                            topic, msgId, connectException.getMessage()),
                        e);
                }
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #6
Source File: BytesMessageImpl.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getBody(Class<T> type) throws OMSMessageFormatException {
    if (type == byte[].class) {
        return (T)body;
    }

    throw new OMSMessageFormatException("", "Cannot assign byte[] to " + type.getName());
}
 
Example #7
Source File: AbstractOMSProducer.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                if (e.getCause() instanceof MQBrokerException) {
                    MQBrokerException brokerException = (MQBrokerException) e.getCause();
                    return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                        topic, msgId, brokerException.getErrorMessage()), e);
                }

                if (e.getCause() instanceof RemotingConnectException) {
                    RemotingConnectException connectException = (RemotingConnectException)e.getCause();
                    return new OMSRuntimeException("-1",
                        String.format("Network connection experiences failures. Topic=%s, msgId=%s, %s",
                            topic, msgId, connectException.getMessage()),
                        e);
                }
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #8
Source File: BytesMessageImpl.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getBody(Class<T> type) throws OMSMessageFormatException {
    if (type == byte[].class) {
        return (T)body;
    }

    throw new OMSMessageFormatException("", "Cannot assign byte[] to " + type.getName());
}
 
Example #9
Source File: AbstractOMSProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
OMSRuntimeException checkProducerException(String topic, String msgId, Throwable e) {
    if (e instanceof MQClientException) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof RemotingTimeoutException) {
                return new OMSTimeOutException("-1", String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s",
                    this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e);
            } else if (e.getCause() instanceof MQBrokerException || e.getCause() instanceof RemotingConnectException) {
                if (e.getCause() instanceof MQBrokerException) {
                    MQBrokerException brokerException = (MQBrokerException) e.getCause();
                    return new OMSRuntimeException("-1", String.format("Received a broker exception, Topic=%s, msgId=%s, %s",
                        topic, msgId, brokerException.getErrorMessage()), e);
                }

                if (e.getCause() instanceof RemotingConnectException) {
                    RemotingConnectException connectException = (RemotingConnectException)e.getCause();
                    return new OMSRuntimeException("-1",
                        String.format("Network connection experiences failures. Topic=%s, msgId=%s, %s",
                            topic, msgId, connectException.getMessage()),
                        e);
                }
            }
        }
        // Exception thrown by local.
        else {
            MQClientException clientException = (MQClientException) e;
            if (-1 == clientException.getResponseCode()) {
                return new OMSRuntimeException("-1", String.format("Topic does not exist, Topic=%s, msgId=%s",
                    topic, msgId), e);
            } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) {
                return new OMSMessageFormatException("-1", String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s",
                    topic, msgId), e);
            }
        }
    }
    return new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.", e);
}
 
Example #10
Source File: BytesMessageImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getBody(Class<T> type) throws OMSMessageFormatException {
    if (type == byte[].class) {
        return (T)body;
    }

    throw new OMSMessageFormatException("", "Cannot assign byte[] to " + type.getName());
}