Skip to content

Publish in Realtime channel #597

@amimimor

Description

@amimimor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions