Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

johnkim76/zeromq-java-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a demo project of aPubSub application using∅mq with Google'sProtocol Buffers for serializing data build withMaven.

∅mq

I have a multi account system, so I have to switch to my administrator account.

su admin

Install∅mq form source (the latest homebrew version3.2.1-rc2 had some errors that cause jzmq unit tests to fail)

cd ~/Projects/externalgit clone git://github.com/zeromq/libzmq.gitcd libzmq./autogen.sh./configuremakemake install

Exit to the normal user

exit

jzmq

Switch to admun user

su admin

Install latestjzmq

cd ~/Projects/externalgit clone git://github.com/zeromq/jzmq.gitcd jzmq./autogen.sh./configuremakemake install

Test the installation

cd perfjava -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:../src/zmq.jar:zmq-perf.jar local_lat tcp://127.0.0.1:5555 1 100

At the first run this fails

...Library not loaded: /usr/local/lib/libzmq.1.dylib  Referenced from: /usr/local/lib/libjzmq.0.dylib

And indeed the file does not exist, butlibzmq.3.dylib does exist, so

ln -s /usr/local/lib/libzmq.3.dylib /usr/local/lib/libzmq.1.dylib

Rerun the perf test

java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:../src/zmq.jar:zmq-perf.jar local_lat tcp://127.0.0.1:5555 1 100java -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:../src/zmq.jar:zmq-perf.jar remote_lat tcp://127.0.0.1:5555 1 100

Proceed to compile the maven artifact

cd ..export JAVA_HOME=`/usr/libexec/java_home -v 1.7`mvn clean install -DskipTests

Exit to the normal user

exit

Maven and jzmq

Although jzmq's officialmaven.readme advices you to add a dependency to the native artifact, I didn't work. In fact itdid only work without the native library.

So just add

<dependency><groupId>org.zeromq</groupId><artifactId>jzmq</artifactId><version>${version.jzmq}</version></dependency>

to your dependencies.

Protocol Buffers

I want to use Google'sProtocol Buffers as the serializing mechanism

Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.

brew install protobuf

There is a Maven plugin to build.proto files. It's not released on Maven Central, so you have to add the plugin repository to your$M2_HOME/settings.xml. In this example I added it directly to thepom.xml though.

<pluginRepositories>    <pluginRepository>        <id>protoc-plugin</id>        <url>http://sergei-ivanov.github.com/maven-protoc-plugin/repo/releases/</url>    </pluginRepository></pluginRepositories>

To include the generated source in Eclipse with m2eclipse. You also have to add

<plugin><groupId>org.codehaus.mojo</groupId><artifactId>build-helper-maven-plugin</artifactId><executions><execution><id>add-source</id><phase>generate-sources</phase><goals><goal>add-source</goal></goals><configuration><sources><source>${project.build.directory}/generated-sources/protoc</source></sources></configuration></execution></executions></plugin>

to yourpom.xml.

Appendix

FAQ

java.lang.UnsatisfiedLinkError

Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/lib/libjzmq.0.dylib: dlopen(/usr/local/lib/libjzmq.0.dylib, 1): Library not loaded: /usr/local/lib/libzmq.1.dylib  Referenced from: /usr/local/lib/libjzmq.0.dylib  Reason: image not foundat java.lang.ClassLoader$NativeLibrary.load(Native Method)at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)at java.lang.Runtime.loadLibrary0(Runtime.java:845)at java.lang.System.loadLibrary(System.java:1084)at org.zeromq.ZMQ.<clinit>(ZMQ.java:35)at local_lat.main(local_lat.java:36)

There is a/usr/local/lib/libzmq.3.dylib but no/usr/local/lib/libzmq.3.dylib.

As a workaround I executed

ln -s /usr/local/lib/libzmq.3.dylib /usr/local/lib/libzmq.1.dylib

dyld: DYLD_ environment variables being ignored

When trying to fix my zeromq installation I got

dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

Turned out$LD_LIBRARY_PATH was set. Unset it via

unset LD_LIBRARY_PATH

testDestruction(org.zeromq.ZContextTest): no jzmq in java.library.path

cd ~/Projects/external/jzmqmvn clean install

fails with

Tests in error:   testDestruction(org.zeromq.ZContextTest): no jzmq in java.library.path  ...

What isjava.library.path

java.library.path is used for pointing to native system libraries (dll or so files). It points to a directory and calls to native code that use System.loadLibrary look in that directory for the native libs.

The project dependencies (jar files) should be specified on the application's classpath, not in this location.

from1

Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin

As I couldn't get the tests to finish I did

mvn clean install -DskipTests

But was greeted with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.7:jar (attach-javadoc) on project jzmq: MavenReportException: Error while creating archive:Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

Make sureJAVA_HOME is set. If you have Java 6

export JAVA_HOME=`/usr/libexec/java_home -v 1.6`

or Java 7

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

junit.framework.AssertionFailedError

Unfortunately the Maven tests for jzmq ddidn't finish (correctly).

singleMessage(org.zeromq.ZDispatcherTest)  Time elapsed: 1.01 sec  <<< FAILURE!junit.framework.AssertionFailedError: expected:<0> but was:<1>

and even worseRunning org.zeromq.ZFrameTest seems to be stuck in an endless loop.

The mailing listsuggested to remove homebrews latest version (3.2.1-rc2) and install libzmq from source.

This solved the problems with the tests.

Install zeromq from source

The mailing list suggested to install zeromq from source

brew remove zeromqgit clone git://github.com/zeromq/libzmq.gitcd libzmq/./autogen.sh./configuremakemake install

Testing the installation with perf failed at first

cd perfjava -Djava.library.path=/usr/local/lib -classpath /usr/local/share/java/zmq.jar:../src/zmq.jar:zmq-perf.jar local_lat tcp://127.0.0.1:5555 1 100...Library not loaded: /usr/local/lib/libzmq.1.dylib  Referenced from: /usr/local/lib/libjzmq.0.dylib

So, I executed

ln -s /usr/local/lib/libzmq.3.dylib /usr/local/lib/libzmq.1.dylib

Then I recompiled jzmq

cd ../jzmqmake cleanmakemake install

Now the tests successfully ran, so installed the artifact

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`mvn clean install

Resources

The code example for protocol buffers is taken from2 and the basic pubsub example is taken from ∅mq official java examples3, and4

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp