Skip to content

Initial checkin of PublishMessage/Publish#9515

Closed
flowchartsman wants to merge 1 commit intoapache:masterfrom
flowchartsman:go-functions-rework-multi-dispatch
Closed

Initial checkin of PublishMessage/Publish#9515
flowchartsman wants to merge 1 commit intoapache:masterfrom
flowchartsman:go-functions-rework-multi-dispatch

Conversation

@flowchartsman
Copy link
Contributor

fixes #9512

Motivation

#9512

Modifications

similar to #9512, but errors are fatal, as with normal message handling. (FEEDBACK REQUESTED))

Verifying this change

  • None of the tests in the Go code exercise this change, and there were no tests for NewOutputMessage either, except for very basic assertions on a producer.

This change added tests and can be verified as follows:

  • I will need help testing this, because currently there are no integration tests for go pulsar functions in the SDK code. I am still unfamiliar with how they are integration / unit tested at all outside of the module

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)
  • If yes, how is the feature documented? (not documented) (draft)

@flowchartsman
Copy link
Contributor Author

feedback CC @freeznet @sijie

@flowchartsman
Copy link
Contributor Author

flowchartsman commented Feb 7, 2021

This is one possible way this could be implemented, sticking to the standards of Go Pulsar functions by sending the message async and not returning error/messageID to the user. The other possible route would be like my original suggestion, and then all sends to topics that are not the output topic would be synchronous. FEEDBACK REQUESTED

@sijie
Copy link
Member

sijie commented Feb 8, 2021

@freeznet @nlu90 Can you review this?

producer.SendAsync(ctx, &message, func(_ pulsar.MessageID, _ *pulsar.ProducerMessage, err error) {
if err != nil {
goInstance.stats.incrTotalSysExceptions(err)
log.Fatal(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to exit the process here or instead return an error to allow users to handle delivering failures?


producer := fctx.NewOutputMessage(publishTopic)
msgID, err := producer.Send(ctx, &pulsar.ProducerMessage{
log.Printf("publishing to additional topic %s", publishTopic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for debugging purpose and will be removed when checked in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the example, so it's only there to show that it's doing something. I wasn't sure what to put here. Recommendations?

Comment on lines +40 to +41
Publish func(topic string, payload []byte)
PublishMessage func(topic string, message pulsar.ProducerMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give little more control to the caller with a context and return an error?

  1. Something like func(ctx Context, topic string, payload []byte), since you are creating and passing a context to the lower level anyway.
  2. Return an error instead of log.Fatal crash the process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@flowchartsman flowchartsman Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally wrote it that way, but returning an error is not how the rest of the framework works. If there's an error, it dies, relying on metrics/backpressure to alert and remediate. Why should this be any different for multiple output topics? If you look at the conceptual documents for multi-topic dispatch (with python examples), they are not treated any differently as a unit. To me, this suggests they should be treated (and automatically tracked with metrics) the same way, otherwise the user should just create a regular consumer/producer with the regular golang SDK, not a pulsar function.

// topic for output message
// topic for output message (DEPRECATED)
func (c *FunctionContext) NewOutputMessage(topicName string) pulsar.Producer {
log.Warn("NewOutputMessage is deprecated, please use Publish() or PublishMsg()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a new function like NewProducer(topicName string) (pulsar.Producer, error) or with any proper name. the reason is we need to remain this function exists, and let user know with the log.Warn if they still want this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would agree, but as I've discussed elsewhere, the pulsar function SDK API is relatively lightweight by design. The more knobs you give the user to tweak at runtime, the further you get from the control of the process the SDK appears to be designed for. At that point, it is not much different from a regular consumer/producer with deployment, some configuration and some logging taken care of.

Comment on lines +40 to +41
Publish func(topic string, payload []byte)
PublishMessage func(topic string, message pulsar.ProducerMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codelipenghui
Copy link
Contributor

The pr had no activity for 30 days, mark with Stale label.

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

@flowchartsman:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@tisonkun
Copy link
Member

Closed as the development of the Go client has been permanently moved to https://github.com/apache/pulsar-client-go.

@tisonkun tisonkun closed this Nov 11, 2022
@tisonkun
Copy link
Member

Oops. It's about the Go Functions, not the Go client.

But still, there're several conflicts so please feel free to resubmit the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go Functions] NewOutputMessage API should probably be changed to Publish()

7 participants