当前位置:   article > 正文

RocketMQ源码解析-Producer消息发送_producerclient sendcallback sendcallback 实现

producerclient sendcallback sendcallback 实现

首先以默认的异步消息发送模式作为例子。DefaultMQProducer中的send()方法会直接调用DefaultMQProducerImpl的send()方法,在DefaultMQProducerImpl会直接调用sendDefaultImpl()方法。

 

  1. public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException,
  2. InterruptedException {
  3. send(msg, sendCallback, this.defaultMQProducer.getSendMsgTimeout());
  4. }
  5. public void send(Message msg, SendCallback sendCallback, long timeout) throws MQClientException,
  6. RemotingException, InterruptedException {
  7. try {
  8. this.sendDefaultImpl(msg, CommunicationMode.ASYNC, sendCallback, timeout);
  9. }
  10. catch (MQBrokerException e) {
  11. throw new MQClientException("unknown exception", e);
  12. }
  13. }
  14. private SendResult sendDefaultImpl(//
  15. Message msg,//
  16. final CommunicationMode communicationMode,//
  17. final SendCallback sendCallback, final long timeout//
  18. ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
  19. this.makeSureStateOK();
  20. Validators.checkMessage(msg, this.defaultMQProducer);
  21. final long maxTimeout = this.defaultMQProducer.getSendMsgTimeout() + 1000;
  22. final long beginTimestamp = System.currentTimeMillis();
  23. long endTimestamp = beginTimestamp;
  24. TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
  25. if (topicPublishInfo != null && topicPublishInfo.ok()) {
  26. MessageQueue mq = null;
  27. Exception exception = null;
  28. SendResult sendResult = null;
  29. int timesTotal = 1 + this.defaultMQProducer.getRetryTimesWhenSendFailed();
  30. int times = 0;
  31. String[] brokersSent = new String[timesTotal];
  32. for (; times < timesTotal && (endTimestamp - beginTimestamp) < maxTimeout; times++) {
  33. String lastBrokerName = null == mq ? null : mq.getBrokerName();
  34. MessageQueue tmpmq = topicPublishInfo.selectOneMessageQueue(lastBrokerName);
  35. if (tmpmq != null) {
  36. mq = tmpmq;
  37. brokersSent[times] = mq.getBrokerName();
  38. try {
  39. sendResult = this.sendKernelImpl(msg, mq, communicationMode, sendCallback, timeout);
  40. endTimestamp = System.currentTimeMillis();
  41. switch (communicationMode) {
  42. case ASYNC:
  43. return null;
  44. case ONEWAY:
  45. return null;
  46. case SYNC:
  47. if (sendResult.getSendStatus() != SendStatus.SEND_OK) {
  48. if (this.defaultMQProducer.isRetryAnotherBrokerWhenNotStoreOK()) {
  49. continue;
  50. }
  51. }
  52. return sendResult;
  53. default:
  54. break;
  55. }
  56. }
  57. catch (RemotingException e) {
  58. log.warn("sendKernelImpl exception", e);
  59. log.warn(msg.toString());
  60. exception = e;
  61. endTimestamp = System.currentTimeMillis();
  62. continue;
  63. }
  64. catch (MQClientException e) {
  65. log.warn("sendKernelImpl exception", e);
  66. log.warn(msg.toString());
  67. exception = e;
  68. endTimestamp = System.currentTimeMillis();
  69. continue;
  70. }
  71. catch (MQBrokerException e) {
  72. log.warn("sendKernelImpl exception", e);
  73. log.warn(msg.toString());
  74. exception = e;
  75. endTimestamp = System.currentTimeMillis();
  76. switch (e.getResponseCode()) {
  77. case ResponseCode.TOPIC_NOT_EXIST:
  78. case ResponseCode.SERVICE_NOT_AVAILABLE:
  79. case ResponseCode.SYSTEM_ERROR:
  80. case ResponseCode.NO_PERMISSION:
  81. case ResponseCode.NO_BUYER_ID:
  82. case ResponseCode.NOT_IN_CURRENT_UNIT:
  83. continue;
  84. default:
  85. if (sendResult != null) {
  86. return sendResult;
  87. }
  88. throw e;
  89. }
  90. }
  91. catch (InterruptedException e) {
  92. log.warn("sendKernelImpl exception", e);
  93. log.warn(msg.toString());
  94. throw e;
  95. }
  96. }
  97. else {
  98. break;
  99. }
  100. } // end of for
  101. if (sendResult != null) {
  102. return sendResult;
  103. }
  104. String info =
  105. String.format("Send [%d] times, still failed, cost [%d]ms, Topic: %s, BrokersSent: %s", //
  106. times, //
  107. (System.currentTimeMillis() - beginTimestamp), //
  108. msg.getTopic(),//
  109. Arrays.toString(brokersSent));
  110. info += FAQUrl.suggestTodo(FAQUrl.SEND_MSG_FAILED);
  111. throw new MQClientException(info, exception);
  112. }
  113. List<String> nsList = this.getmQClientFactory().getMQClientAPIImpl().getNameServerAddressList();
  114. if (null == nsList || nsList.isEmpty()) {
  115. throw new MQClientException("No name server address, please set it."
  116. + FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL), null);
  117. }
  118. throw new MQClientException("No route info of this topic, " + msg.getTopic()
  119. + FAQUrl.suggestTodo(FAQUrl.NO_TOPIC_ROUTE_INFO), null);
  120. }

 

 

 

由该方法的参数可得知Rocketmq的消息发送模式,打开CommunicationMode可以看到具体的发送模式

  1. public enum CommunicationMode {
  2. SYNC,
  3. ASYNC,
  4. ONEWAY,
  5. }

以异步消息发送模式(ASYNC)作为例子,需要在具体的实现里传入相应的sendCallback处理消息异步收到消息回复结果的消息处理。

首先通过调用makeSureStateOK()方法来确保该生产者正处于运行状态,判断的方式很简单

  1. private void makeSureStateOK() throws MQClientException {
  2. if (this.serviceState != ServiceState.RUNNING) {
  3. throw new MQClientException("The producer service state not OK, "//
  4. + this.serviceState//
  5. + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null);
  6. }
  7. }

只要比较一下状态量就行了。

接下来是对所需要的发送的消息进行验证,具体的验证方法在RocketMq里的Validators实现

  1. public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer)
  2. throws MQClientException {
  3. if (null == msg) {
  4. throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message is null");
  5. }
  6. // topic
  7. Validators.checkTopic(msg.getTopic());
  8. // body
  9. if (null == msg.getBody()) {
  10. throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body is null");
  11. }
  12. if (0 == msg.getBody().length) {
  13. throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body length is zero");
  14. }
  15. if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
  16. throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,
  17. "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize());
  18. }
  19. }

 

具体是对消息具体数据的判空,以及在通过和在DefaultMQProducer里的消息大小配置属性进行比较确保消息的大小符合在配置中的设置。在其中也对消息的topic进行了检察,主要通过正则表达式确保topic的格式,以及topic的有效性。

 

在接下来的发送步骤中,接下里通过调用tryTOFindTopicPublishInfo()方法来根据消息的topic来获取相关topicd的路由信息。这个时候,整个发送消息的beginTimestamp已经被设置,也就是说整个发送消息的timeout已经开始。

  1. private TopicPublishInfo tryToFindTopicPublishInfo(final String topic) {
  2. TopicPublishInfo topicPublishInfo = this.topicPublishInfoTable.get(topic);
  3. if (null == topicPublishInfo || !topicPublishInfo.ok()) {
  4. this.topicPublishInfoTable.putIfAbsent(topic, new TopicPublishInfo());
  5. this.mQClientFactory.updateTopicRouteInfoFromNameServer(topic);
  6. topicPublishInfo = this.topicPublishInfoTable.get(topic);
  7. }
  8. if (topicPublishInfo.isHaveTopicRouterInfo() || (topicPublishInfo != null && topicPublishInfo.ok())) {
  9. return topicPublishInfo;
  10. }
  11. else {
  12. this.mQClientFactory.updateTopicRouteInfoFromNameServer(topic, true, this.defaultMQProducer);
  13. topicPublishInfo = this.topicPublishInfoTable.get(topic);
  14. return topicPublishInfo;
  15. }
  16. }

 

