Skip to content

Commit

Permalink
Add server-side batching
Browse files Browse the repository at this point in the history
This implements server-side batching[1].

Since the default value of 0 for the interval is not a valid value, and
is evaluated even if `BatchingPolicy` is `false`, I've set this value as
a pointer and added a helper function to set it.

[1] https://ably.com/docs/channels#server-side-batching
  • Loading branch information
surminus committed Aug 13, 2024
1 parent 7e96bc9 commit bec1f80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ type Namespace struct {
// If true, messages received on a channel will contain a unique timeserial that can be
// referenced by later messages for use with message interactions.
ExposeTimeserial bool `json:"exposeTimeserial"`
// If true, channels within this namespace will start batching inbound
// messages instead of sending them out immediately to subscribers as per
// the configured policy.
BatchingEnabled bool `json:"batchingEnabled"`
// When configured, sets the policy for message batching.
BatchingPolicy string `json:"batchingPolicy"`
// When configured, sets the maximium batching interval in the channel.
BatchingInterval *int `json:"batchingInterval"`
}

// Namespaces lists the namespaces for the specified application ID.
Expand Down Expand Up @@ -59,3 +67,7 @@ func (c *Client) DeleteNamespace(appID, namespaceID string) error {
err := c.request("DELETE", "/apps/"+appID+"/namespaces/"+namespaceID, nil, nil)
return err
}

func NewBatchingInterval(interval int) *int {
return &interval
}
3 changes: 3 additions & 0 deletions namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestNamespaces(t *testing.T) {
PushEnabled: true,
TlsOnly: true,
ExposeTimeserial: true,
BatchingEnabled: true,
BatchingPolicy: "some-policy",
BatchingInterval: NewBatchingInterval(100),
}

n, err = client.UpdateNamespace(app.ID, &namespace)
Expand Down

0 comments on commit bec1f80

Please sign in to comment.