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

Using multiple PubNub instances is not possible #91

Closed
bananafish911 opened this issue Nov 22, 2021 · 5 comments
Closed

Using multiple PubNub instances is not possible #91

bananafish911 opened this issue Nov 22, 2021 · 5 comments

Comments

@bananafish911
Copy link

bananafish911 commented Nov 22, 2021

We have a project with literally many chats (8000+), every chat room has following descriptors (chat id itself "chat.id", read receipt descriptor "read-receipts.%chat.id%)", changes descriptor "chat.%chat.id%.changes")

When I try to subscribe to more than 600 chat rooms at once in this way, I got following error in the console:
[Error 2021-11-22T12:00:54.349Z (Subscribe Response Queue#0X2807C6DC0) {Request.finish(error:)#324}] Request 6C151EEC-1C38-4903-82E5-C5192353687E failed with error URI of the request was too long to be processed for response <NSHTTPURLResponse: 0x28138ca00> { URL: https://ps.pndsn.com/v2/subscribe/sub-c-2c6c2b6e-0543-11e8-a831-aa01b54f8d06/read-receipts.5868,read-receipts.4095,read-receipts.5008,read-receipts.5441,chat.4747.changes,chat.5172.changes,read-receipts.4611,chat.4922.changes,read-receipts.5574,chat.5729.changes,chat.6046.changes,read-receipts.4483,read-receipts.4258,read-receipts.4688,chat.4525.changes,read-receipts.4198,chat.5410.changes,chat.4802.changes, ...

To avoid this I tried to use multiple pubnub instances PubNub(configuration: configuration) and subscribe every instance to 200 or less chats.
But turns out every particular instance becomes subscribed to all channels and it still returns error "414 URI too long".
For example: I created PubNub A, and PubNub B instances, subscribe A to channel 1 and b to channel 2, but when I call subscribedChannels() for A, it returns both 1 and 2, and same for B.

And more. When I use unique SubscriptionListener for every unique PubNub instance, every listener handles event from all channels that I subscribe from any PubNub instance.

@parfeon
Copy link
Contributor

parfeon commented Nov 30, 2021

@bananafish911 If it possible to change channel names a bit, there is wildcard subscribe feature available.
With this feature, you should be able to subscribe only for three channels like:

pubnub.subscribe(
  to: ["chat.*", "chat-changes.*", "read-receipts.*"],
  and: [],
  withPresence: true
)

With this configuration, client should receive messages, when they published to chat-changes.5172, chat.5868 or read-receipts.4747. With received message object you can access channel property which will have name of actual channel, on which it has been received (subscription will have wildcard version of it).

@parfeon
Copy link
Contributor

parfeon commented Nov 30, 2021

@bananafish911 if more questions about PubNub SDK usage will appear, our support should be able to help ([email protected])

@bananafish911
Copy link
Author

bananafish911 commented Dec 15, 2021

Thanks for the answer! Yes, wildcard subscribe will be the next step. Currently we just trying to make it work somehow without massive changes in architecture.

JFYI, regarding:

And more. When I use unique SubscriptionListener for every unique PubNub instance, every listener handles event from all channels that I subscribe from any PubNub instance.

Turns out SubscribeSessionFactory returns same SubscriptionSession despite I try to initialize new instance of pubnub. This is because hash getter is not perfect - it compares properties which may be same across different objects. Changing any of values (eg durationUntilTimeout) listed in hasher solved my problem and it became possible to create different pubnub instances.

extension SubscriptionConfiguration {
var subscriptionHashValue: Int {
...
}
}

@parfeon
Copy link
Contributor

parfeon commented Dec 15, 2021

@bananafish911 I wanted to write about listener and subscription factory, but after figured out that wildcard subscription probably will help, I replaced original response with it.

Good to hear that things work for you now!

@TimWatson
Copy link

This is still an issue. I created two different PubNub instances with the same configuration but both of them get events from each other's channels and if I unsubscribeAll() on one of them it unsubscribes from the other instances channels too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants