com.alibaba.rocketmq.client.producer.SendStatus Java Examples
The following examples show how to use
com.alibaba.rocketmq.client.producer.SendStatus.
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: OnSuccessInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testOnSuccessWithErrorStatus() throws Throwable { when(sendResult.getSendStatus()).thenReturn(SendStatus.FLUSH_SLAVE_TIMEOUT); successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null); assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0); List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment); assertThat(spans.size(), is(1)); AbstractTracingSpan successSpan = spans.get(0); SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ_PRODUCER); SpanAssert.assertOccurException(successSpan, true); }
Example #2
Source File: RocketMQSender.java From easyooo-framework with Apache License 2.0 | 6 votes |
@Override public boolean send(Message data) throws Exception { if(data == null){ return false; } try{ SendResult sr = producer.send(data); if(sr.getSendStatus() != SendStatus.SEND_OK){ logger.warn(String.format("Message(%s) has been sent successfully, but send status is %s.", data.getTopic(), sr.getSendStatus())); } }catch(Exception e){ if(needFaultTolerant){ putInErrorQueue(data); } throw e; } return true; }
Example #3
Source File: RocketMqTracingCollector.java From dubbo-plus with Apache License 2.0 | 5 votes |
@Override public void push(List<Span> spanList) { byte[] bytes = JSON.toJSONBytes(spanList); Message message = new Message(DstConstants.ROCKET_MQ_TOPIC,bytes); try { SendResult sendResult = defaultMQProducer.send(message); if(sendResult.getSendStatus()!= SendStatus.SEND_OK){ logger.error("send mq message return ["+sendResult.getSendStatus()+"]"); } } catch (Exception e) { logger.error("fail to send message.",e); } }
Example #4
Source File: OnSuccessInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField(); AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback"); activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER); SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus(); if (sendStatus != SendStatus.SEND_OK) { activeSpan.errorOccurred(); Tags.STATUS_CODE.set(activeSpan, sendStatus.name()); } ContextManager.continued(enhanceInfo.getContextSnapshot()); }
Example #5
Source File: OnSuccessInterceptorTest.java From skywalking with Apache License 2.0 | 5 votes |
@Before public void setUp() { successInterceptor = new OnSuccessInterceptor(); enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot); when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo); when(sendResult.getSendStatus()).thenReturn(SendStatus.SEND_OK); }
Example #6
Source File: MqProducer.java From RocketMqCurrencyBoot with Apache License 2.0 | 4 votes |
/** * 发送数据到MQ方法 * * @param Topic 队列名称 * @param Tags 标签名称 * @param body 发送的数据 推荐 JSOM 或者 XML 结构 * @param Encoding 数据编码格式 默认UTF-8 * @return 响应信息进行了内部处理 确认已经保存到 MQ 并且 日志已经记录 只要值不是NULL 就是成功发送 * @throws UnsupportedEncodingException 转换字符集出错 请检查是否可以转换 */ public SendResult send(String Topic, String Tags, String body, String Encoding) throws UnsupportedEncodingException { String loggerString = MessageFormat.format( "将要发送到Mq的数据 Topic={0} Tags={1} body={2} Encoding={3} ", Topic, Tags, body, Encoding); if (Encoding == null || "".equals(Encoding)) { Encoding = "UTF-8"; } if (Tags == null || "".equals(Tags)) { Tags = "*"; } LOGGER.info(loggerString); Message me = new Message(); // 标示 me.setTopic(Topic); // 标签 me.setTags(Tags); // 内容 me.setBody(body.getBytes(Encoding)); // 发送信息到MQ SendResult 是当前发送的状态 官方说 不出异常 就是成功 SendResult sendResult = null; try { if (producer instanceof TransactionMQProducer) { sendResult = ((TransactionMQProducer) producer).sendMessageInTransaction(me, transactionExecuter, null); } else { sendResult = ((DefaultMQProducer) producer).send(me); } } catch (Exception e) { LOGGER.error(" 发送 数据给MQ出现异常 " + loggerString, e); } // 当消息发送失败时如何处理 getSendStatus 获取发送的状态 if (sendResult == null || sendResult.getSendStatus() != SendStatus.SEND_OK) { LOGGER.info(loggerString + "发送消息失败" + " MQ状态值 SendResult=" + sendResult); sendResult = null; } LOGGER.info("发送到MQ成功" + sendResult); return sendResult; }
Example #7
Source File: RocketMQProducerService.java From onetwo with Apache License 2.0 | 4 votes |
public void sendBytesMessage(String topic, String tags, byte[] body){ SendResult result = sendBytesMessage(topic, tags, body, errorHandler); if(result.getSendStatus()!=SendStatus.SEND_OK){ throw BaseException.formatMessage("发送消息失败!(%s)", result.getSendStatus()); } }
Example #8
Source File: RocketMQProducerService.java From onetwo with Apache License 2.0 | 4 votes |
public void sendRawMessage(Message message){ SendResult result = sendRawMessage(message, errorHandler); if(result.getSendStatus()!=SendStatus.SEND_OK){ throw BaseException.formatMessage("发送消息失败!(%s)", result.getSendStatus()); } }