NATS服务器配置详解

来源:互联网 发布:数值的整数次方 java 编辑:程序博客网 时间:2024/06/06 06:30

NATS服务器配置详解

作者:chszs,未经博主允许不得转载。经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs

尽管NATS可以无配置的运行,但也可以使用配置文件配置NATS服务器。

1)配置项包括

  • 客户端监听器端口 Client listening port
  • HTTP监听器端口 HTTP monitoring port
  • 客户端认证 Client auth
  • 集群定义 Cluster definitions
  • 集群路由 Cluster routes
  • 日志 Logging
  • 最大客户端连接数 Max client connections
  • 最大有效负载 Max payload
  • 慢消费者阀值 Slow consumer threshold

2)配置文件的语法

NATS服务器配置文件的格式比较灵活,结合了传统的JSON格式和新的YAML格式的风格。

NATS配置文件格式支持以下语法:

  • Mixed Arrays: […]
  • Nested Maps: {…}
  • Multiple comment types: # and //
  • Key value assigments using:

    Equals sign (foo = 2)
    Colon (foo: 2)
    Whitespace (foo 2)

  • Maps can be assigned with no key separator

  • Semicolons as value terminators in key/value assignments are optional

注:YAML不是标记语言,而是一种语言中立的、对阅读友好的数据序列化标准。YAML语言发展了三个版本,1.0、1.1、1.2,

3)NATS服务器配置文件示例

下面是一个完整的NATS服务器配置文件样例:

port: 4242      # 供客户端连接的监听端口net: apcera.me  # 监听的网络地址http_port: 8222 # HTTP监控端口# 客户端连接的认证信息authorization {  user:     derek  password: T0pS3cr3t  timeout:  1}# 集群定义cluster {  host: '127.0.0.1'  # 主机地址  port: 4244         # 路由连接的入站(inbound)端口  # 路由连接的认证信息  authorization {    user: route_user    password: T0pS3cr3tT00!    timeout: 0.5  }  # Routes are actively solicited and connected to from this server.  # Other servers can connect to us if they supply the correct credentials  # in their routes definitions from above.  routes = [    nats-route://user1:pass1@127.0.0.1:4245    nats-route://user2:pass2@127.0.0.1:4246  ]}# 日志选项debug:   falsetrace:   truelogtime: falselog_file: "/tmp/gnatsd.log"# PID进程文件pid_file: "/tmp/gnatsd.pid"# 一些系统属性# 客户端最大连接数max_connections: 100# 最大协议控制行max_control_line: 512# 最大的有效负载max_payload: 65536# 慢消费者阀值max_pending_size: 10000000
0 0