Python PubNub订阅者不会打印出该消息

时间:2016-12-02 22:55:01

标签: python pubnub

这是我的出版商:

from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub

def publish_callback(result, status):
    print(result)
    print(status)
    # Handle PNPublishResult and PNStatus

pnconfig = PNConfiguration()

pnconfig.subscribe_key = 'sub-c-ec413276-b805-11e6-b737-xxxxx'
pnconfig.publish_key = 'pub-c-528502df-76a6-4f07-8636-xxxxx'

pubnub = PubNub(pnconfig)

pubnub.publish().channel("awesomeChannel").message("hello!!").async(publish_callback)

这是我的订阅者

from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub

from pubnubtets import MySubscribeCallback
pnconfig = PNConfiguration()

pnconfig.subscribe_key = 'sub-c-ec413276-b805-11e6-b737-xxxxx'
pnconfig.publish_key = 'pub-c-528502df-76a6-4f07-8636-xxxxx'
pubnub = PubNub(pnconfig)

pubnub.add_listener(MySubscribeCallback())
pubnub.subscribe().channels('awesomeChannel').execute()

这是我的回调:

from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNStatusCategory

class MySubscribeCallback(SubscribeCallback):
  def presence(self, pubnub, presence):
    print(presence)

  def status(self, pubnub, status):
    if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory:
      pass  # This event happens when radio / connectivity is lost

    elif status.category == PNStatusCategory.PNConnectedCategory:
      # Connect event. You can do stuff like publish, and know you'll get it.
      # Or just use the connected event to confirm you are subscribed for
      # UI / internal notifications, etc
      pass
    elif status.category == PNStatusCategory.PNReconnectedCategory:
      pass
      # Happens as part of our regular operation. This event happens when
      # radio / connectivity is lost, then regained.
    elif status.category == PNStatusCategory.PNDecryptionErrorCategory:
      pass
      # Handle message decryption error. Probably client configured to
      # encrypt messages and on live data feed it received plain text.

  def message(self, pubnub, message):
    print(message)

我遇到的问题是当我运行它监听的订阅者时,当我运行发布者发送消息hello!!时,我的回调得到它但是当我打印消息时它打印出<pubnub.models.consumer.pubsub.PNMessageResult object at 0x108453278>。我希望它实际向我显示我的消息hello!!

我有什么遗失的吗?

0 个答案:

没有答案