谁来管理ZeroMQ中的持久化?
当我们在Python语言中使用ZeroMQ客户端时,可以使用哪些插件/模块来管理持久化?
我想知道使用ZeroMQ的模式。
发布于 2010-12-07 15:49:47
据我所知,Zeromq没有任何持久性。它超出了它的范围,需要由最终用户处理。就像序列化消息一样。在C#中,我使用了db4o来添加持久性。通常,我将对象保持在其原始状态,然后序列化它并将其发送到ZMQ套接字。顺便说一句,这是为PUB/SUB对准备的。
发布于 2012-03-07 06:46:54
在应用程序端,您可以相应地持久化,例如,我在node.js中构建了一个持久层,它通过websockets与后端php调用进行通信。
持久性方面将消息保存了一段时间(http://en.wikipedia.org/wiki/Time_to_live),这是为了给客户端一个连接的机会。我使用了内存中的数据结构,但我玩弄了一下使用redis来获得磁盘持久性的想法。
发布于 2018-05-05 16:28:26
在处理消息之前,我们需要持久化从订阅者那里收到的消息。消息在单独的线程中接收并存储在磁盘上,而持久化消息队列在主线程中操作。
该模块的网址为:https://pypi.org/project/persizmq。从文档中:
import pathlib
import zmq
import persizmq
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.setsockopt_string(zmq.SUBSCRIBE, "")
subscriber.connect("ipc:///some-queue.zeromq")
persistent_dir = pathlib.Path("/some/dir")
storage = persizmq.PersistentStorage(persistent_dir=persistent_dir)
def on_exception(exception: Exception)->None:
print("an exception in the listening thread: {}".format(exception))
with persizmq.ThreadedSubscriber(
callback=storage.add_message, subscriber=subscriber,
on_exception=on_exception):
msg = storage.front() # non-blocking
if msg is not None:
print("Received a persistent message: {}".format(msg))
storage.pop_front()https://stackoverflow.com/questions/4059706
复制相似问题