coadu / zeromq-playground

Configuration for zeromq-playground Vagrant box and docker containers
MIT License
2 stars 0 forks source link

zeromq-playground

Updates

Background

This is a playground setup that I put together in preparation for attending ZeroMQ CPH Community Meetup with Pieter Hintjen

It is a vagrant box with docker installed and some docker containers for running ØMQ.

There is also a script to install and run Skydns and Skydock (DNS based service discovery for docker) allowing containers to reference each other by dns name instead of ip address.

Install

To use this setup you need to install:

I am using this setup on Linux, but it should work on Mac and Windows as well.

Get

Clone this repository and start the box:

git clone https://github.com/madscoaducom/zeromq-playground
cd zeromq-playground
vagrant box add coadu/zeromq-playground
vagrant up
# time for coffee

To access the image:

vagrant ssh

ZMQ tutorial is located in ./zguide

Run with Skydock

Setup Skydock/Skydns:

vagrant ssh
/vagrant/setup-skydock.sh

Here are instructions for running the ØMQ zguide Hello World example in Python. The source to zguide examples are included on the image, look in "zguide/examples".

NOTE that the standard examples are written for a singlehost setup, so some tweaking is needed for them to work here.

I have tweaked two of the examples and included the code in the app folder including run scripts.

For below examples when it says "Open a terminal and run", it expects you to be inside vagrant image in app folder:

vagrant ssh
cd app

Hello World

Open a terminal and run:

./hwserver.sh

Open another terminal:

./hwclient.sh

You should see the server and client talking.

BStar

Open a terminal and run:

./bstarprimary.sh

Open another terminal:

./bstarbackup.sh

Open a third terminal:

./bstarcli.sh

Now the primary and backup are connected, and the client connected to the primary.

If you kill the primary:

sudo docker kill primary

You should see the client switching to use the backup.

Tweaking notes

When using hostnames in code they have to resolve at time of bind(), but skydock only adds entries to the skydns when a container starts. So the code has to be tolerant and wait to bind() untill necesary parts are running (Note that currently docker does not support assigning IP's to containers).

In the BStar example, the primary and backup need to know about each other at startup time, I have hacked the example for it to retry connection to the other node indefinetely. I am sure there are better solutions, but that is something to work on.

Working on your own code

Simply place your source files inside the app folder on your host, and you can access it from vagrant, in /home/vagrant/app and in containers from /app (you can change this by means of the -v option to docker run)

Other clients

Currently I have published a docker container with Python ØMQ bindings, but you can easily build others with your prefered language bindings.

Simply:

docker build --rm=true -t <name of conainer> .

(Notice the trailing '.')

To run your new container, look in pyzmq.sh for an example, or lookup the docker run docs.

ToDo's and Issues:

If you find (and fix?) issues please report them on github

References

This setup is possible because of these great projects and services:

Check them out!