RocketMQ--生产者消息发送

异步发消息

image-20201021065310564

	//  2.2 异步发送消息
//			producer.send(message, new SendCallback() {
//				//rabbitmq急速入门的实战: 可靠性消息投递
//				@Override
//				public void onSuccess(SendResult sendResult) {
//					System.err.println("msgId: " + sendResult.getMsgId() + ", status: " + sendResult.getSendStatus());
//				}
//				@Override
//				public void onException(Throwable e) {
//					e.printStackTrace();
//					System.err.println("------发送失败");
//				}
//			});

image-20201021061331877

异步发消息不能将producer关掉

image-20201021061346455

同步发消息

image-20201021061525212

=========================================================================================================

image-20201021061604756

 @Override
    public SendResult send(
        Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
        return this.defaultMQProducerImpl.send(msg);
    }

=========================================================================================================

image-20201021061708272

    public SendResult send(
        Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
        return send(msg, this.defaultMQProducer.getSendMsgTimeout());
    }

=========================================================================================================

image-20201021062104384

    public SendResult send(Message msg,
        long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
        return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout);
    }

=========================================================================================================

image-20201021062217503

    private SendResult sendDefaultImpl(
        Message msg,
        final CommunicationMode communicationMode,
        final SendCallback sendCallback,
        final long timeout
    ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
        this.makeSureStateOK();
        Validators.checkMessage(msg, this.defaultMQProducer);

=========================================================================================================

image-20201021062240784

=========================================================================================================

image-20201021062424327

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.rocketmq.client.impl;

public enum CommunicationMode {
    SYNC, 同步
    ASYNC, 异步
    ONEWAY, 单向
}

=========================================================================================================

image-20201021062931773

image-20201021063221769

=========================================================================================================

image-20201021063249100

=========================================================================================================

image-20201021064414565

image-20201021064437875

=========================================================================================================

image-20201021064740947

image-20201021064806324

image-20201021064831530

image-20201021064903181

image-20201021065102943

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值