在这个方法中,首先会尝试在DefaultMQProducerImpl中保存的路由信息map里去寻找,如果找不到则会重新创建一个topicPublishInfo类,从名称服务那里去尝试更新获取新的路由信息数据。这里调用的方法updateTopicPublishInfo()方法与客户端执行的定时更新路由任务相同,也就说在发送topic找不到相应的路由信息的时候会重复一次更新这个定时任务的操作。

 

在成功获取了相应路由信息的同时就可以正式开始消息的发送。在之前的尝试获取路由消息的步骤已经算在了整个消息发送的timeout里。

在整个消息发送的过程中,如果因为各种原因消息发送失败,可以设置消息重新发送的次数。也就是说一短消息最大可以发送的次数是1+最大可重发次数,建立一个该次数大小的定长数组来保存每次发送的brokerName。这里主要针对同步发送模式。

首先通过之前获得topic得到的路由信息来以上一次发送的BrokerName为依据得到当前次数发送的消息队列。

由topicPublishInfo的selectOneMessageQuene()方法来实现。

 

 

 

  1. public MessageQueue selectOneMessageQueue(final String lastBrokerName) {
  2. if (lastBrokerName != null) {
  3. int index = this.sendWhichQueue.getAndIncrement();
  4. for (int i = 0; i < this.messageQueueList.size(); i++) {
  5. int pos = Math.abs(index++) % this.messageQueueList.size();
  6. MessageQueue mq = this.messageQueueList.get(pos);
  7. if (!mq.getBrokerName().equals(lastBrokerName)) {
  8. return mq;
  9. }
  10. }
  11. return null;
  12. }
  13. else {
  14. int index = this.sendWhichQueue.getAndIncrement();
  15. int pos = Math.abs(index) % this.messageQueueList.size();
  16. return this.messageQueueList.get(pos);
  17. }
  18. }

消息队列的选取在这里根据消息传进来的时候的index达到平均轮询各个消息队列的目的,也就是说完成了每个消息队列负载的平衡,与此同时,可以根据上一次发送的broker名称达到不在一条消息队列重复发送的目的。

