QBoard » Advanced Visualizations » Viz - Python » What are Pubnub Channels also how to push data into pubnub?

What are Pubnub Channels also how to push data into pubnub?

  • I am looking into pubnub to use in my real time data visualization with Rickshaw. But I do not understand are the channels already configured or do we have to configure them. If so how can we configure a channel for a data viz? Also I am getting the data from python Ceilometer API how can I push that data into pubnub?
      August 20, 2021 12:55 PM IST
    0
  • Channels are an abstraction, similar to "chat rooms". Any message sent using PubNub, will be over a channel. A message consists of a channel, and its associated data payload. A publishing client publishes messages to a given channel, and a subscribing client receives only the messages associated with the channels its subscribed to.

    Channels are created on-the-fly, and do not incur any additional charges to use one or many in your application. When you create a PubNub application, all messages will be associated with a channel.

    It has the advantage of minimal network usage (each client receives only the data it needs) and minimal processing (no need for filtering unneeded data).

    In order to push data into PubNub(we call this publish), you need to first create a PubNub instance, and put in your API keys. Get your keys here.

    pubnub = Pubnub(publish_key='demo', subscribe_key='demo')

    PubNub uses simple APIs to publish data as shown below :

    def callback(message):
         print(message)
    pubnub.publish('my_channel', 'Hello from PubNub Python SDK!', callback=callback, error=callback)​


    The first parameter is the channel you want to publish data to, the second is the message you want to send, and the last two are callback functions that are called when you publish.

    You can find detailed information on the APIs and on how to get started for the Python SDK on the site.
      August 28, 2021 1:51 PM IST
    0