Publish/Subscribe with PubNub Data Streams

Use PubNub's Data Streams to Publish Subscibe and Push Notiications to any device globally.

What Data Streams Does

  • Stream data and signal any device in realtime
  • Stream data instantly to millions of users or signal devices one-to-one
  • Manage dropped connections and catch up of missed messages
  • All the capabilities of WebSockets, Socket.IO, SignalR, WebRTC Data Channel and other streaming protocols

Key Features

  • Publish/Subscribe Model for realtime messaging and signaling
  • Broadcast (one-to-many) realtime messages to a huge user base
  • Unicast (one-to-one) signaling of devices via dedicated channels
  • Multiplexing of multiple data streams on a single connection (part of Stream Controller)
  • Channel Groups to manage thousands of channels as a single unit (part of Stream Controller)
  • Server-Side Cache to automatically re-establish dropped connections and catch up messages
  • Supported Everywhere with over 50 SDKs including: iOS, Android, JavaScript, .NET, Java, Ruby, Python, PHP and many more
Publish Subscribe Data Streams
Publish Subscribe Data Streams

Resources

Get the Code
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    10. 10
    11. 11
  1. // say hello!
  2.  
  3. pubnub.publish({
  4. channel : 'my_channel',
  5. message : 'hello!'
  6. });
  7.  
  8. pubnub.subscribe({
  9. channel : 'my_channel',
  10. message : function(m){console.log(m)}
  11. });
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    10. 10
  1. // say hello!
  2.  
  3. pubnub.Publish<string>(channel="mychannel",
  4. publishMsg="hello!", DisplayReturnMessage,
  5. DisplayErrorMessage);
  6.  
  7. pubnub.Subscribe<string>(channel="mychannel",
  8. DisplaySubscribeReturnMessage,
  9. DisplaySubscribeConnectStatusMessage,
  10. DisplayErrorMessage);
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
  1. // say hello!
  2.  
  3. ## Subscribe on the channel
  4. [PubNub subscribeOnChannel:channel_1];
  5.  
  6. ## Publish on the channel
  7. [PubNub sendMessage:@"hello!"
  8. toChannel:channel_1];
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
  1. // say hello!
  2.  
  3. Hashtable args = new Hashtable(2);
  4. String message = "hello!";
  5. String channel = "hello_world";
  6. args.put("message", message);
  7. args.put("channel", channel);
  8.  
  9. // Publish
  10.  
  11. pubnub.publish(args, new Callback() {
  12. public void successCallback(String channel,
  13. Object message) {
  14. notifyUser(channel + " : " +
  15. message.toString());
  16. }
  17. public void errorCallback(String channel,
  18. Object message) {
  19. notifyUser(channel + " : " +
  20. message.toString());
  21. }
  22. });
  23.  
  24. // Subsribe
  25.  
  26. Hashtable args = new Hashtable(1);
  27. args.put("channel", channel);
  28. pubnub.subscribe(args, new Callback() {
  29. public void connectCallback(String channel) {
  30. notifyUser("CONNECT on channel:" + channel);
  31. }
  32. public void disconnectCallback(String channel)
  33. {
  34. notifyUser("DISCONNECT on channel:" +
  35. channel);
  36. }
  37. public void reconnectCallback(String channel) {
  38. notifyUser("RECONNECT on channel:" + channel);
  39. }
  40. public void successCallback(String channel,
  41. Object message) {
  42. notifyUser(channel + " " +
  43. message.toString());
  44. }
  45. public void errorCallback(String channel,
  46. Object message) {
  47. notifyUser(channel + " " +
  48. message.toString());
  49. }
  50. });
Watch the Video

Loading...