PubNub: Can I divide my users to groups and get messages only from one group on one channel? - pubnub

I have two types of users 'Managers' and 'Students' which subscribe to a channel 'all.channel', I want the following behavior to be applied:
a. Users from 'Managers' group will get all messages published from both user groups 'Managers' and 'Students'.
b. Users from group 'Students' will get publish messages only from user of group 'Managers' (will not see 'Students' publish messages).
My idea was to create two channels:
a. 'all.channel' - 'Managers' and 'Students' users will publish to it. only 'Managers' users will subscribe to it. A pubnub 'After Publish' function will chain only 'Managers' message to another channel called 'all.student.channel'
b. 'all.student.channel' - only 'Students' will subscribe to it.
My question is if there're any build-in tools or capabilities in PubNub to do it less complex, or even with only one channel?

Manager & Student Configuration
🔐 Security is important. Students should not see Manager's private messages.
You'll need to consider security. Only managers should be able to see manager messages. Consider multiplexing your channels for Managers. A manager will subscribe to both root.managers channel and root.students channel too. While students only subscribe to root.students channel. This way you can grant read/write permission to managers on the root.*. You can grant access to students on root.students.roomID to read/write.
You may also consider 💬 ChatEngine an open and extensible chat SDK and APIs for building group chat.
More channel configuration options below for your consideration.
Channel Configuration Options
For the PubNub SDKs 4.0 and higher. Multiplexing the SDK supports up to about 50 channels practically. You can increase this number further but device performance will be impacted. It is better to utilize the Channel Group feature of the core PubNub Stream Controller product. Stream Controller includes the following channel subscription enhancements.
Wildcard Subscribe
Maximum Addressable Channels: ( Unlimited )
PubNub Also supports Wildcard Subscriptions using a Hierarchical dot notation. Today in PubNub you can subscribe to channel "a.b.*" and receive messages at any channel below a.b. You could publish to channel "a.b.c" and receive the message in your wildcard subscribe. Note that the maximum depth supported of the hierarchy is currently a depth of three. For example "a.b.*" is good but "a.b.c.*" is not supported.
Channel Groups
Maximum Addressable Channels: ( 2,000 ✕ 10 = 20,000 )
Dynamically control the device's data stream feed with PubNub Channel Groups. You can remotely control which streams the device is subscribed to and dynamically add and remove channels from the list of channels. You can multiplex subscribe up to 10 channel groups and each channel group can contain up to 2,000 channels.
Multiplexing
Maximum Addressable Channels: ( ~50 )
You can multiplex your connection by subscribing to a combination of Wildcard Channels, Channel Groups, Presence Event Stream Channels and more. It is recommended to keep your multiplexed channels below 50 for best device performance.
Stream Filtering:
Maximum Addressable Channels: ( Unlimited )
Stream Filter allows a subscriber to apply a filter to only receive messages that satisfy the conditions of the filter. The message filter is set by the subscribing client(s) but it is applied on the server side thus preventing unwanted messages (those that do not meet the conditions of the filter) from reaching the subscriber. Stream Filters are implemented with two components: meta dictionary on publish and filter expression on subscribe. Filters are applied to all channels that the client is subscribed to. When messages are encrypted (using crypto key when initializing PubNub), the meta dictionary is plain text, so that the PubNub Network can properly apply the filters as required. It is important to only include information that is not confidential or otherwise requiring encryption.

Related

How to subscribe 1000 pubnub channels from the client?

