org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader Java Examples

The following examples show how to use org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader. 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: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public PullResult pullMessage(
    final String addr,
    final PullMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final PullCallback pullCallback
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);

    switch (communicationMode) {
        case ONEWAY:
            assert false;
            return null;
        case ASYNC:
            this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
            return null;
        case SYNC:
            return this.pullMessageSync(addr, request, timeoutMillis);
        default:
            assert false;
            break;
    }

    return null;
}
 
Example #2
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<>());
}
 
Example #3
Source File: DefaultMQPullConsumerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #4
Source File: DeFiPullMessageProcessor.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
private void handleProcessResult(final PullMessageRequestHeader requestHeader, final RemotingCommand response) {
    if (response != null) {
        switch (response.getCode()) {
            case SUBSCRIPTION_GROUP_NOT_EXIST:
            case NO_PERMISSION:
            case SUBSCRIPTION_NOT_EXIST:
            case SUBSCRIPTION_NOT_LATEST:
                response.setCode(PULL_NOT_FOUND);
                final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.readCustomHeader();
                responseHeader.setMinOffset(this.deFiBrokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()));
                responseHeader.setMaxOffset(this.deFiBrokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId()));
                responseHeader.setNextBeginOffset(requestHeader.getQueueOffset());
                responseHeader.setSuggestWhichBrokerId(MixAll.MASTER_ID);
                break;
        }
    }
}
 
Example #5
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #6
Source File: DeFiPullMessageProcessor.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Override
public RemotingCommand processRequest(final ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    RemotingCommand response = super.processRequest(ctx, request);

    final PullMessageRequestHeader requestHeader =
        (PullMessageRequestHeader) request.decodeCommandCustomHeader(PullMessageRequestHeader.class);
    ConsumerGroupInfo consumerGroupInfo = deFiBrokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup());
    if (consumerGroupInfo != null) {
        ClientChannelInfo clientChannelInfo = consumerGroupInfo.getChannelInfoTable().get(ctx.channel());
        if (clientChannelInfo != null) {
            String clientId = clientChannelInfo.getClientId();
            deFiBrokerController.getClientRebalanceResultManager().updateListenMap(requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId(), clientId);
        }
    }
    handleProcessResult(requestHeader, response);
    return response;
}
 
Example #7
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public PullResult pullMessage(
    final String addr,
    final PullMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final PullCallback pullCallback
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);

    switch (communicationMode) {
        case ONEWAY:
            assert false;
            return null;
        case ASYNC:
            this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
            return null;
        case SYNC:
            return this.pullMessageSync(addr, request, timeoutMillis);
        default:
            assert false;
            break;
    }

    return null;
}
 
Example #8
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public PullResult pullMessage(
    final String addr,
    final PullMessageRequestHeader requestHeader,
    final long timeoutMillis,
    final CommunicationMode communicationMode,
    final PullCallback pullCallback
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);

    switch (communicationMode) {
        case ONEWAY:
            assert false;
            return null;
        case ASYNC:
            this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
            return null;
        case SYNC:
            return this.pullMessageSync(addr, request, timeoutMillis);
        default:
            assert false;
            break;
    }

    return null;
}
 
Example #9
Source File: DefaultMQPullConsumerTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #10
Source File: MQClientAPIImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public PullResult pullMessage(//
    final String addr, //
    final PullMessageRequestHeader requestHeader, //
    final long timeoutMillis, //
    final CommunicationMode communicationMode, //
    final PullCallback pullCallback//
) throws RemotingException, MQBrokerException, InterruptedException {
	//发送PULL_MESSAGE类型的请求
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);

    switch (communicationMode) {
        case ONEWAY:
            assert false;
            return null;
        case ASYNC:
            this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
            return null;
        case SYNC:
            return this.pullMessageSync(addr, request, timeoutMillis);
        default:
            assert false;
            break;
    }

    return null;
}
 
Example #11
Source File: DefaultMQPullConsumerTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #12
Source File: DefaultMQPullConsumerTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<>());
}
 
Example #13
Source File: DefaultMQPullConsumerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #14
Source File: DefaultMQPullConsumerTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testPullMessage_Success() throws Exception {
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult).isNotNull();
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
    assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
    assertThat(pullResult.getMinOffset()).isEqualTo(123);
    assertThat(pullResult.getMaxOffset()).isEqualTo(2048);
    assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
}
 
