Coder Social home page Coder Social logo

bmcustodio / docker-compose-nats-cluster Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 8.0 13 KB

A three-node NATS cluster running on top of Docker Compose for testing purposes.

License: Apache License 2.0

docker-compose nats nats-cluster nats-server

docker-compose-nats-cluster's Introduction

docker-compose-nats-cluster

A three-node NATS cluster running on top of Docker Compose, for testing purposes.

License

Starting

To start the NATS cluster, run

$ docker-compose up
(...)
nats-2_1  | [1] 2020/03/07 13:40:29.890917 [INF] Starting nats-server version 2.1.4
(...)
nats-1_1  | [1] 2020/03/07 13:40:29.841022 [INF] Starting nats-server version 2.1.4
(...)
nats-3_1  | [1] 2020/03/07 13:40:29.895016 [INF] Starting nats-server version 2.1.4
(...)

Connecting

To connect to the NATS cluster, point your NATS client at one of 127.0.0.1:{14222,24222,34222}.

Example

Install nats-pub and nats-sub:

$ go get github.com/nats-io/nats.go/examples/nats-pub
$ go get github.com/nats-io/nats.go/examples/nats-sub

Point nats-sub at nats://127.0.0.1:14222 and at the foo subject:

$ nats-sub -s nats://127.0.0.1:14222 foo
Listening on [foo]

Now, in another shell, point nats-pub at nats://127.0.0.1:24222 and nats://127.0.0.1:34222 and at the foo subject:

$ nats-pub -s nats://127.0.0.1:24222 foo bar
Published [foo] : 'bar'
$ nats-pub -s nats://127.0.0.1:34222 foo baz
Published [foo] : 'baz'

By then, you should start seeing messages arriving in the shell where nats-sub is running:

$ nats-sub -s nats://127.0.0.1:14222 foo
Listening on [foo]
[#1] Received on [foo] : 'bar'
[#2] Received on [foo] : 'baz'

Stopping

To stop the NATS cluster, hit Ctrl+C.

Destroying

To destroy the NATS cluster, run

$ docker-compose down
Removing docker-compose-nats-cluster_nats-1_1 ... done
Removing docker-compose-nats-cluster_nats-3_1 ... done
Removing docker-compose-nats-cluster_nats-2_1 ... done
Removing network docker-compose-nats-cluster_main

License

Copyright 2017-2020 bmcustodio

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.