I have a web client using pubnub, and there are 1000 channels need to be subscribed. But once I call pubnub.subscribe(allChannels), the server returns 500.
I did not find any limit saying why it cannot.
Actually, there is no hard limit on the number of channels you can subscribe to. But if you are going to subscribe to more than 20-30 channels, it's usually recommended to use Channel Groups instead, which allows you to create a collection of channels and give that collection a name. Then, your client simply subscribes to the Channel Group instead of the individual channels. https://www.pubnub.com/developers/tech/key-concepts/stream-controller/channel-groups/
There is a limit number of subscribed channels, that's what I have tested: 640 channels. And once subscribed 640 channels, it is still successful, but if you subscribe one more, errors will start happening (server returns 500) and all your pubnub connection will get destroyed.
It seems you can subscribe many more channels at one time (Its official website suggest 50 channels, but I have tried subscribed 400 channels at one time and it is successful)
So total limit 640 is what I have found.
Subscribe to 1,000 Channels and Beyond
You already know the list of channels you want to subscribe to, Channel Groups will help you get to 2,000 channels per group. There are also some options to subscribe to an unlimited number of channels using wildcards!
You can have 2,000 channels per channel group. This matches your need for 1,000 channel subscription.
🔐 Also remember that Security is important. Remember that you should secure your data.
More channel subscription options below for your consideration.
Channel Subscription Options
For the PubNub SDKs 4.0 and higher. Multiplexing the SDK supports up to around 50 channels practically. You can increase this number further but device performance will be impacted. It is better to utilize the Channel Group feature of the core PubNub Stream Controller product. Stream Controller includes the following channel subscription enhancements.
Wildcard Subscribe
Maximum Addressable Channels: ( Unlimited )
PubNub Also supports Wildcard Subscriptions using a Hierarchical dot notation. Today in PubNub you can subscribe to channel "a.b.*" and receive messages at any channel below a.b. You could publish to channel "a.b.c" and receive the message in your wildcard subscribe. Note that the maximum depth supported of the hierarchy is currently a depth of three. For example "a.b.*" is good but "a.b.c.*" is not supported.
Channel Groups
Maximum Addressable Channels: ( 2,000 ✕ 10 = 20,000 )
Dynamically control the device's data stream feed with PubNub Channel Groups. You can remotely control which streams the device is subscribed to and dynamically add and remove channels from the list of channels. You can multiplex subscribe up to 10 channel groups and each channel group can contain up to 2,000 channels.
Multiplexing
Maximum Addressable Channels: ( ~50-500 )
You can multiplex your connection by subscribing to a combination of Wildcard Channels, Channel Groups, Presence Event Stream Channels and more. It is recommended to keep your multiplexed channels below 50 for best device performance.
Stream Filtering
Maximum Addressable Channels: ( Unlimited )
Stream Filter allows a subscriber to apply a filter to only receive messages that satisfy the conditions of the filter. The message filter is set by the subscribing client(s) but it is applied on the server side thus preventing unwanted messages (those that do not meet the conditions of the filter) from reaching the subscriber. Stream Filters are implemented with two components: meta dictionary on publish and filter expression on subscribe. Filters are applied to all channels that the client is subscribed to. When messages are encrypted (using crypto key when initializing PubNub), the meta dictionary is plain text, so that the PubNub Network can properly apply the filters as required. It is important to only include information that is not confidential or otherwise requiring encryption.
you need to correct the syntax.
pubnub.subscribe({
channels:allChann
})

How to handle an event raised in one channel in a different channel in Hyperledger Composer of Fabric?

