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

Publish in Realtime channel #597

Open
amimimor opened this issue Jun 5, 2023 · 1 comment
Open

Publish in Realtime channel #597

amimimor opened this issue Jun 5, 2023 · 1 comment

Comments

@amimimor
Copy link

amimimor commented Jun 5, 2023

While trying to understand how to publish directly to a single subscriber with the realtime channel, I came across this:

func (c *RealtimeChannel) Publish(ctx context.Context, name string, data interface{}) error {
return c.PublishMultiple(ctx, []*Message{{Name: name, Data: data}})
}
// PublishMultiple publishes all given messages on the channel at once.
//
// This implicitly attaches the channel if it's not already attached. If the
// context is canceled before the attach operation finishes, the call
// returns with an error, but the operation carries on in the background and
// the channel may eventually be attached and the message published anyway (RTL6i).
func (c *RealtimeChannel) PublishMultiple(ctx context.Context, messages []*Message) error {
id := c.client.Auth.clientIDForCheck()
for _, v := range messages {
if v.ClientID != "" && id != wildcardClientID && v.ClientID != id {
// Spec RTL6g3,RTL6g4
return fmt.Errorf("Unable to publish message containing a clientId (%s) that is incompatible with the library clientId (%s)", v.ClientID, id)
}
}

When using the Publish method, it effectively creates a []*Message{{Name: name, Data: data}} and calls the PublishMultiple.
Given this in the iteration over L608 (where v is type *Message from the passed in slice):

a) one cannot publish any message that bares additional properties (never there is a ClientId property)
b) therefore, the conditional in the snippet above is never evaluated to true

Additionally, and CMIIW, I'm failing to understand the usage of the Publish method with the data being passed as ably.Message (as in realtime_channel_test.go), since what would happen (given the above snippet) if I call publish like so:
Publish(context.Background(), "name", able.Message{Name: "name", Data: "hi", OtherPublicProp: "a"})
... and would effectively create a []*Message{{Name: name, Data: able.Message{Name: "name", Data: "hi", OtherPublicProp: "a"}}, i.e. a Message wrapping the passed in Message, and call PublishMultiple with this slice as param, so even if I wanted to build my own Message with a ClientId, it would be wrapped in a Message that doesn't have a ClientId

┆Issue is synchronized with this Jira Task by Unito

@sync-by-unito
Copy link

sync-by-unito bot commented Jun 5, 2023

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3620

@amimimor amimimor changed the title Unable to pass ClientId to Publish in Realtime channel Publish in Realtime channel Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant