The following steps will run a small NSQ cluster on your local machine and walk through publishing,

以下步骤将在您的本地机器上运行一个小型NSQ集群,并遍历发布过程,

consuming, and archiving messages to disk.

使用并将消息存档到磁盘。

  1. follow the instructions in the INSTALLING doc.

    遵循安装文档中的说明
    文档 链接 :https://nsq.io/deployment/installing.html
  1. in one shell, start nsqlookupd:

    #在一个shell中,启动nsqlookupd
    $ nsqlookupd
  2. in another shell, start nsqd:

    在另一个shell中,启动' nsqd ':
    $ nsqd --lookupd-tcp-address=127.0.0.1:4160
  1. in another shell, start nsqadmin:

    #在另一个shell中,启动' nsqadmin '
    $ nsqadmin --lookupd-http-address=127.0.0.1:4161
  1. publish an initial message (creates the topic in the cluster, too):

    #发布初始消息(也在集群中创建主题)
    $ curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test'
  1. finally, in another shell, start nsq_to_file:

    最后,在另一个shell中,启动' nsq_to_file '
    $ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
  1. publish more messages to nsqd:

    向“nsqd”发布更多消息:
    $ curl -d 'hello world 2' 'http://127.0.0.1:4151/pub?topic=test'
    $ curl -d 'hello world 3' 'http://127.0.0.1:4151/pub?topic=test'
  1. to verify things worked as expected, in a web browser open http://127.0.0.1:4171/ to view the nsqadmin UI and see statistics. Also, check the contents of the log files (test.*.log) written to /tmp.

    #要验证事情是否如预期的那样工作,可以在web浏览器中打开“http://127.0.0.1:4171/”来查看“nsqadmin”UI并查看统计数据。另外,检查写入' /tmp '的日志文件(' test.*.log ')的内容。

The important lesson here is that nsq_to_file (the client) is not explicitly told where the test topic is produced, it retrieves this information from nsqlookupd and, despite the timing of the connection, no messages are lost.

#这里的重要教训是,“nsq_to_file”(客户机)没有显式地告知“test”主题在何处生成,它从“nsqlookupd”检索此信息,并且,尽管连接的时间是定时的,但不会丢失任何消息。
最后修改:2021 年 02 月 19 日 10 : 22 PM
如果觉得我的文章对你有用,请随意赞赏