I have this scenario that a single node is part of different channels. In one channel there are only traders. In the other channel there are traders and regulator. Details of the trades should not be shared with the regulator. The only thing which is being shared is aggregated value at the end of the business day. By aggregated value, we mean how much of each asset is sold, not the detail of each trade. In other words there is confidential information between two parties that cannot be shared with regulator, and there is aggregated value that is not confidential and must be shared with the regulator.
Now I have an event when there is a nomination. By nomination I mean a trade made over some asset in the first channel, the one without regulator. Is it possible to handle this trading event in the other channel where the regulator is?
As I read through the documents, channels are isolated. But how isolated are they? Are they isolated in a way that events raised in one channel cannot be seen or handled in another channel? In that case, how do you suggest to implement this scenario? I mean do you suggest any specific architecture or tools enabling implementation of this scenario? Also do you think Hyperledger Fabric or Composer are suitable for these requirements?
I appreciate any help. Thank you.
So you have two channels, two separate ledgers and two separate business networks (as you've configured it).
Your 'nomination' is, in effect, a 'transaction' as described above. (events in Composer mean, business events that are usually subscribed to by a client application FYI).
In Hyperledger Composer, you can do 'cross-channel' or 'inter business network' queries. So can allow [only] the Regulator (from the 2nd channel) to query [only] those trade 'events' (ie transactions with the fields that contain the 'trade') or indeed assets (updated by the transaction), if need be - back in the '1st' channel (and access controls) in the 2nd channel can restrict the Regulator to do only that 'query' (if that's all he/she is supposed to have jurisdiction to do). Hope this helps.
See example
https://hyperledger.github.io/composer/latest/tutorials/invoke-composer-network

Unique identifier for Spring Integration

I have a pub/subscribe queue in Spring Integration. Once a message is put on the queue I can see a new message ID is generated and different message ID for each of the subscribers. I want to use the initial unique message ID as an unique identifier while it flows through various microservices subscribers. Can I get the original message ID from each of the subscribers?
Also if I had multiple spring integration instances writing the messages into a single kafka queue, would message ID be unique?
I think Kafka deserves its own SO question. Re. the same id for all the subflows: how about a applySequence = true for the PublishSubscribeChannel and each message copy will be send with the Sequence Details headers where the IntegrationMessageHeaderAccessor.CORRELATION_ID is exactly copy of the original message?
The problem with Messaging that each new message should be really a new unique object. This way each message is a stand along entity and it doesn't effect all others and even may not know about their existence. The stateless is one of the consistency goals of Messaging per se.
Therefore if you would like to carry some identificator to all the messages, you should consider to use some other header, not an id. For this purpose the Framework already provides for your conventional mechanism called correlation and sequence details: https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/messaging-channels-section.html#channel-configuration-pubsubchannel

Number of channels and billing

I am looking at building an app that monitors the public transport buses for a major city:
I did a quick prototype using pubnub. The buses have a phone transmitting gps signals to a channel and bus users have phones subscribed to channels. I have questions:
I am planning for each bus route there is a channel. The city has 50 routes so there will be 50 routes. Does this adhere to the best practice?
Is there an api to list channels ?
I am sending a message to a channel every second. Assume, there are 50 routes with 5 buses each running 24 hours. There will be 216000000 daily messages. what will i be charged for a day?
Does your Android client open a network connection everytime a publish is call? I want to minimize the bandwith used by the phone that is transmitting the GPS signal.
Bus users may want to see location of multiples buses. I know best practice is to subscribe to one public and one private channel. What is the best way to do it?
I would appreciate if you could answer the above questions.
Full disclosure up front - I work for PubNub Customer Success so responses for pricing related questions are informational in nature only and not to be construed as a promotional. Asker specifically mentions PubNub and the information provided below is publicly available from the PubNub website.
Anant, also as an FYI StackOverflow would normally ask that each of these questions gets asked as a separate thread. Moving forward please do your best to adhere to community guidelines.
1 Every implementation will be different as far as the specific architecture and design pattern strategy though your proposed approach seems to be a sensible utilization of channel methodology. PubNub does not limit the total number of channels in use, however as a practical limitation for most mobile development frameworks subscribing to more than 50 channels simultaneously would be around the upper limit. Adding more than that and both iOS and Android will begin exhibiting performance limitations. If new bus lines are added the subscriptions can be managed to only subscribe to nearby routes, etc.
Question 1 the second with the indent. Yes that can be done with the here_now API
2 PubNub charges $1 per million messages (without SSL enabled) so based on your hypothetical your message charges would be $216 per day. That being said, there is significant room here for design pattern optimization so that busses only publish a new location whenever there is a change - repeated publishes while the bus is standing still are unnecessary. This optimization on it's own will bring the message usage figure down significantly, and there are other strategies which can be utilized to further optimize depending on your specific implementation approach. If you anticipate needing more than 1 billion messages per month, a deployment to Global Cloud would make sense so as to avail yourself of volume discount pricing not otherwise available on Go Cloud.
3 Rather than opening a new connection with every publish, PubNub keeps an active socket connection open until unsubscribed or disconnected via loss of network connection/app force close. The bandwidth utilization to keep this connection active over a period of several hours and absent any other publish/subscribe activity typically measures less than 1K depending on your configuration parameters. Android supports background threading so even when the app is not in focus the connection can remain open to facilitate data push alerts which can be used to prompt the user to bring the app back into the foreground to review any updated information.
4 This question is not clear, assuming that the bus locations are published to the public channel what would the purpose of the private channel serve? If you meant a private channel to receive alerts for the arrival of the user's selected bus, then yes that would be an appropriate implementation strategy. Please clarify if you meant something different.

How do I create a channel in Pusher

I could not find any explicit information about the creation of channels with Pusher.
Is that simply an implicit action when either subscribing on the client or pushing events on the server?
class HelloController < ApplicationController
def hello
#does this create a channel "named 'test-channel'"?
Pusher['test-channel'].trigger('test_event', { :hello => 'world' })
end
end
If so is there a limit to the number of channels available?
The reason for my question is that I'd like to create a unique channel for every user and after the client side has closed down that channel.
But probably that is not really a good idea ;-)
thanks
Channels are really just a way of routing or filtering data. They exist by simply being subscribed to or having data published to them. So, it is an implicit action.
There are no limits to the number of channels you use and a unique channel per user is a nice solution for targeted messaging.

Resources