• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SendCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.alibaba.rocketmq.client.producer.SendCallback的典型用法代码示例。如果您正苦于以下问题:Java SendCallback类的具体用法?Java SendCallback怎么用?Java SendCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SendCallback类属于com.alibaba.rocketmq.client.producer包,在下文中一共展示了SendCallback类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testAsyncProducer

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
@Test
public void testAsyncProducer() throws Exception {
    // Instantiate with a producer group name.
    DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");
    // Launch the instance.
    producer.start();
    producer.setRetryTimesWhenSendAsyncFailed(0);
    for (int i = 0; i < 100; i++) {
        final int index = i;
        // Create a message instance, specifying topic, tag and message body.
        Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
        producer.send(msg, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.printf("%-10d OK %s %n", index, sendResult.getMsgId());
            }

            @Override
            public void onException(Throwable e) {
                System.out.printf("%-10d Exception %s %n", index, e);
                e.printStackTrace();
            }
        });
    }
}
 
开发者ID:dzh,项目名称:coca,代码行数:26,代码来源:TestProducer.java


示例2: send

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
/**
 * KERNEL ASYNC -------------------------------------------------------
 */
public void send(Message msg, MessageQueue mq, SendCallback sendCallback) 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);
    }
    catch (MQBrokerException e) {
        throw new MQClientException("unknow exception", e);
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:21,代码来源:DefaultMQProducerImpl.java


示例3: sendMessage

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
public SendResult sendMessage(//
        final String addr,// 1
        final String brokerName,// 2
        final Message msg,// 3
        final SendMessageRequestHeader requestHeader,// 4
        final long timeoutMillis,// 5
        final CommunicationMode communicationMode,// 6
        final SendCallback sendCallback// 7
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = null;
    if (sendSmartMsg) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    }
    else { //组装头部信息
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody()); //包体body信息赋值

    switch (communicationMode) {
    case ONEWAY:
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
        return null;
    case ASYNC:
        this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
        return null;
    case SYNC:
        return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
    default:
        assert false;
        break;
    }

    return null;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:37,代码来源:MQClientAPIImpl.java


示例4: sendMessageAsync

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private void sendMessageAsync(//
        final String addr,//
        final String brokerName,//
        final Message msg,//
        final long timeoutMillis,//
        final RemotingCommand request,//
        final SendCallback sendCallback//
) throws RemotingException, InterruptedException {
    this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            if (null == sendCallback)
                return;

            RemotingCommand response = responseFuture.getResponseCommand();
            if (response != null) {
                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    assert sendResult != null;
                    sendCallback.onSuccess(sendResult);
                }
                catch (Exception e) {
                    sendCallback.onException(e);
                }
            }
            else {
                if (!responseFuture.isSendRequestOK()) {
                    sendCallback.onException(new MQClientException("send request failed", responseFuture.getCause()));
                }
                else if (responseFuture.isTimeout()) {
                    sendCallback.onException(new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms",
                        responseFuture.getCause()));
                }
                else {
                    sendCallback.onException(new MQClientException("unknow reseaon", responseFuture.getCause()));
                }
            }
        }
    });
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:41,代码来源:MQClientAPIImpl.java


示例5: send

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private void send(Message msg, PacketFuture pf) throws Exception {
    producer.send(msg, new SendCallback() {
        @Override
        public void onSuccess(SendResult sendResult) {
            LOG.info(sendResult.toString());
            pf.result(new PacketResult(PacketResult.IOSt.SEND_SUCC));
        }

        @Override
        public void onException(Throwable e) {
            LOG.error(e.getMessage(), e);
            pf.result(new PacketResult(PacketResult.IOSt.SEND_FAIL));
        }
    });
}
 
开发者ID:dzh,项目名称:coca,代码行数:16,代码来源:RMQGroupChannel.java


示例6: sendMessageAsync

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private void sendMessageAsync(//
                              final String addr,//
                              final String brokerName,//
                              final Message msg,//
                              final long timeoutMillis,//
                              final RemotingCommand request,//
                              final SendCallback sendCallback//
) throws RemotingException, InterruptedException {
    this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            if (null == sendCallback)
                return;

            RemotingCommand response = responseFuture.getResponseCommand();
            if (response != null) {
                try {
                    SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    assert sendResult != null;
                    sendCallback.onSuccess(sendResult);
                } catch (Exception e) {
                    sendCallback.onException(e);
                }
            } else {
                if (!responseFuture.isSendRequestOK()) {
                    sendCallback.onException(new MQClientException("send request failed", responseFuture.getCause()));
                } else if (responseFuture.isTimeout()) {
                    sendCallback.onException(new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms",
                            responseFuture.getCause()));
                } else {
                    sendCallback.onException(new MQClientException("unknow reseaon", responseFuture.getCause()));
                }
            }
        }
    });
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:37,代码来源:MQClientAPIImpl.java


示例7: sendSelectImpl

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private SendResult sendSelectImpl(//
        Message msg,//
        MessageQueueSelector selector,//
        Object arg,//
        final CommunicationMode communicationMode,//
        final SendCallback sendCallback//
) 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);
        }
        else {
            throw new MQClientException("select message queue return null.", null);
        }
    }

    throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:32,代码来源:DefaultMQProducerImpl.java


示例8: sendMessage

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
/**
 * 发送消息
 */
