srkukarni commented on a change in pull request #3854: [issue #3767] support go
function for pulsar
URL: https://github.com/apache/pulsar/pull/3854#discussion_r272302963
##########
File path: pulsar-function-go/pf/instance.go
##########
@@ -29,68 +29,72 @@ import (
"github.com/apache/pulsar/pulsar-function-go/pb"
)
-type GoInstance struct {
- function Function
+type goInstance struct {
+ function function
context *FunctionContext
producer pulsar.Producer
consumers map[string]pulsar.Consumer
client pulsar.Client
}
-// NewGoInstance init GoInstance and init function context
-func NewGoInstance() *GoInstance {
- goInstance := &GoInstance{
+// newGoInstance init goInstance and init function context
+func newGoInstance() *goInstance {
+ goInstance := &goInstance{
context: NewFuncContext(),
consumers: make(map[string]pulsar.Consumer),
}
return goInstance
}
-func (gi *GoInstance) StartFunction(function Function) {
+func (gi *goInstance) startFunction(function function) error {
gi.function = function
err := gi.setupClient()
if err != nil {
- panic("setup client failed, please check.")
+ log.Errorf("setup client failed, error is:%v", err)
+ return err
}
err = gi.setupProducer()
if err != nil {
- panic("setup producer failed, please check.")
+ log.Errorf("setup producer failed, error is:%v", err)
+ return err
}
channel, err := gi.setupConsumer()
if err != nil {
- panic("setup consumer failed, please check.")
+ log.Errorf("setup consumer failed, error is:%v", err)
+ return err
}
CLOSE:
for {
select {
case cm := <-channel:
msgInput := cm.Message
- atMostOnce :=
gi.context.InstanceConf.FuncDetails.ProcessingGuarantees ==
pb.ProcessingGuarantees_ATMOST_ONCE
- autoAck := gi.context.InstanceConf.FuncDetails.AutoAck
+ atMostOnce :=
gi.context.instanceConf.funcDetails.ProcessingGuarantees ==
pb.ProcessingGuarantees_ATMOST_ONCE
+ autoAck := gi.context.instanceConf.funcDetails.AutoAck
if autoAck && atMostOnce {
gi.ackInputMessage(msgInput)
}
output, err := gi.handlerMsg(msgInput)
if err != nil {
log.Errorf("handler message error:%v", err)
gi.nackInputMessage(msgInput)
- } else {
- gi.processResult(msgInput, output)
+ return err
Review comment:
in google logging library log(fatal) means process death. I assumed that
would be the case with go as well. my mistake.
In any case, in case of any error while handleMessage, if effectively once,
just panic. else if atleast_once, nack. That should do the trick
----------------------------------------------------------------
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