use of org.apache.rocketmq.common.message.MessageClientExt in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class QueryMsgByIdIT method testQueryMsg.
@Test
public void testQueryMsg() {
int msgSize = 20;
producer.send(msgSize);
Assert.assertEquals("Not all are sent", msgSize, producer.getAllUndupMsgBody().size());
consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
Assert.assertEquals("Not all are consumed", 0, VerifyUtils.verify(producer.getAllMsgBody(), consumer.getListner().getAllMsgBody()));
MessageExt recvMsg = (MessageExt) consumer.getListner().getFirstMsg();
MessageExt queryMsg = null;
try {
TestUtils.waitForMoment(3000);
queryMsg = producer.getProducer().viewMessage(((MessageClientExt) recvMsg).getOffsetMsgId());
} catch (Exception e) {
}
assertThat(queryMsg).isNotNull();
assertThat(new String(queryMsg.getBody())).isEqualTo(new String(recvMsg.getBody()));
}
use of org.apache.rocketmq.common.message.MessageClientExt in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class QueryMsgByIdSubCommand method printMsg.
public static void printMsg(final DefaultMQAdminExt admin, final MessageExt msg) throws IOException {
if (msg == null) {
System.out.printf("%nMessage not found!");
return;
}
// 存储消息 body 到指定路径
String bodyTmpFilePath = createBodyFile(msg);
String msgId = msg.getMsgId();
if (msg instanceof MessageClientExt) {
msgId = ((MessageClientExt) msg).getOffsetMsgId();
}
System.out.printf("%-20s %s%n", "OffsetID:", msgId);
System.out.printf("%-20s %s%n", "OffsetID:", msgId);
System.out.printf("%-20s %s%n", "Topic:", msg.getTopic());
System.out.printf("%-20s %s%n", "Tags:", "[" + msg.getTags() + "]");
System.out.printf("%-20s %s%n", "Keys:", "[" + msg.getKeys() + "]");
System.out.printf("%-20s %d%n", "Queue ID:", msg.getQueueId());
System.out.printf("%-20s %d%n", "Queue Offset:", msg.getQueueOffset());
System.out.printf("%-20s %d%n", "CommitLog Offset:", msg.getCommitLogOffset());
System.out.printf("%-20s %d%n", "Reconsume Times:", msg.getReconsumeTimes());
System.out.printf("%-20s %s%n", "Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()));
System.out.printf("%-20s %s%n", "Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()));
System.out.printf("%-20s %s%n", "Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost()));
System.out.printf("%-20s %s%n", "Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()));
System.out.printf("%-20s %d%n", "System Flag:", msg.getSysFlag());
System.out.printf("%-20s %s%n", "Properties:", msg.getProperties() != null ? msg.getProperties().toString() : "");
System.out.printf("%-20s %s%n", "Message Body Path:", bodyTmpFilePath);
try {
List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
if (mtdList.isEmpty()) {
System.out.printf("%n%nWARN: No Consumer");
} else {
System.out.printf("%n%n");
for (MessageTrack mt : mtdList) {
System.out.printf("%s", mt);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.rocketmq.common.message.MessageClientExt in project rocketmq by apache.
the class DefaultMQPushConsumerTest method init.
@Before
public void init() throws Exception {
consumerGroup = "FooBarGroup" + System.currentTimeMillis();
pushConsumer = new DefaultMQPushConsumer(consumerGroup);
pushConsumer.setNamesrvAddr("127.0.0.1:9876");
pushConsumer.setPullInterval(60 * 1000);
pushConsumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
return null;
}
});
DefaultMQPushConsumerImpl pushConsumerImpl = pushConsumer.getDefaultMQPushConsumerImpl();
rebalancePushImpl = spy(new RebalancePushImpl(pushConsumer.getDefaultMQPushConsumerImpl()));
Field field = DefaultMQPushConsumerImpl.class.getDeclaredField("rebalanceImpl");
field.setAccessible(true);
field.set(pushConsumerImpl, rebalancePushImpl);
pushConsumer.subscribe(topic, "*");
pushConsumer.start();
mQClientFactory = spy(pushConsumerImpl.getmQClientFactory());
field = DefaultMQPushConsumerImpl.class.getDeclaredField("mQClientFactory");
field.setAccessible(true);
field.set(pushConsumerImpl, mQClientFactory);
field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
field.setAccessible(true);
field.set(mQClientFactory, mQClientAPIImpl);
pullAPIWrapper = spy(new PullAPIWrapper(mQClientFactory, consumerGroup, false));
field = DefaultMQPushConsumerImpl.class.getDeclaredField("pullAPIWrapper");
field.setAccessible(true);
field.set(pushConsumerImpl, pullAPIWrapper);
pushConsumer.getDefaultMQPushConsumerImpl().getRebalanceImpl().setmQClientFactory(mQClientFactory);
mQClientFactory.registerConsumer(consumerGroup, pushConsumerImpl);
when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock mock) throws Throwable {
PullMessageRequestHeader requestHeader = mock.getArgument(1);
MessageClientExt messageClientExt = new MessageClientExt();
messageClientExt.setTopic(topic);
messageClientExt.setQueueId(0);
messageClientExt.setMsgId("123");
messageClientExt.setBody(new byte[] { 'a' });
messageClientExt.setOffsetMsgId("234");
messageClientExt.setBornHost(new InetSocketAddress(8080));
messageClientExt.setStoreHost(new InetSocketAddress(8080));
PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.<MessageExt>singletonList(messageClientExt));
((PullCallback) mock.getArgument(4)).onSuccess(pullResult);
return pullResult;
}
});
doReturn(new FindBrokerResult("127.0.0.1:10911", false)).when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
doReturn(Collections.singletonList(mQClientFactory.getClientId())).when(mQClientFactory).findConsumerIdList(anyString(), anyString());
Set<MessageQueue> messageQueueSet = new HashSet<MessageQueue>();
messageQueueSet.add(createPullRequest().getMessageQueue());
pushConsumer.getDefaultMQPushConsumerImpl().updateTopicSubscribeInfo(topic, messageQueueSet);
doReturn(123L).when(rebalancePushImpl).computePullFromWhere(any(MessageQueue.class));
}
use of org.apache.rocketmq.common.message.MessageClientExt in project rocketmq by apache.
the class QueryMsgByIdSubCommand method printMsg.
public static void printMsg(final DefaultMQAdminExt admin, final MessageExt msg) throws IOException {
if (msg == null) {
System.out.printf("%nMessage not found!");
return;
}
String bodyTmpFilePath = createBodyFile(msg);
String msgId = msg.getMsgId();
if (msg instanceof MessageClientExt) {
msgId = ((MessageClientExt) msg).getOffsetMsgId();
}
System.out.printf("%-20s %s%n", "OffsetID:", msgId);
System.out.printf("%-20s %s%n", "OffsetID:", msgId);
System.out.printf("%-20s %s%n", "Topic:", msg.getTopic());
System.out.printf("%-20s %s%n", "Tags:", "[" + msg.getTags() + "]");
System.out.printf("%-20s %s%n", "Keys:", "[" + msg.getKeys() + "]");
System.out.printf("%-20s %d%n", "Queue ID:", msg.getQueueId());
System.out.printf("%-20s %d%n", "Queue Offset:", msg.getQueueOffset());
System.out.printf("%-20s %d%n", "CommitLog Offset:", msg.getCommitLogOffset());
System.out.printf("%-20s %d%n", "Reconsume Times:", msg.getReconsumeTimes());
System.out.printf("%-20s %s%n", "Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()));
System.out.printf("%-20s %s%n", "Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()));
System.out.printf("%-20s %s%n", "Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost()));
System.out.printf("%-20s %s%n", "Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()));
System.out.printf("%-20s %d%n", "System Flag:", msg.getSysFlag());
System.out.printf("%-20s %s%n", "Properties:", msg.getProperties() != null ? msg.getProperties().toString() : "");
System.out.printf("%-20s %s%n", "Message Body Path:", bodyTmpFilePath);
try {
List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
if (mtdList.isEmpty()) {
System.out.printf("%n%nWARN: No Consumer");
} else {
System.out.printf("%n%n");
for (MessageTrack mt : mtdList) {
System.out.printf("%s", mt);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.rocketmq.common.message.MessageClientExt in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class DefaultMQPushConsumerTest method init.
@Before
public void init() throws Exception {
consumerGroup = "FooBarGroup" + System.currentTimeMillis();
pushConsumer = new DefaultMQPushConsumer(consumerGroup);
pushConsumer.setNamesrvAddr("127.0.0.1:9876");
pushConsumer.setPullInterval(60 * 1000);
pushConsumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
return null;
}
});
DefaultMQPushConsumerImpl pushConsumerImpl = pushConsumer.getDefaultMQPushConsumerImpl();
rebalancePushImpl = spy(new RebalancePushImpl(pushConsumer.getDefaultMQPushConsumerImpl()));
Field field = DefaultMQPushConsumerImpl.class.getDeclaredField("rebalanceImpl");
field.setAccessible(true);
field.set(pushConsumerImpl, rebalancePushImpl);
pushConsumer.subscribe(topic, "*");
pushConsumer.start();
mQClientFactory = spy(pushConsumerImpl.getmQClientFactory());
field = DefaultMQPushConsumerImpl.class.getDeclaredField("mQClientFactory");
field.setAccessible(true);
field.set(pushConsumerImpl, mQClientFactory);
field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
field.setAccessible(true);
field.set(mQClientFactory, mQClientAPIImpl);
pullAPIWrapper = spy(new PullAPIWrapper(mQClientFactory, consumerGroup, false));
field = DefaultMQPushConsumerImpl.class.getDeclaredField("pullAPIWrapper");
field.setAccessible(true);
field.set(pushConsumerImpl, pullAPIWrapper);
pushConsumer.getDefaultMQPushConsumerImpl().getRebalanceImpl().setmQClientFactory(mQClientFactory);
mQClientFactory.registerConsumer(consumerGroup, pushConsumerImpl);
when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock mock) throws Throwable {
PullMessageRequestHeader requestHeader = mock.getArgument(1);
MessageClientExt messageClientExt = new MessageClientExt();
messageClientExt.setTopic(topic);
messageClientExt.setQueueId(0);
messageClientExt.setMsgId("123");
messageClientExt.setBody(new byte[] { 'a' });
messageClientExt.setOffsetMsgId("234");
messageClientExt.setBornHost(new InetSocketAddress(8080));
messageClientExt.setStoreHost(new InetSocketAddress(8080));
PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.<MessageExt>singletonList(messageClientExt));
((PullCallback) mock.getArgument(4)).onSuccess(pullResult);
return pullResult;
}
});
doReturn(new FindBrokerResult("127.0.0.1:10911", false)).when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
doReturn(Collections.singletonList(mQClientFactory.getClientId())).when(mQClientFactory).findConsumerIdList(anyString(), anyString());
Set<MessageQueue> messageQueueSet = new HashSet<MessageQueue>();
messageQueueSet.add(createPullRequest().getMessageQueue());
pushConsumer.getDefaultMQPushConsumerImpl().updateTopicSubscribeInfo(topic, messageQueueSet);
doReturn(123L).when(rebalancePushImpl).computePullFromWhere(any(MessageQueue.class));
}
Aggregations