在成功获取了需要发送的消息队列之后,调用sendKernalImpl()发送消息。

  1. private SendResult sendKernelImpl(final Message msg,//
  2. final MessageQueue mq,//
  3. final CommunicationMode communicationMode,//
  4. final SendCallback sendCallback,//
  5. final long timeout) throws MQClientException, RemotingException, MQBrokerException,
  6. InterruptedException {
  7. String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
  8. if (null == brokerAddr) {
  9. tryToFindTopicPublishInfo(mq.getTopic());
  10. brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
  11. }
  12. SendMessageContext context = null;
  13. if (brokerAddr != null) {
  14. if(this.defaultMQProducer.isSendMessageWithVIPChannel()) {
  15. brokerAddr = MixAll.brokerVIPChannel(brokerAddr);
  16. }
  17. byte[] prevBody = msg.getBody();
  18. try {
  19. int sysFlag = 0;
  20. if (this.tryToCompressMessage(msg)) {
  21. sysFlag |= MessageSysFlag.CompressedFlag;
  22. }
  23. final String tranMsg = msg.getProperty(MessageConst.PROPERTY_TRANSACTION_PREPARED);
  24. if (tranMsg != null && Boolean.parseBoolean(tranMsg)) {
  25. sysFlag |= MessageSysFlag.TransactionPreparedType;
  26. }
  27. if (hasCheckForbiddenHook()) {
  28. CheckForbiddenContext checkForbiddenContext = new CheckForbiddenContext();
  29. checkForbiddenContext.setNameSrvAddr(this.defaultMQProducer.getNamesrvAddr());
  30. checkForbiddenContext.setGroup(this.defaultMQProducer.getProducerGroup());
  31. checkForbiddenContext.setCommunicationMode(communicationMode);
  32. checkForbiddenContext.setBrokerAddr(brokerAddr);
  33. checkForbiddenContext.setMessage(msg);
  34. checkForbiddenContext.setMq(mq);
  35. checkForbiddenContext.setUnitMode(this.isUnitMode());
  36. this.executeCheckForbiddenHook(checkForbiddenContext);
  37. }
  38. if (this.hasSendMessageHook()) {
  39. context = new SendMessageContext();
  40. context.setProducerGroup(this.defaultMQProducer.getProducerGroup());
  41. context.setCommunicationMode(communicationMode);
  42. context.setBornHost(this.defaultMQProducer.getClientIP());
  43. context.setBrokerAddr(brokerAddr);
  44. context.setMessage(msg);
  45. context.setMq(mq);
  46. this.executeSendMessageHookBefore(context);
  47. }
  48. SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
  49. requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup());
  50. requestHeader.setTopic(msg.getTopic());
  51. requestHeader.setDefaultTopic(this.defaultMQProducer.getCreateTopicKey());
  52. requestHeader.setDefaultTopicQueueNums(this.defaultMQProducer.getDefaultTopicQueueNums());
  53. requestHeader.setQueueId(mq.getQueueId());
  54. requestHeader.setSysFlag(sysFlag);
  55. requestHeader.setBornTimestamp(System.currentTimeMillis());
  56. requestHeader.setFlag(msg.getFlag());
  57. requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));
  58. requestHeader.setReconsumeTimes(0);
  59. requestHeader.setUnitMode(this.isUnitMode());
  60. if (requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
  61. String reconsumeTimes = MessageAccessor.getReconsumeTime(msg);
  62. if (reconsumeTimes != null) {
  63. requestHeader.setReconsumeTimes(new Integer(reconsumeTimes));
  64. MessageAccessor.clearProperty(msg, MessageConst.PROPERTY_RECONSUME_TIME);
  65. }
  66. }
  67. SendResult sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(//
  68. brokerAddr,// 1
  69. mq.getBrokerName(),// 2
  70. msg,// 3
  71. requestHeader,// 4
  72. timeout,// 5
  73. communicationMode,// 6
  74. sendCallback// 7
  75. );
  76. if (this.hasSendMessageHook()) {
  77. context.setSendResult(sendResult);
  78. this.executeSendMessageHookAfter(context);
  79. }
  80. return sendResult;
  81. }
  82. catch (RemotingException e) {
  83. if (this.hasSendMessageHook()) {
  84. context.setException(e);
  85. this.executeSendMessageHookAfter(context);
  86. }
  87. throw e;
  88. }
  89. catch (MQBrokerException e) {
  90. if (this.hasSendMessageHook()) {
  91. context.setException(e);
  92. this.executeSendMessageHookAfter(context);
  93. }
  94. throw e;
  95. }
  96. catch (InterruptedException e) {
  97. if (this.hasSendMessageHook()) {
  98. context.setException(e);
  99. this.executeSendMessageHookAfter(context);
  100. }
  101. throw e;
  102. }
  103. finally {
  104. msg.setBody(prevBody);
  105. }
  106. }
  107. throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
  108. }

 

首先,根据当前的BorkerName从本地的Broker地址缓存中获取相应的地址,如果找不到,跟之前的方式一样,重新跟名称服务更新新的路由信息。

 

接下来根据之前的DefaultProducer配置类对具体的方式方式进行配置。

如果在一开始配置了高优先级队列,则在这里就会选择高优先级队列。

在这里给出一个sysFlag标志位。