public SendResult sendMessage(//
        final String addr,// 1
        final String brokerName,// 2
        final Message msg,// 3
        final SendMessageRequestHeader requestHeader,// 4
        final long timeoutMillis,// 5
        final CommunicationMode communicationMode,// 6
        final SendCallback sendCallback// 7
) throws RemotingException, MQBrokerException, InterruptedException {
    // 添加虚拟运行环境相关的projectGroupPrefix
    if (!UtilAll.isBlank(projectGroupPrefix)) {
        msg.setTopic(VirtualEnvUtil.buildWithProjectGroup(msg.getTopic(), projectGroupPrefix));
        requestHeader.setProducerGroup(VirtualEnvUtil.buildWithProjectGroup(
            requestHeader.getProducerGroup(), projectGroupPrefix));
        requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
            projectGroupPrefix));
    }

    RemotingCommand request =
            RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);

    request.setBody(msg.getBody());

    switch (communicationMode) {
    case ONEWAY:
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
        return null;
    case ASYNC:
        this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
        return null;
    case SYNC:
        return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
    default:
        assert false;
        break;
    }

    return null;
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:43,代码来源:MQClientAPIImpl.java


示例9: sendMessage

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
/**
 * 发送消息
 */
public SendResult sendMessage(//
        final String addr,// 1
        final String brokerName,// 2
        final Message msg,// 3
        final SendMessageRequestHeader requestHeader,// 4
        final long timeoutMillis,// 5
        final CommunicationMode communicationMode,// 6
        final SendCallback sendCallback// 7
) throws RemotingException, MQBrokerException, InterruptedException {
    // 添加虚拟运行环境相关的projectGroupPrefix
    if (!UtilAll.isBlank(projectGroupPrefix)) {
        msg.setTopic(VirtualEnvUtil.buildWithProjectGroup(msg.getTopic(), projectGroupPrefix));
        requestHeader.setProducerGroup(VirtualEnvUtil.buildWithProjectGroup(
            requestHeader.getProducerGroup(), projectGroupPrefix));
        requestHeader.setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(),
            projectGroupPrefix));
    }

    RemotingCommand request =
            RemotingCommand.createRequestCommand(MQRequestCode.SEND_MESSAGE_VALUE, requestHeader);
    request.setBody(msg.getBody());

    switch (communicationMode) {
    case ONEWAY:
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
        return null;
    case ASYNC:
        this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
        return null;
    case SYNC:
        return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
    default:
        assert false;
        break;
    }

    return null;
}
 
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:42,代码来源:MQClientAPIImpl.java


示例10: sendMessage

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
/**
 * 发送消息到Broker
 *
 * @param addr              broker地址
 * @param brokerName
 * @param msg
 * @param requestHeader
 * @param timeoutMillis
 * @param communicationMode
 * @param sendCallback
 * @return
 * @throws RemotingException
 * @throws MQBrokerException
 * @throws InterruptedException
 */
public SendResult sendMessage(//
                              final String addr,// 1
                              final String brokerName,// 2
                              final Message msg,// 3
                              final SendMessageRequestHeader requestHeader,// 4
                              final long timeoutMillis,// 5
                              final CommunicationMode communicationMode,// 6
                              final SendCallback sendCallback// 7
) throws RemotingException, MQBrokerException, InterruptedException {

    RemotingCommand request = null;
    /**
     * send smart msg?
     * 作用是啥?
     */
    if (sendSmartMsg) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    } else {
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody());

    switch (communicationMode) {
        case ONEWAY:
            this.remotingClient.invokeOneway(addr, request, timeoutMillis);
            return null;
        case ASYNC:
            this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
            return null;
        case SYNC:
            return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
        default:
            assert false;
            break;
    }

    return null;
}
 
开发者ID:medusar,项目名称:rocketmq-commet,代码行数:56,代码来源:MQClientAPIImpl.java


示例11: sendMessageAsync

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private void sendMessageAsync(//
        final String addr,//
        final String brokerName,//
        final Message msg,//
        final long timeoutMillis,//
        final RemotingCommand request,//
        final SendCallback sendCallback//
) throws RemotingException, InterruptedException {
    this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            if (null == sendCallback)
                return;

            RemotingCommand response = responseFuture.getResponseCommand();
            if (response != null) {
                try {
                    SendResult sendResult =
                            MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
                    assert sendResult != null;
                    sendCallback.onSuccess(sendResult);
                }
                catch (Exception e) {
                    sendCallback.onException(e);
                }
            }
            else {
                if (!responseFuture.isSendRequestOK()) {
                    sendCallback.onException(new MQClientException("send request failed", responseFuture
                        .getCause()));
                }
                else if (responseFuture.isTimeout()) {
                    sendCallback.onException(new MQClientException("wait response timeout "
                            + responseFuture.getTimeoutMillis() + "ms", responseFuture.getCause()));
                }
                else {
                    sendCallback.onException(new MQClientException("unknow reseaon", responseFuture
                        .getCause()));
                }
            }
        }
    });
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:44,代码来源:MQClientAPIImpl.java


示例12: createDefaultSendCallback

import com.alibaba.rocketmq.client.producer.SendCallback; //导入依赖的package包/类
private SendCallback createDefaultSendCallback(){
	
	return new DefaultSendCallback();
}
 
开发者ID:bigdatafly,项目名称:flume-rocketmq-sink,代码行数:5,代码来源:RocketMQSink.java



注:本文中的com.alibaba.rocketmq.client.producer.SendCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WalletCoinsSentEventListener类代码示例发布时间:2022-05-23
下一篇:
Java InclusiveNamespaces类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap