@Override public byte[] getData() { return msg.getData(); }
TopicMessageImpl(String topicPartitionName, String topicName, Message<T> msg) { this.topicPartitionName = topicPartitionName; this.msg = msg; this.messageId = new TopicMessageIdImpl(topicPartitionName, topicName, msg.getMessageId()); }
if (log.isDebugEnabled()) { log.debug("[{}] [{}] [{}] Got message {}", getSession().getRemoteAddress(), topic, subscription, msg.getMessageId()); dm.messageId = Base64.getEncoder().encodeToString(msg.getMessageId().toByteArray()); dm.payload = Base64.getEncoder().encodeToString(msg.getData()); dm.properties = msg.getProperties(); dm.publishTime = DateFormatter.format(msg.getPublishTime()); if (msg.getEventTime() != 0) { dm.eventTime = DateFormatter.format(msg.getEventTime()); if (msg.hasKey()) { dm.key = msg.getKey(); final long msgSize = msg.getData().length;
@Override void run() throws PulsarAdminException { String persistentTopic = validatePersistentTopic(params); List<Message<byte[]>> messages = persistentTopics.peekMessages(persistentTopic, subName, numMessages); int position = 0; for (Message<byte[]> msg : messages) { if (++position != 1) { System.out.println("-------------------------------------------------------------------------\n"); } if (msg.getMessageId() instanceof BatchMessageIdImpl) { BatchMessageIdImpl msgId = (BatchMessageIdImpl) msg.getMessageId(); System.out.println("Batch Message ID: " + msgId.getLedgerId() + ":" + msgId.getEntryId() + ":" + msgId.getBatchIndex()); } else { MessageIdImpl msgId = (MessageIdImpl) msg.getMessageId(); System.out.println("Message ID: " + msgId.getLedgerId() + ":" + msgId.getEntryId()); } if (msg.getProperties().size() > 0) { System.out.println("Tenants:"); print(msg.getProperties()); } ByteBuf data = Unpooled.wrappedBuffer(msg.getData()); System.out.println(ByteBufUtil.prettyHexDump(data)); } } }
@Override public CompletableFuture<BenchmarkConsumer> createConsumer(String topic, String subscriptionName, ConsumerCallback consumerCallback) { return client.newConsumer().subscriptionType(SubscriptionType.Failover).messageListener((consumer, msg) -> { consumerCallback.messageReceived(msg.getData(), msg.getPublishTime()); consumer.acknowledgeAsync(msg); }).topic(topic).subscriptionName(subscriptionName).subscribeAsync() .thenApply(consumer -> new PulsarBenchmarkConsumer(consumer)); }
@Override public Map<String, String> getProperties() { return msg.getProperties(); }
@Override public int choosePartition(Message msg, TopicMetadata metadata) { // if key is specified, we should use key as routing; // if key is not specified and no sequence id is provided, not an effectively-once publish, use the default // round-robin routing. if (msg.hasKey() || msg.getSequenceId() < 0) { // TODO: the message key routing is problematic at this moment. // https://github.com/apache/pulsar/pull/1029 is fixing that. return super.choosePartition(msg, metadata); } // if there is no key and sequence id is provided, it is an effectively-once publish, we need to ensure // for a given message it always go to one partition, so we use sequence id to do a deterministic routing. return (int) (msg.getSequenceId() % metadata.numPartitions()); }
@Override public long getPublishTime() { return msg.getPublishTime(); }
@Override public String getKey() { return msg.getKey(); }
@Override public long getEventTime() { return msg.getEventTime(); }
@Override public T getValue() { return msg.getValue(); }
@Override public boolean hasKey() { return msg.hasKey(); }
if (log.isDebugEnabled()) { log.debug("[{}] [{}] [{}] Got message {}", getSession().getRemoteAddress(), topic, subscription, msg.getMessageId()); dm.messageId = Base64.getEncoder().encodeToString(msg.getMessageId().toByteArray()); dm.payload = Base64.getEncoder().encodeToString(msg.getData()); dm.properties = msg.getProperties(); dm.publishTime = DateFormatter.format(msg.getPublishTime()); if (msg.getEventTime() != 0) { dm.eventTime = DateFormatter.format(msg.getEventTime()); if (msg.hasKey()) { dm.key = msg.getKey(); final long msgSize = msg.getData().length;
@Override void run() throws PulsarAdminException { String persistentTopic = validatePersistentTopic(params); List<Message<byte[]>> messages = topics.peekMessages(persistentTopic, subName, numMessages); int position = 0; for (Message<byte[]> msg : messages) { if (++position != 1) { System.out.println("-------------------------------------------------------------------------\n"); } if (msg.getMessageId() instanceof BatchMessageIdImpl) { BatchMessageIdImpl msgId = (BatchMessageIdImpl) msg.getMessageId(); System.out.println("Batch Message ID: " + msgId.getLedgerId() + ":" + msgId.getEntryId() + ":" + msgId.getBatchIndex()); } else { MessageIdImpl msgId = (MessageIdImpl) msg.getMessageId(); System.out.println("Message ID: " + msgId.getLedgerId() + ":" + msgId.getEntryId()); } if (msg.getProperties().size() > 0) { System.out.println("Tenants:"); print(msg.getProperties()); } ByteBuf data = Unpooled.wrappedBuffer(msg.getData()); System.out.println(ByteBufUtil.prettyHexDump(data)); } } }
bytesReceived.add(msg.getData().length); long latencyMillis = System.currentTimeMillis() - msg.getPublishTime(); if (latencyMillis >= 0) { recorder.recordValue(latencyMillis);
@Override public Map<String, String> getProperties() { return msg.getProperties(); }
@Override public long getPublishTime() { return msg.getPublishTime(); }
@Override public String getKey() { return msg.getKey(); }