org.apache.rocketmq.client.producer.SendStatus Java Examples

The following examples show how to use org.apache.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: DefaultRocketMQListenerContainer.java    From rocketmq-spring with Apache License 2.0 6 votes vote down vote up
private void handleMessage(
    MessageExt messageExt) throws MQClientException, RemotingException, InterruptedException {
    if (rocketMQListener != null) {
        rocketMQListener.onMessage(doConvertMessage(messageExt));
    } else if (rocketMQReplyListener != null) {
        Object replyContent = rocketMQReplyListener.onMessage(doConvertMessage(messageExt));
        Message<?> message = MessageBuilder.withPayload(replyContent).build();

        org.apache.rocketmq.common.message.Message replyMessage = MessageUtil.createReplyMessage(messageExt, convertToBytes(message));
        consumer.getDefaultMQPushConsumerImpl().getmQClientFactory().getDefaultMQProducer().send(replyMessage, new SendCallback() {
            @Override public void onSuccess(SendResult sendResult) {
                if (sendResult.getSendStatus() != SendStatus.SEND_OK) {
                    log.error("Consumer replies message failed. SendStatus: {}", sendResult.getSendStatus());
                } else {
                    log.info("Consumer replies message success.");
                }
            }

            @Override public void onException(Throwable e) {
                log.error("Consumer replies message failed. error: {}", e.getLocalizedMessage());
            }
        });
    }
}
 
Example #2
Source File: BatchSendIT.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #3
Source File: MQClientAPIImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #4
Source File: OnSuccessInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: SendMessageCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, NoSuchFieldException, IllegalAccessException {

    DefaultMQProducer defaultMQProducer = mock(DefaultMQProducer.class);
    SendResult sendResult = new SendResult();
    sendResult.setMessageQueue(new MessageQueue());
    sendResult.getMessageQueue().setBrokerName("broker1");
    sendResult.getMessageQueue().setQueueId(1);
    sendResult.setSendStatus(SendStatus.SEND_OK);
    sendResult.setMsgId("fgwejigherughwueyutyu4t4343t43");

    when(defaultMQProducer.send(any(Message.class))).thenReturn(sendResult);
    when(defaultMQProducer.send(any(Message.class), any(MessageQueue.class))).thenReturn(sendResult);

    Field producerField = SendMessageCommand.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    producerField.set(sendMessageCommand, defaultMQProducer);
}
 
Example #6
Source File: ProducerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #7
Source File: MQClientAPIImplTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #8
Source File: ProducerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #9
Source File: MQClientAPIImplTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #10
Source File: BatchSendIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #11
Source File: BatchSendIT.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #12
Source File: SendMessageCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, NoSuchFieldException, IllegalAccessException {

    DefaultMQProducer defaultMQProducer = mock(DefaultMQProducer.class);
    SendResult sendResult = new SendResult();
    sendResult.setMessageQueue(new MessageQueue());
    sendResult.getMessageQueue().setBrokerName("broker1");
    sendResult.getMessageQueue().setQueueId(1);
    sendResult.setSendStatus(SendStatus.SEND_OK);
    sendResult.setMsgId("fgwejigherughwueyutyu4t4343t43");

    when(defaultMQProducer.send(any(Message.class))).thenReturn(sendResult);
    when(defaultMQProducer.send(any(Message.class), any(MessageQueue.class))).thenReturn(sendResult);

    Field producerField = SendMessageCommand.class.getDeclaredField("producer");
    producerField.setAccessible(true);
    producerField.set(sendMessageCommand, defaultMQProducer);
}
 
Example #13
Source File: MQClientAPIImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #14
Source File: MQClientAPIImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            RemotingCommand request = mock.getArgument(1);
            return createSuccessResponse(request);
        }
    }).when(remotingClient).invokeSync(anyString(), any(RemotingCommand.class), anyLong());

    SendMessageRequestHeader requestHeader = createSendMessageRequestHeader();

    SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, requestHeader,
        3 * 1000, CommunicationMode.SYNC, new SendMessageContext(), defaultMQProducerImpl);

    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
    assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
    assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
    assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
}
 
Example #15
Source File: BatchSendIT.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #16
Source File: ProducerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.sysHeaders().put(Message.BuiltinKeys.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID), e);
    }
}
 
Example #17
Source File: ProducerImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private SendResult send(final Message message, long timeout) {
    checkMessageType(message);
    org.apache.rocketmq.common.message.Message rmqMessage = msgConvert((BytesMessage) message);
    try {
        org.apache.rocketmq.client.producer.SendResult rmqResult = this.rocketmqProducer.send(rmqMessage, timeout);
        if (!rmqResult.getSendStatus().equals(SendStatus.SEND_OK)) {
            log.error(String.format("Send message to RocketMQ failed, %s", message));
            throw new OMSRuntimeException("-1", "Send message to RocketMQ broker failed.");
        }
        message.headers().put(MessageHeader.MESSAGE_ID, rmqResult.getMsgId());
        return OMSUtil.sendResultConvert(rmqResult);
    } catch (Exception e) {
        log.error(String.format("Send message to RocketMQ failed, %s", message), e);
        throw checkProducerException(rmqMessage.getTopic(), message.headers().getString(MessageHeader.MESSAGE_ID), e);
    }
}
 