之后进行压缩处理,如果所要发送消息的body部分超过了配置类需要压缩的大小。

  1. private boolean tryToCompressMessage(final Message msg) {
  2. byte[] body = msg.getBody();
  3. if (body != null) {
  4. if (body.length >= this.defaultMQProducer.getCompressMsgBodyOverHowmuch()) {
  5. try {
  6. byte[] data = UtilAll.compress(body, zipCompressLevel);
  7. if (data != null) {
  8. msg.setBody(data);
  9. return true;
  10. }
  11. }
  12. catch (IOException e) {
  13. log.error("tryToCompressMessage exception", e);
  14. log.warn(msg.toString());
  15. }
  16. }
  17. }
  18. return false;
  19. }

在压缩中,具体采用了zip压缩方式。

如果在此处的确采用了压缩,则给标志量低一位为1。

public final static int CompressedFlag = (0x1 << 0);

 

接下来,若果该消息属于事务消息,也会给相应的标志量赋值,这里暂时不展开。

 

在接下里,如果该生产者配置了相关的注册了chackForbiddenHook,则在这里将会走一遍所有的注册了的checkForbidden钩子保证本来配置被禁发的消息不会被发送出去。
类似的,在接下里如果跟之前的钩子一样的方式配置注册了sendMessageHook消息发送钩子,则会在这里遍历调用所有钩子的executesendMessageHookBefore()方法,相应的,在消息发送完毕之后也会  执行executeSendMessageHookAfter()方法。
之后根据之前得到的一系列发送消息的配置,来构造发送给Broker的请求头数据。
在一切准备就绪之后,调用客户端的API接口来实现消息的物理发送。
  1. SendResult sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(//
  2. brokerAddr,// 1
  3. mq.getBrokerName(),// 2
  4. msg,// 3
  5. requestHeader,// 4
  6. timeout,// 5
  7. communicationMode,// 6
  8. sendCallback// 7
  9. );

 

如果采用了ASYNC的异步发送模式,则这个最后一个参数就是在消息发送之后用来处理消息回复的类。

 

  1. public SendResult sendMessage(//
  2. final String addr,// 1
  3. final String brokerName,// 2
  4. final Message msg,// 3
  5. final SendMessageRequestHeader requestHeader,// 4
  6. final long timeoutMillis,// 5
  7. final CommunicationMode communicationMode,// 6
  8. final SendCallback sendCallback// 7
  9. ) throws RemotingException, MQBrokerException, InterruptedException {
  10. RemotingCommand request = null;
  11. if (sendSmartMsg) {
  12. SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
  13. request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
  14. }
  15. else {
  16. request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
  17. }
  18. request.setBody(msg.getBody());
  19. switch (communicationMode) {
  20. case ONEWAY:
  21. this.remotingClient.invokeOneway(addr, request, timeoutMillis);
  22. return null;
  23. case ASYNC:
  24. this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
  25. return null;
  26. case SYNC:
  27. return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
  28. default:
  29. assert false;
  30. break;
  31. }
  32. return null;
  33. }

 

以异步方式为例

 

  1. private void sendMessageAsync(//
  2. final String addr,//
  3. final String brokerName,//
  4. final Message msg,//
  5. final long timeoutMillis,//
  6. final RemotingCommand request,//
  7. final SendCallback sendCallback//
  8. ) throws RemotingException, InterruptedException {
  9. this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
  10. @Override
  11. public void operationComplete(ResponseFuture responseFuture) {
  12. if (null == sendCallback)
  13. return;
  14. RemotingCommand response = responseFuture.getResponseCommand();
  15. if (response != null) {
  16. try {
  17. SendResult sendResult = MQClientAPIImpl.this.processSendResponse(brokerName, msg, response);
  18. assert sendResult != null;
  19. sendCallback.onSuccess(sendResult);
  20. }
  21. catch (Exception e) {
  22. sendCallback.onException(e);
  23. }
  24. }
  25. else {
  26. if (!responseFuture.isSendRequestOK()) {
  27. sendCallback.onException(new MQClientException("send request failed", responseFuture.getCause()));
  28. }
  29. else if (responseFuture.isTimeout()) {
  30. sendCallback.onException(new MQClientException("wait response timeout " + responseFuture.getTimeoutMillis() + "ms",
  31. responseFuture.getCause()));
  32. }
  33. else {
  34. sendCallback.onException(new MQClientException("unknow reseaon", responseFuture.getCause()));
  35. }
  36. }
  37. }
  38. });
  39. }
