In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Python how to achieve publish and subscribe", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python how to achieve publish and subscribe" bar!
Python uses redis libraries to publish and subscribe.
`import redis
Class RedisHelper:
Def _ _ init__ (self): self.__conn = redis.Redis (host='192.168.5.124',password='V6jZVVhNBfSiJ7Ib') self.chan_pub = 'TaskManager.Redis.Channel' self.chan_sub =' TaskManager.Redis.Channel'def public (self,msg): self.__conn.publish (self.chan_pub Msg) return Truedef subscribe (self): pub = self.__conn.pubsub () pub.subscribe (self.chan_pub) pub.parse_response () return pubrhl = RedisHelper () msg = {"name": 'Tim'} redis_sub = rhl.subscribe () rhl.public (json.dumps (msg)) while True: msg = redis_sub.parse_response () print (msg)
`
Chan_pub is a redis communication channel. Publishers and subscribers who connect to the same channel can communicate.
If the password set by the redis library, be sure to add password, otherwise an error will be reported.
Thank you for reading, the above is the content of "how to publish and subscribe to Python". After the study of this article, I believe you have a deeper understanding of how to achieve publishing and subscription in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.