Example #18
Source File: BatchSendIT.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchSend_ViewMessage() throws Exception {
    List<Message> messageList = new ArrayList<>();
    int batchNum = 100;
    for (int i = 0; i < batchNum; i++) {
        messageList.add(new Message(topic, RandomUtils.getStringByUUID().getBytes()));
    }

    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    for (int i = 0; i < 3; i++) {
        producer.viewMessage(offsetIds[random.nextInt(batchNum)]);
    }
    for (int i = 0; i < 3; i++) {
        producer.viewMessage(topic, msgIds[random.nextInt(batchNum)]);
    }
}
 
Example #19
Source File: MessageExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testProducerSmoke() {
    Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }

    assertThat(sendResult).isNotEqualTo(null);
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
Example #20
Source File: SequenceProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_WithCommit() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setMsgId("TestMsgID");
    sendResult.setSendStatus(SendStatus.SEND_OK);
    when(rocketmqProducer.send(ArgumentMatchers.<Message>anyList())).thenReturn(sendResult);
    when(rocketmqProducer.getMaxMessageSize()).thenReturn(1024);
    final BytesMessage message = producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] {'a'});
    producer.send(message);
    producer.commit();
    assertThat(message.headers().getString(MessageHeader.MESSAGE_ID)).isEqualTo("TestMsgID");
}
 
Example #21
Source File: RMQNormalProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public SendResult send(Object msg, Object orderKey) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    Message metaqMsg = (Message) msg;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(metaqMsg);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(metaqMsg.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(metaqMsg.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}
 
Example #22
Source File: ProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend_Not_OK() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    SendResult sendResult = new SendResult();
    sendResult.setSendStatus(SendStatus.FLUSH_DISK_TIMEOUT);

    when(rocketmqProducer.send(any(Message.class), anyLong())).thenReturn(sendResult);
    try {
        producer.send(producer.createBytesMessageToTopic("HELLO_TOPIC", new byte[] {'a'}));
        failBecauseExceptionWasNotThrown(OMSRuntimeException.class);
    } catch (Exception e) {
        assertThat(e).hasMessageContaining("Send message to RocketMQ broker failed.");
    }
}
 
Example #23
Source File: RMQNormalProducer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public SendResult send(Object msg, Object orderKey) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    Message message = (Message) msg;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(message);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(message.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(message.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}
 
Example #24
Source File: RMQNormalProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ResultWrapper sendMQ(Message msg, MessageQueue mq) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(msg, mq);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(msg.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}
 
Example #25
Source File: MessageExceptionIT.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendLess128kMsg() {
    Message msg = new Message(topic, RandomUtils.getStringWithNumber(128 * 1024).getBytes());
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
Example #26
Source File: MessageExceptionIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendLess128kMsg() {
    Message msg = new Message(topic, RandomUtils.getStringWithNumber(128 * 1024).getBytes());
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
Example #27
Source File: RMQNormalProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public SendResult send(Object msg, Object orderKey) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    Message metaqMsg = (Message) msg;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(metaqMsg);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(metaqMsg.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(metaqMsg.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}
 
Example #28
Source File: RMQNormalProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public SendResult sendMQ(Message msg, MessageQueue mq) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(msg, mq);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(msg.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(msg.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}
 
Example #29
Source File: ChinaPropIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * @since version3.4.6
 */
@Test
public void testSend10kChinaPropMsg() {

    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
Example #30
Source File: RMQNormalProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ResultWrapper send(Object msg, Object orderKey) {
    org.apache.rocketmq.client.producer.SendResult metaqResult = null;
    Message message = (Message) msg;
    try {
        long start = System.currentTimeMillis();
        metaqResult = producer.send(message);
        this.msgRTs.addData(System.currentTimeMillis() - start);
        if (isDebug) {
            logger.info(metaqResult);
        }
        sendResult.setMsgId(metaqResult.getMsgId());
        sendResult.setSendResult(metaqResult.getSendStatus().equals(SendStatus.SEND_OK));
        sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName());
        msgBodys.addData(new String(message.getBody()));
        originMsgs.addData(msg);
        originMsgIndex.put(new String(message.getBody()), metaqResult);
    } catch (Exception e) {
        if (isDebug) {
            e.printStackTrace();
        }

        sendResult.setSendResult(false);
        sendResult.setSendException(e);
        errorMsgs.addData(msg);
    }

    return sendResult;
}