Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service-bus] Message batching #15136

Closed
richardpark-msft opened this issue Jul 23, 2021 · 3 comments
Closed

[service-bus] Message batching #15136

richardpark-msft opened this issue Jul 23, 2021 · 3 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved. Service Bus

Comments

@richardpark-msft
Copy link
Member

richardpark-msft commented Jul 23, 2021

Track 2 added in the ability to create a message batch - basically, it's a "append only" collection of messages which are encoded and sent as a single message. This can be a big efficiency boost for senders as it allows the combining of several small messages into one, eliminating some per-message send overhead which can add up.

Interfaces used for illustration - current policy for the Go SDK (from what I can see) is to use concrete types:

type ServiceBusMessageBatch interface {
  AddMessage(msg *Message) bool
}

type interface ServiceBusSender {
  // other methods elided...

  // looks at the current link for the 'max batch size', creates a message batch
  // NOTE this does actually need to potentially initialize the link so it needs to take a context.
  CreateMessageBatch(ctx context.Context) (*ServiceBusMessageBatch, error)
}

// usage

batch, err := sender.CreateMessageBatch(context.TODO())

// NOTE: in other languages where we throw exceptions this check is less
// complicated. Perhaps we'd like to have a designated error (message too big) 
// so we just have the single return value instead of having `added` and `err`?
if added, err := batch.TryAdd(message); !added {
  // message failed to add - decisions to make:
  if err != nil {
      // If there was an internal encoding failure the best they can do is drop this message.
      return
  }

  // otherwise the only reason we failed here was because the message was too big to fit
  // into the existing batch. So we can:
  // a. Send the batch immediately and then start a new batch with this message
  // b. Discard this message

  // There is also the potential pitfall that the message is too large, even on it's own,
  // to fit into a batch. All of this is determinable using the .TryAdd() call and checking
  // it's return value.
}

sender.SendMessageBatch(context.TODO(), batch)

References:

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 23, 2021
@richardpark-msft richardpark-msft added Client This issue points to a problem in the data-plane of the library. Service Bus labels Jul 23, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 23, 2021
@richardpark-msft
Copy link
Member Author

There is some code related to batching here: https://github.com/richardpark-msft/azure-sdk-for-go/blob/sb-track-2/sdk/servicebus/batch.go

It looks like it's hard coding the max message size based on the messaging tier, which should not be done (it can be dynamically retrieved from the link).

@richardpark-msft
Copy link
Member Author

Even better - the .Add signature in the existing batch code already has the .Add() (bool, error) signature:

https://github.com/richardpark-msft/azure-sdk-for-go/blob/e68e55fb55079816240f0dab9991215d7d33885a/sdk/servicebus/batch.go#L106

@RickWinter RickWinter added the feature-request This issue requires a new behavior in the product in order be resolved. label Jul 23, 2021
@richardpark-msft richardpark-msft added this to the [2021] September milestone Jul 27, 2021
richardpark-msft added a commit that referenced this issue Sep 15, 2021
Updating track 2 to support sending message batches.

- Adds in 'SendableMessage' as an interface that all sendable things (Message, MessageBatch) conform to. This will also be the future interface that our AmqpMessage will support as well.
- Some more fields have been added to the Message/ReceivedMessage.

Close #15136
@richardpark-msft
Copy link
Member Author

Implemented in #15561

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. feature-request This issue requires a new behavior in the product in order be resolved. Service Bus
Projects
None yet
Development

No branches or pull requests

2 participants