在这里会根据传入的SendCallBack对象生成相应的responseFuture任务类交由netty客户端来处理。
  1. public void invokeAsyncImpl(final Channel channel, final RemotingCommand request,
  2. final long timeoutMillis, final InvokeCallback invokeCallback) throws InterruptedException,
  3. RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException {
  4. boolean acquired = this.semaphoreAsync.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS);
  5. if (acquired) {
  6. final SemaphoreReleaseOnlyOnce once = new SemaphoreReleaseOnlyOnce(this.semaphoreAsync);
  7. final ResponseFuture responseFuture =
  8. new ResponseFuture(request.getOpaque(), timeoutMillis, invokeCallback, once);
  9. this.responseTable.put(request.getOpaque(), responseFuture);
  10. try {
  11. channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
  12. @Override
  13. public void operationComplete(ChannelFuture f) throws Exception {
  14. if (f.isSuccess()) {
  15. responseFuture.setSendRequestOK(true);
  16. return;
  17. }
  18. else {
  19. responseFuture.setSendRequestOK(false);
  20. }
  21. responseFuture.putResponse(null);
  22. responseTable.remove(request.getOpaque());
  23. try {
  24. responseFuture.executeInvokeCallback();
  25. }
  26. catch (Throwable e) {
  27. plog.warn("excute callback in writeAndFlush addListener, and callback throw", e);
  28. }
  29. finally {
  30. responseFuture.release();
  31. }
  32. plog.warn("send a request command to channel <{}> failed.",
  33. RemotingHelper.parseChannelRemoteAddr(channel));
  34. plog.warn(request.toString());
  35. }
  36. });
  37. }
  38. catch (Exception e) {
  39. responseFuture.release();
  40. plog.warn(
  41. "send a request command to channel <" + RemotingHelper.parseChannelRemoteAddr(channel)
  42. + "> Exception", e);
  43. throw new RemotingSendRequestException(RemotingHelper.parseChannelRemoteAddr(channel), e);
  44. }
  45. }
  46. else {
  47. if (timeoutMillis <= 0) {
  48. throw new RemotingTooMuchRequestException("invokeAsyncImpl invoke too fast");
  49. }
  50. else {
  51. String info =
  52. String
  53. .format(
  54. "invokeAsyncImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", //
  55. timeoutMillis,//
  56. this.semaphoreAsync.getQueueLength(),//
  57. this.semaphoreAsync.availablePermits()//
  58. );
  59. plog.warn(info);
  60. plog.warn(request.toString());
  61. throw new RemotingTimeoutException(info);
  62. }
  63. }
  64. }

 

可以看到,生成的responseFuture被netty远程客户端管理在map里,动态实现了在收到消息回复之后调用的operationCompleted()方法,将根据消息结果的异步返回调用相应的鄂onSuccess()或者onException()方法,来完成ASYNC异步的目的。

 

在这里,如果是异步的将直接返回,由上面的方式完成之后消息回复的处理。到这里RockerMQ异步发送的步骤正式宣告结束。
而ONEWAY单向消息发送模式在发送完毕消息后马上会结束,并不会管消息发送的结果。

如果是SYNC同步消息发送模式,如果消息发送失败,则会选择另一个BrokerName来尝试继续发送,直到retry次数用尽。当然顾名思义,在同步消息模式的消息发送后,将会等待结果并调用客户端API接口实现的processSendResponse()方法来处理结果。


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/256919
推荐阅读
相关标签
  

闽ICP备14008679号