Setting up the NATS server cluster
NATS servers can be clustered to support high-volume systems and to provide better availability. NATS uses a simple clustering protocol to connect with other servers via gossiping and connecting to all the servers that a particular server is aware of. Once clients connect to a given server, the clients are informed about the current cluster members. We discussed NATS clustering in detail in Chapter 3, What Is NATS Messaging?. For this chapter, let's create a three-node cluster to try out our OPD microservice application.
Starting up the three-node NATS server cluster
Let's start a three-node cluster by specifying the client port and the cluster port, as shown here:
- Start the first server as the seed server:
$ nats-server -p 4222 -cluster nats://localhost:4248 -D
- Start the second server by specifying the cluster URL of the first (seed) server:
$ nats-server -p 5222 -cluster nats://localhost:5248 -routes nats://localhost:4248...