Create an overlay network for the NATS & NATS Streaming cluster (in this example, nats-streaming-example). Notice we added the --attachable option which will allow other containers to join the network which will be done at the end to confirm that can connect to the cluster.
Next create the NATS cluster which will be used by the NATS Streaming cluster.
for i in`seq13`; dosudodockerservicecreate--networknats-streaming-example \--namenats-cluster-node-$i nats:1.1.0 \-clusternats://0.0.0.0:6222 \ -routes nats://nats-cluster-node-1:6222,nats://nats-cluster-node-2:6222,nats://nats-cluster-node-3:6222
done
Step 3:
Now that there is a NATS cluster available to connect, create the NATS Streaming cluster of three nodes as follows:
for i in`seq13`; dosudodockerservicecreate--networknats-streaming-example \--namenats-streaming-node-$i nats-streaming:0.9.2 \-storefile-dirstore-clustered-cluster_idswarm-cluster_node_idnode-$i \-cluster_peersnode-1,node-2,node-3 \ -nats_server nats://nats-cluster-node-1:4222,nats://nats-cluster-node-2:4222,nats://nats-cluster-node-3:4222
done
Step 4:
Next, confirm that it is possible to publish and replay messages via NATS Streaming by attaching a container to the same network where both NATS and NATS Streaming exist. Below you can find an example session of doing so, note that even though the client is only connecting to nats://nats-cluster-node-1:4222 the NATS cluster will be routing the messages so that they will be processed to the NATS Streaming cluster service.