Example #15
Source File: DefaultMQConsumerWithTraceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
    List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #16
Source File: PullMessageProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
private RemotingCommand createPullMsgCommand(int requestCode) {
    PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
    requestHeader.setCommitOffset(123L);
    requestHeader.setConsumerGroup(group);
    requestHeader.setMaxMsgNums(100);
    requestHeader.setQueueId(1);
    requestHeader.setQueueOffset(456L);
    requestHeader.setSubscription("*");
    requestHeader.setTopic(topic);
    requestHeader.setSysFlag(0);
    requestHeader.setSubVersion(100L);
    RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader);
    request.makeCustomHeaderToNet();
    return request;
}
 
Example #17
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPullMessage_NotFound() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList<MessageExt>());
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.NO_NEW_MSG);
}
 
Example #18
Source File: DefaultMQPushConsumerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
    List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #19
Source File: DefaultLitePullConsumerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
    List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #20
Source File: DefaultMQPushConsumerTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #21
Source File: DefaultMQPullConsumerTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testPullMessage_NotFound() throws Exception{
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList<MessageExt>());
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.NO_NEW_MSG);
}
 
Example #22
Source File: DefaultMQPushConsumerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #23
Source File: ConsumeMessageConcurrentlyServiceTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
                                       List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #24
Source File: PullMessageProcessorTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
private RemotingCommand createPullMsgCommand(int requestCode) {
    PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
    requestHeader.setCommitOffset(123L);
    requestHeader.setConsumerGroup(group);
    requestHeader.setMaxMsgNums(100);
    requestHeader.setQueueId(1);
    requestHeader.setQueueOffset(456L);
    requestHeader.setSubscription("*");
    requestHeader.setTopic(topic);
    requestHeader.setSysFlag(0);
    requestHeader.setSubVersion(100L);
    RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader);
    request.makeCustomHeaderToNet();
    return request;
}
 
Example #25
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private RemotingCommand createPullMsgCommand(int requestCode) {
    PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
    requestHeader.setCommitOffset(123L);
    requestHeader.setConsumerGroup(group);
    requestHeader.setMaxMsgNums(100);
    requestHeader.setQueueId(1);
    requestHeader.setQueueOffset(456L);
    requestHeader.setSubscription("*");
    requestHeader.setTopic(topic);
    requestHeader.setSysFlag(0);
    requestHeader.setSubVersion(100L);
    RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader);
    request.makeCustomHeaderToNet();
    return request;
}
 
Example #26
Source File: DefaultMQPullConsumerTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testPullMessage_NotFound() throws Exception {
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList<MessageExt>());
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.NO_NEW_MSG);
}
 
Example #27
Source File: DefaultMQPushConsumerTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
    List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
Example #28
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private RemotingCommand createPullMsgCommand(int requestCode) {
    PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
    requestHeader.setCommitOffset(123L);
    requestHeader.setConsumerGroup(group);
    requestHeader.setMaxMsgNums(100);
    requestHeader.setQueueId(1);
    requestHeader.setQueueOffset(456L);
    requestHeader.setSubscription("*");
    requestHeader.setTopic(topic);
    requestHeader.setSysFlag(0);
    requestHeader.setSubVersion(100L);
    RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader);
    request.makeCustomHeaderToNet();
    return request;
}
 
Example #29
Source File: DefaultMQPullConsumerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testPullMessage_NotFound() throws Exception{
    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            PullMessageRequestHeader requestHeader = mock.getArgument(1);
            return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList<MessageExt>());
        }
    }).when(mQClientAPIImpl).pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult = pullConsumer.pull(messageQueue, "*", 1024, 3);
    assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.NO_NEW_MSG);
}
 
Example #30
Source File: PullMessageProcessorTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private RemotingCommand createPullMsgCommand(int requestCode) {
    PullMessageRequestHeader requestHeader = new PullMessageRequestHeader();
    requestHeader.setCommitOffset(123L);
    requestHeader.setConsumerGroup(group);
    requestHeader.setMaxMsgNums(100);
    requestHeader.setQueueId(1);
    requestHeader.setQueueOffset(456L);
    requestHeader.setSubscription("*");
    requestHeader.setTopic(topic);
    requestHeader.setSysFlag(0);
    requestHeader.setSubVersion(100L);
    RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestHeader);
    request.makeCustomHeaderToNet();
    return request;
}