Preparations
- Find out docker host’s IP and create the following shell function. Replace
172.17.0.1
with the one found on your system:
1 | export DOCKER_HOST=172.17.0.1 |
- Get nsq
1
docker pull nsqio/nsq
Start the containers
1 | run-nsq |
Publish a message **
1 | curl -d 'hello world' "http://$DOCKER_HOST:4151/pub?topic=sample_topic" |
Set up a consumer
1 | mkdir -p ~/projects/test-nsq |
Create consumer.js as listed below.
1 |
|
Test
1 | node consumer.js |
You should see something similar to:
1 | Received message [0abc62e587053000]: hello world |
nsqadmin
Open http://127.0.0.1:4171/
from a browser.
** The reason why publisher runs before consumer is for the topic to be created before a consumer can subscribe to it.