In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about the use of IPFS pubsub functions, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
What is pubsub?
The publish-subscribe model (Publish-subscribe pattern) was first introduced by Apple in Mac OS.
The sender of the message (publishers) does not send the message directly to the recipient (subscriber). Instead, the message is classified, and the sender does not know and does not need to know the existence of the receiver. On the other hand, the receiver only needs to subscribe to one or more categories of message classes, only receive messages of interest, and do not know or need to know the existence of the publisher. (https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)
Code writers are no stranger to Observer. This is somewhat similar to the Observer pattern in software design patterns. But it's not exactly the same. Pubsub is more loosely coupled than Observer. I will not compare the difference between the two in detail here. If you are interested, Google by yourself.
At present, the pubsub function is also an experimental function of ipfs. If you want to turn on the pubsub function, you need to specify the parameter:-- enable-pubsub-experiment when starting ipfs daempon.
Let's use specific examples to illustrate how to use ipfs pubsub?
1. Build two IPFS nodes An and B
If you don't already know how to build a node, see the previous article, "how to upload a picture in an IPFS network."
A (editor's local node):
IPFS node ID: QmTrRNgt6M9syRq8ZqM4o92Fgh7avK8v862n2QZLyDPywY
IPFS address: 192.168.162.129 (privacy protection, no public network IP)
B (Amazon aws):
IPFS address: 13.231.198.154
IPFS node address; / ip4/13.231.198.154/tcp/4001/ipfs/QmXL2h7Y51BHZMaypzjCnNc1MiVk2H5EZJxWgAuRkLanaK
two。 Start Node B
Ipfs daemon-- enable-pubsub-experiment (note that the parameter-- enable-pubsub-experiment is required here)
3. For a quick demonstration, connect nodes An and B directly
Delete all bootstrap addresses of node A
Ipfs bootstrap rm all
Add B node to A node as bootstrap node
Ipfs bootstrap add / ip4/13.231.198.154/tcp/4001/ipfs/QmXL2h7Y51BHZMaypzjCnNc1MiVk2H5EZJxWgAuRkLanaK
4. Start Node A
Ipfs daemon-enable-pubsub-experiment
(note that you need to use the parameter-- enable-pubsub-experiment)
5. Use of pubsub function
Open a new command line on node A, execute
Ipfs pubsub sub flytofuture
This means that we subscribe to the message topic: flytofuture on node A. All messages sent to this message subject will be received by A node.
We send a message to the message subject flytofuture at node B
Ipfs pubsub pub flytofuture "hello, IPFS Guide, fly to the Future!"
At this point we can see the message output on the command line of node A: hello, IPFS Guide, fly to the Future!
Two IPFS nodes across different networks and different regions communicate with pubsub functions.
In fact, the pubsub function is not only limited to two directly connected nodes, but also can be transferred through intermediate nodes.
For example, there are three nodes, A, A, B, B, C, A, B, B, C, C, B, C, C, B, C, B, B, C, C, B, B, C, C, Then A can still subscribe to receive messages from C. This is very useful for some complex network environments, such as those where NAT is not very friendly.
Command usage and functions related to pubsub
Pubsub-related commands use:
Ipfs pubsub ls-lists all the topics subscribed to by this node
Ipfs pubsub peers-list the nodes connected to this node with pubsub enabled
Ipfs pubsub pub-publish data to the appropriate topic
Ipfs pubsub sub-subscribe to topics
Pubsub function has many uses, the majority of developers can open their minds to build their own applications based on such functions.
At present, there are two benchmarking applications on IPFS that are based on pubsub functions.
Orbit-db: distributed database
Orbit: peer-to-peer chat tool
After reading the above, do you have any further understanding of the use of IPFS pubsub functions? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.