Jason918 commented on a change in pull request #11139:
URL: https://github.com/apache/pulsar/pull/11139#discussion_r660581016
##########
File path: site2/docs/admin-api-topics.md
##########
@@ -538,6 +538,31 @@ admin.topics().getMessageById(topic, ledgerId, entryId);
<!--END_DOCUSAURUS_CODE_TABS-->
+### Get message ID
+
+You can get message id published at or just after the given datetime.
+
+<!--DOCUSAURUS_CODE_TABS-->
+<!--pulsar-admin-->
+```shell
+$ ./bin/pulsar-admin topics get-message-id \
Review comment:
There are $ in all the other shell demos. You sure we should do that?
Either is fine by me.
##########
File path: site2/docs/admin-api-topics.md
##########
@@ -538,6 +538,31 @@ admin.topics().getMessageById(topic, ledgerId, entryId);
<!--END_DOCUSAURUS_CODE_TABS-->
+### Get message ID
+
+You can get message id published at or just after the given datetime.
Review comment:
This doc is for user, it's more detailed. Modified the previous one in
new commit. Please check it out.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/PersistentTopicsTest.java
##########
@@ -796,4 +798,55 @@ public void testSetReplicatedSubscriptionStatus() {
Assert.assertEquals(responseCaptor.getValue().getStatus(),
Response.Status.NO_CONTENT.getStatusCode());
}
+ @Test
+ public void testGetMessageIdByTimestamp() throws Exception {
+ TenantInfoImpl tenantInfo = new
TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
+ admin.tenants().createTenant("tenant-xyz", tenantInfo);
+ admin.namespaces().createNamespace("tenant-xyz/ns-abc",
Sets.newHashSet("test"));
+ final String topicName =
"persistent://tenant-xyz/ns-abc/testGetMessageIdByTimestamp";
+ admin.topics().createNonPartitionedTopic(topicName);
+
+ AtomicLong publishTime = new AtomicLong(0);
+ ProducerBase<byte[]> producer = (ProducerBase<byte[]>)
pulsarClient.newProducer().topic(topicName)
+ .enableBatching(false)
+ .intercept(new ProducerInterceptor() {
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public boolean eligible(Message message) {
+ return true;
+ }
+
+ @Override
+ public Message beforeSend(Producer producer, Message
message) {
+ return message;
+ }
+
+ @Override
+ public void onSendAcknowledgement(Producer producer,
Message message, MessageId msgId,
+ Throwable exception) {
+ publishTime.set(message.getPublishTime());
+ }
+ })
+ .create();
+
+ MessageId id1 = producer.send("test1".getBytes());
+ long publish1 = publishTime.get();
+
+ Thread.sleep(10);
Review comment:
This sleep is not waiting for some other operation to finish. It's used
for making sure that the publish_time of the two messages is different. Any
suggestions how we can do this in a better way?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]