[zeromq-dev] Question on connecting a C++ model to a Java model via Python uzing ZeroMQ

Sara Rimer sara.p.rimer at gmail.com
Fri Apr 29 22:58:48 CEST 2016


This worked!!!! Thank you so much!!

As a follow-up question, I was just curious if you might have a
recommendation to me for how I conceptually set up my ZeroMQ system. So I
basically want a server that I run that receives and sends messages to two
clients. Client1 waits for a message from the Server before it runs for a
given time, then sends a message to the Server once it has finished.
Client2 waits to receive a message from the Server that it sends once it
receives a message from Client1. Then once Client2 receives this message,
it runs for a given time and sends a message to the Server to then deploy
Client1. And this repeats.

I think I am stuck as to how to do the "waiting" part for both of the
clients. Do you have any suggestions?

I can't thank you enough for your help.

On Fri, Apr 29, 2016 at 12:16 AM, Stephen Riesenberg <
stephen.riesenberg at gmail.com> wrote:

> Looks like you're on the right path now. So -Djava.library.path is what
> allows the Java program to find the binary linked library for jzmq. For
> reference, -D is a flag that allows you to pass runtime environment
> parameters which are available via e.g.
> System.getProperty("java.library.path").
>
> So for Eclipse, you need two things.
>
>    1. Set up your program to run with that property (java.library.path)
>    set, which can be done per program (main) or globally.
>    2. Set up your classpath.
>
> I'm using STS, but should be the same.
>
> To set your library path for a program, go to Run -> Run Configurations ->
> Java Application -> [your program] -> Arguments tab. If you don't have any
> programs yet, just right-click your program with a main() and run it. It
> gets created automatically even if it has errors. In the Arguments tab,
> under VM arguments, add -Djava.library.path=/usr/local/lib.
>
> To set your classpath, I usually use Maven or Gradle, but if you're
> rolling your own custom project with no dependency management, you right
> click your project -> Properties -> Java Build Path -> Libraries tab, then
> add your jar(s).
>
> Hope that helps.
>
> Also, if you want to set up a Maven or Gradle based sample ZeroMQ Java
> project, let me know, and I can help with that. It would be a nice repo to
> have on GitHub for people like yourself to fork and start coding.
>
> On Thu, Apr 28, 2016 at 6:24 PM, Sara Rimer <sara.p.rimer at gmail.com>
> wrote:
>
>> Ok, so I ran the
>> mvn test
>> and it everything was okay. I was originally trying to rebuild some basic
>> ZeroMQ programs using Java just to make sure it worked (my preferred
>> language is Python). But while the programs would compile, they wouldn't
>> run. That is when I went back to looking for tutorials and came across one
>> that used local_lat as an example, which thanks to your advice I
>> abandoned trying it.
>>
>> Thus, I retried building hwClient.java and hwServer.java and I finally
>> got them to work! My issue was pointing to the correct classpaths (which I
>> am not quite used to doing in Java), and also adding in this (
>> -Djava.library.path=/usr/local/lib), but I don't really understand what
>> the "-Djava" command does).
>>
>> Anyway, I had to add the following paths so my command looked like this:
>>
>> java -cp
>> ./:/usr/local/share/java/zmq.jar:/home/sara/Applications/zeromq/jzmq/jzmq-jni/src/main/c++/zmq.jar
>> -Djava.library.path=/usr/local/lib hwClient
>>
>> The Java program that I have built that I am trying to implement ZeroMQ
>> with I have built within Eclipse. So I am not really used to working with
>> Java via the terminal. Thus, I was wondering how I can I run the command
>> above via Eclipse? That is, if you are familiar with Eclipse, how to I add
>> these classpaths?
>> -cp
>> ./:/usr/local/share/java/zmq.jar:/home/sara/Applications/zeromq/jzmq/jzmq-jni/src/main/c++/zmq.jar
>>
>> And then how do I implement the following command in Eclipse?
>> -Djava.library.path=/usr/local/lib hwClient
>>
>> ​Thank you all. I appreciate your help.
>>
>> Sincerely,
>> Sara​
>>
>>
>> On Wed, Apr 27, 2016 at 9:35 PM, Stephen Riesenberg <
>> stephen.riesenberg at gmail.com> wrote:
>>
>>> Sara,
>>>
>>> While I've done quite a bit of working with jzmq on my local machine,
>>> I've rarely run the local_lat program that's used as an example on the
>>> documentation page for the java binding. So, I may be off a bit, but I
>>> think you would need to build the C++ project in the
>>> jzmq/builds/msvc/local_lat to have that class available. Possibly at
>>> one time it was included in the jar, but that may have changed and it looks
>>> like it isn't any longer.
>>>
>>> Perhaps try running the following (assuming you have maven installed) in
>>> the local directory where you downloaded and built jzmq:
>>>
>>> mvn test
>>>
>>>
>>> Another option is the JeroMQ test suite, which includes several of the
>>> guide examples, which also requires you to download and set up the project
>>> locally (using maven). Or skip it and drop these classes into your own
>>> project (
>>> https://github.com/sjohnr/jeromq/blob/develop/src/test/java/guide/hwclient.java
>>> ,
>>> https://github.com/sjohnr/jeromq/blob/develop/src/test/java/guide/hwserver.java
>>> ).
>>>
>>> Or try running a minimal example of your own within your own project.
>>>
>>> Hope that helps.
>>>
>>> On Wed, Apr 27, 2016 at 7:55 PM, Sara Rimer <sara.p.rimer at gmail.com>
>>> wrote:
>>>
>>>> Hi everyone,
>>>>
>>>> I am finally getting back to this part of my project. So I think the
>>>> issue is that I just can't get ZeroMQ to work with Java on my machine. I
>>>> have tried JeroMQ as well. I have been following this guide:
>>>> http://zeromq.org/bindings:java and when I try
>>>>
>>>> $ java -cp /usr/local/share/java/zmq.jar:. local_lat tcp://127.0.0.1:5000 1 100
>>>>
>>>> I get this error
>>>>
>>>> Error: Could not find or load main class local_lat
>>>>
>>>> I think I have just not found a good guide for how to set up ZeroMQ for
>>>> Java on Linux 12.04. Any suggestions?
>>>>
>>>> Thank you.
>>>>
>>>> Sincerely,
>>>> Sara
>>>>
>>>> On Mon, Mar 28, 2016 at 8:30 PM, Stephen Riesenberg <
>>>> stephen.riesenberg at gmail.com> wrote:
>>>>
>>>>> Sara,
>>>>>
>>>>> How far have you gotten in your effort? Do you have an example class?
>>>>> What issues did you run into? What requirements do you have for your
>>>>> API? Is it files, or just data you are sending back and forth between these
>>>>> two environments?
>>>>>
>>>>> Sorry for so many questions, but I bet with a few details we can get
>>>>> you pointed in the right direction. Sounds like an interesting project!
>>>>>
>>>>> On Friday, March 25, 2016, Sara Rimer <sara.p.rimer at gmail.com> wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> This is most likely a very basic usage of ZeroMQ, but I am a
>>>>>> computational engineer and I am trying to connect a hydraulic model written
>>>>>> in C++ to a decision tree model written in Java. I would like to send data
>>>>>> files back and forth between the two programs. I am using ZeroMQ for this.
>>>>>> And I have gotten ZeroMQ to work via Python no problem (which I am planning
>>>>>> on using for my C++ model which I run via a bash script). However, I am
>>>>>> having difficulty interfacing it with Java. I was planning on just creating
>>>>>> a class in Java that is solely used to interface with ZeroMQ. Does anyone
>>>>>> have any suggestions?
>>>>>>
>>>>>> Thanks,
>>>>>> Sara
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> _______________________________________________
>>>>> zeromq-dev mailing list
>>>>> zeromq-dev at lists.zeromq.org
>>>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Sara Rimer
>>>> University of Michigan Graduate Student
>>>> Department of Civil and Environmental Engineering
>>>> srimer at umich.edu
>>>> sara.p.rimer at gmail.com
>>>> 269.483.6334
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> zeromq-dev mailing list
>>>> zeromq-dev at lists.zeromq.org
>>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>
>>>
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>
>>
>>
>> --
>> Sara Rimer
>> University of Michigan Graduate Student
>> Department of Civil and Environmental Engineering
>> srimer at umich.edu
>> sara.p.rimer at gmail.com
>> 269.483.6334
>>
>>
>>
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



-- 
Sara Rimer
University of Michigan Graduate Student
Department of Civil and Environmental Engineering
srimer at umich.edu
sara.p.rimer at gmail.com
269.483.6334
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20160429/e3f44ac1/attachment.htm>


More information about the zeromq-dev mailing list