Search in sources :

Example 1 with DefaultPromise

use of io.openmessaging.rocketmq.promise.DefaultPromise in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ProducerImpl method sendAsync.

private Promise<SendResult> sendAsync(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    final Promise<SendResult> promise = new DefaultPromise<>();
    try {
        this.rocketmqProducer.send(rmqMessage, new SendCallback() {

            @Override
            public void onSuccess(final org.apache.rocketmq.client.producer.SendResult rmqResult) {
                message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
                promise.set(OMSUtil.sendResultConvert(rmqResult));
            }

            @Override
            public void onException(final Throwable e) {
                promise.setFailure(e);
            }
        }, timeout);
    } catch (Exception e) {
        promise.setFailure(e);
    }
    return promise;
}
Also used : OMSRuntimeException(io.openmessaging.exception.OMSRuntimeException) DefaultPromise(io.openmessaging.rocketmq.promise.DefaultPromise) SendResult(io.openmessaging.SendResult) SendCallback(org.apache.rocketmq.client.producer.SendCallback)

Example 2 with DefaultPromise

use of io.openmessaging.rocketmq.promise.DefaultPromise in project rocketmq by apache.

the class ProducerImpl method sendAsync.

private Promise<SendResult> sendAsync(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    final Promise<SendResult> promise = new DefaultPromise<>();
    try {
        this.rocketmqProducer.send(rmqMessage, new SendCallback() {

            @Override
            public void onSuccess(final org.apache.rocketmq.client.producer.SendResult rmqResult) {
                message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
                promise.set(OMSUtil.sendResultConvert(rmqResult));
            }

            @Override
            public void onException(final Throwable e) {
                promise.setFailure(e);
            }
        }, timeout);
    } catch (Exception e) {
        promise.setFailure(e);
    }
    return promise;
}
Also used : OMSRuntimeException(io.openmessaging.exception.OMSRuntimeException) DefaultPromise(io.openmessaging.rocketmq.promise.DefaultPromise) SendResult(io.openmessaging.SendResult) SendCallback(org.apache.rocketmq.client.producer.SendCallback)

Aggregations

SendResult (io.openmessaging.SendResult)2 OMSRuntimeException (io.openmessaging.exception.OMSRuntimeException)2 DefaultPromise (io.openmessaging.rocketmq.promise.DefaultPromise)2 SendCallback (org.apache.rocketmq.client.producer.SendCallback)2