繁体   English   中英

安装并运行ZeroMQ

[英]Installing and running ZeroMQ

我正在尝试在PC上安装ZeroMQ,但无法使我的程序运行而不会崩溃。
安装:

1) install Visual Studio 2017.

2) clone from git jzmq and libzmq

3) install ZMQ version 4.0.4 for windows.

4) run the script build in: \libzmq\builds\msvc\build\build.bat

5) open in Visual Studio 2017: libzmq\builds\msvc\vs2017\libzmq.sln and jzmq\jzmq-jni\builds\msvc\msvc.sln.

6) rebuild in the Visual Studio 2017 the sln files:

+ libzmq.sln : in the properties: configuration: Active(DebugDLL) platform: Active(x64)

+ msvc.sln : in the properties: configuration:Release platform: Active(x64)
label VC++ Directories: update the include directories and Library directories,
label Linker -> Input: update the Additional Dependencies with - C:\git-repo\libzmq\bin\x64\Debug\v141\dynamic\libzmq.lib;%(AdditionalDependencies)

7) put the libzmq.dll and the jzmq.dll in the system32 folder.

完成安装后,我尝试运行简单的Java示例以查看一切是否正常:
Java代码:

import org.zeromq.ZMQ;
import java.nio.charset.Charset;

public class TestMainClass {

public static void main(String[] args){
    try {
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket replier = context.socket(ZMQ.REP);
        replier.bind("tcp://*:5559");

        while (true) {

            String gwSource = replier.recvStr(Charset.defaultCharset());
            replier.send("OK");
            System.out.println(gwSource);
        }
    }catch (Throwable e) {
        System.out.println(e);
    }
  }
}

import org.zeromq.ZMQ;

public class Requester {

public static void main(String[] args){
    ZMQ.Context context = ZMQ.context(1);
    ZMQ.Socket replier = context.socket(ZMQ.REQ);
    replier.connect("tcp://localhost:5559");

    while (true) {
        replier.send("public");
        System.out.println(new String(replier.recv()));
    }
  }
}

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

<groupId>com.test.hagar</groupId>
<artifactId>hagarTestRealTick</artifactId>
<version>current-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.zeromq</groupId>
        <artifactId>jzmq</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

</project>

领事输出:

对于TestMainClass:

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Xcheck:jni -verbose:jni "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.1\lib\idea_rt.jar=57531:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Fil
WARNING in native method: JNI call made without checking exceptions when required to from CallLongMethodV
at org.zeromq.ZMQ$Socket.construct(Native Method)
at org.zeromq.ZMQ$Socket.<init>(ZMQ.java:1719)
at org.zeromq.ZMQ$Context.socket(ZMQ.java:451)
at TestMainClass.main(TestMainClass.java:11)
[Dynamic-linking native method org.zeromq.ZMQ$Socket.bind ... JNI]
[Dynamic-linking native method org.zeromq.ZMQ$Socket.recv ... JNI]

Process finished with exit code -1073740791 (0xC0000409)

对于请求者:

[Registering JNI native method java.lang.System.arraycopy]
[Dynamic-linking native method java.lang.Thread.registerNatives ... JNI]
[Registering JNI native method java.lang.Thread.start0]
WARNING in native method: JNI call made without checking exceptions when required to from CallLongMethodV
at org.zeromq.ZMQ$Socket.construct(Native Method)
at org.zeromq.ZMQ$Socket.<init>(ZMQ.java:1719)
at org.zeromq.ZMQ$Context.socket(ZMQ.java:451)
at Requester.main(Requester.java:8)
[Dynamic-linking native method org.zeromq.ZMQ$Socket.connect ... JNI]
[Dynamic-linking native method org.zeromq.ZMQ$Socket.send ... JNI]  
[Dynamic-linking native method org.zeromq.ZMQ$Socket.recv ... JNI]

TestMainClass尝试接收响应并打印后,程序崩溃:进程结束,退出代码为-1073740791(0xC0000409)

我认为安装失败是导致失败的原因,但我找不到问题。

好的,Alea Acta Est:

如何调试根本原因?

级别0:首先仅发送int -s而不是任何string -s(其中具有不同的附加字符集问题)

级别1 :尝试.recv()方法的非阻塞模式(其中,从.recv()方法调用的非阻塞模式返回的.recv()将最终证明ZeroMQ部分不是问题)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM