1

我正在尝试在我的 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 尝试接收响应并打印后程序崩溃: Process finished with exit code -1073740791 (0xC0000409)

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

4

1 回答 1

0

好的,Alea Acta Est:

如何调试根本原因?

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

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

于 2017-08-15T15:00:09.527 回答