I’m playing with ZeroMQ and Java again.
If you ask my friends about my previous experience with ZeroMQ and Java, it went something like this:
They seemed to have fixed some of that by offering a pure java implementation of ZMQ. Unfortunately, it doesn’t support all the features that I need so I’ll be using the ‘standard’ jzmq.
Anyways, this is just a quick post to help others get it working.
PS. This is on Ubuntu 12.04.1 LTS but I’ll add OSX instructions when I get that setup again on my MBP.
You must install zeromq first. I’m using 3.2.3.
sudo apt-get install libtool autoconf automake uuid-dev # install prereqs. most of these are probably already install but it doesn't hurt to run these wget http://download.zeromq.org/zeromq-3.2.3.tar.gz tar xzvf zeromq-3.2.3.tar.gz cd zeromq-3.2.3/ ./autogen.sh ./configure # include whatever options you want to build with (read INSTALL or ./configure for available options make make install # sudo if you want this system wide sudo ldconfig # this line ensures profit after installing
Pay attention to any errors that happen during the above. Hopefully you won’t have any. Take a break and reward yourself for successfully installing zmq.
Testing your install:
Ok, you actually rewarded yourself too early because you don’t actually know if install worked already. So let’s just test it real quick. I’ll be using python for this even though, eventually, I’ll be writing a java client. Why? Because I can and it should allow me to and well, python is the right tool for a quick testing job. I’m using python 2.7.3 for this.
sudo apt-get install python-setuptools # make sure you have this installed because we will be using easy_install sudo easy_install pyzmq
The above will actually detect your zmq install. Now interesting enough, I made a mistake of having an earlier version of zmq on my box when I was writing this and got:
collect2: ld returned 1 exit status ZMQ version detected: 2.1.7
A quick locate zmq.so (you might need to updatedb first) showed me where the old libraries were and removing them fixed the issue.
Next clone https://github.com/h3adache/zmq_stuff. It just provides a very very simple client/server test based on https://github.com/zeromq/pyzmq/tree/master/examples/bench.
Start up 2 terminals.
In one type:
python # this will start the python interpreter >>> import server >>> server.start()
In the other type:
python >>> import client >>> client.echo("whatever you want")
You should see messages to consoles.
Now you can start up n terminals all running the client and test each separately.
If you didn’t change my code then it should be running in REQ/REP mode. Check here to see what other modes you can run with.
I’m going to end this here for now because it’s getting long and it’s time for lunch ;). But congrats on getting zmq setup quickly (I hope) and painlessly (I hope).
Update: You can now run it multicast too