You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2023/05/15 03:25:09 UTC
[GitHub] [pulsar] KMoonSC edited a discussion: How to get properties in org.apache.pulsar.broker.intercept.BrokerInterceptor#beforeSendMessage ?
GitHub user KMoonSC edited a discussion: How to get properties in org.apache.pulsar.broker.intercept.BrokerInterceptor#beforeSendMessage ?
### Version
2.7.1
### What do you want ?
i want to log some information in Broker before messages send to consumer
### What have you done?
i use BrokerInterceptor to do so
here's my BrokerInterceptor:
`
public class LogBrokerInterceptor implements BrokerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(LogBrokerInterceptor.class);
@Override
public void beforeSendMessage(Subscription subscription, Entry entry, long[] ackSet, PulsarApi.MessageMetadata msgMetadata) {
List<PulsarApi.KeyValue> properties = msgMetadata.getPropertiesList();
for (PulsarApi.KeyValue keyValue : properties) {
logger.info("LogBrokerInterceptor beforeSendMessage. properties key:{} value:{}", keyValue.getKey(), keyValue.getValue());
}
logger.info("LogBrokerInterceptor beforeSendMessage. topic:{} subscription:{} sequenceId:{} propertiesSize:{}", subscription.getTopic(), subscription.getName(), msgMetadata.getSequenceId(), properties.size());
}
`
and here's my produce test:
`
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://localhost:6650")
.build();
Producer producer = client.newProducer()
.topic("public/default/my-topic")
.create();
Map<String, String> properties = new HashMap<>();
properties.put("clientId", "clientId123");
producer.newMessage()
.properties(properties)
.value("data1234".getBytes())
.send();
`
### What did you expect to see?
the properties i settled wound be logged like this:
"LogBrokerInterceptor beforeSendMessage. properties key:clientId value:clientId123"
### What did you see instead?
there's no such log, but this;
"LogBrokerInterceptor beforeSendMessage. topic:xxx subscription:xxx sequenceId:xxx propertiesSize:0"
shows that there is no properties in msgMetadata
### Q
so here is the Question:
Am I using the wrong way to get the properties I set to the message ?
If so, how to make it right?
GitHub link: https://github.com/apache/pulsar/discussions/20322
----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscribe@pulsar.apache.org