sijie commented on a change in pull request #4093: [issue#4042] improve java
functions API
URL: https://github.com/apache/pulsar/pull/4093#discussion_r277241098
##########
File path:
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java
##########
@@ -346,60 +346,31 @@ public ByteBuffer getState(String key) {
return publish(topicName, object, (Schema<O>)
topicSchema.getSchema(topicName, object, schemaOrSerdeClassName, false),
messageConf);
}
+ @Override
+ public <O> TypedMessageBuilder<O> newOutputMessage(String topicName,
Schema<O> schema) throws PulsarClientException {
+ Producer<O> producer = getProducer(topicName, schema);
+ return producer.newMessage();
Review comment:
as Jerry and me discussed in thread, you need to add a simple wrapper to
update metrics correctly.
```
public <O> TypedMessageBuilder<O> newOutputMessage(String topicName,
Schema<O> schema) {
final TypedMessageBuilder<O> underlyingBuilder = ...;
return new TypedMessageBuilder<O>() {
@Override
public MessageId send() throws PulsarClientException {
return sendAsync().get();
}
@Override
public CompletableFuture<MessageId> sendAsync() {
return underlyingBuilder.sendAsync()
.whenComplete((result, cause) -> {
if (null != cause) {
statsManager.incrSysExceptions(cause);
logger.error("Failed to publish to topic {} with
error {}", topicName, e);
}
});
}
@Override
public TypedMessageBuilder<O> key(String key) {
underlyingBuilder.key(key);
return this;
}
@Override
public TypedMessageBuilder<O> keyBytes(byte[] key) {
underlyingBuilder.keyBytes(key);
return this;
}
@Override
public TypedMessageBuilder<O> value(O value) {
underlyingBuilder.value(value);
return this;
}
@Override
public TypedMessageBuilder<O> property(String name, String
value) {
underlyingBuilder.property(name, value);
return this;
}
@Override
public TypedMessageBuilder<O> properties(Map<String, String>
properties) {
underlyingBuilder.properties(properties);
return this;
}
@Override
public TypedMessageBuilder<O> eventTime(long timestamp) {
underlyingBuilder.eventTime(timestamp);
return this;
}
@Override
public TypedMessageBuilder<O> sequenceId(long sequenceId) {
underlyingBuilder.sequenceId(sequenceId);
return this;
}
@Override
public TypedMessageBuilder<O> replicationClusters(List<String>
clusters) {
underlyingBuilder.replicationClusters(clusters);
return this;
}
@Override
public TypedMessageBuilder<O> disableReplication() {
underlyingBuilder.disableReplication();
return this;
}
@Override
public TypedMessageBuilder<O> loadConf(Map<String, Object>
config) {
underlyingBuilder.loadConf(config);
return this;
}
};
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services