wolfstudy commented on a change in pull request #4008: [go function]support log
topic for go function
URL: https://github.com/apache/pulsar/pull/4008#discussion_r273620101
##########
File path: pulsar-function-go/pf/instance.go
##########
@@ -259,6 +268,39 @@ func getIdleTimeout(timeoutMilliSecond time.Duration)
time.Duration {
return timeoutMilliSecond
}
+func (gi *goInstance) setupLogHandler() error {
+ if gi.context.instanceConf.funcDetails.GetLogTopic() != "" {
+ gi.context.logAppender = NewLogAppender(
+ gi.client,
//pulsar client
+ gi.context.instanceConf.funcDetails.GetLogTopic(),
//log topic
+
getDefaultSubscriptionName(gi.context.instanceConf.funcDetails.Tenant, //fqn
+ gi.context.instanceConf.funcDetails.Namespace,
+ gi.context.instanceConf.funcDetails.Name),
+ )
+ return gi.context.logAppender.Start()
+ }
+ return nil
+}
+
+func (gi *goInstance) addLogTopicHandler() {
+ if gi.context.logAppender == nil {
+ panic("please init logAppender")
+ }
+
+ for _, logByte := range log.StrEntry {
+ gi.context.logAppender.Append([]byte(logByte))
+ }
+}
+
+func (gi *goInstance) closeLogTopic() {
+ log.Info("closing log topic...")
Review comment:
In fact, their results are the same, Stop() will only be called by
closeLogTopic(). According to Java logic, I should remove the corresponding
logAppender after processing handlerMsg(), but the processing logic of go
function here is a little different, all msg is received through the channel,
assuming, we follow the logic of Java, if the producer produces multiple
messages, then this will panic, because when I get the first message from the
channel after that, I have closed the producer . So here, I chose to close all
resources at the end.
----------------------------------------------------------------
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