java.library.path 中没有 jzmq

No jzmq in java.library.path

我在一个交易引擎上工作,在 运行 时,我从 engine.log 获取日志,如下所示,

2018_01_02_03_28_20_684 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - no jzmq in java.library.path, sleeping 2 minutes then try again
2018_01_02_03_28_20_697 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_30_20_696 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_30_20_710 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_32_20_697 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_32_20_711 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_34_20_698 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_34_20_712 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_36_20_699 INFO  ZMQCommunicatorService REMOTE_EXECUTOR_MARKET_ADMIN-ALL_MARKETS-0-5 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again
2018_01_02_03_36_20_713 INFO  ZMQCommunicatorService ENGINE_MARKET_ADMIN-ALL_MARKETS-0-4 - Could not initialize class org.zeromq.ZMQ, sleeping 2 minutes then try again

我相信第一行说明了主要问题,

No jzmq in java.library.path

我按照 ZMQ binding 的安装手册为 Java、

cd /root
wget https://github.com/zeromq/jzmq/archive/v3.1.0.tar.gz -O jzmq-3.1.0.tar.gz
tar zxf jzmq-3.1.0.tar.gz
cd jzmq-3.1.0
./autogen.sh
./configure --prefix=/opt/jzmq-3.1.0
nice make
make install

加载项目后,需要运行项目根目录中的命令,

root@debian:~# export LD_LIBRARY_PATH=/opt/jzmq-3.1.0/lib

root@debian:~# java -Xss256k -cp /opt/jzmq-3.1.0/share/java/zmq.jar:draglet-common/target/lib/*:draglet-balser/target/lib/*:draglet-engine/target/lib/*:draglet-remote/target/lib/*:draglet-mapu/target/lib/*:draglet-shaba/target/lib/*:draglet-meba/target/lib/* -Dlog4j.configurationFile=draglet-common/src/main/resources/log4j2.xml -DisThreadContextMapInheritable=true com.draglet.batch.Batch draglet.yml

当时我得到这样的输出,

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

Tue Jan 02 03:59:17 EST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

问题是否与Intellij终端中提供的警告有关?如何检查 jzmq 是否在 java.library.path?

好的。那么,让我们一起动手吧:

在您的机器上查看,在适当的安装后是否可以正常工作:

最简单的形式原型之一是 REQ/REP 示例,它使用两部分,一个 - “server":

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

public class rrserver{
    public static void main (String[] args) {
        Context context = ZMQ.context(1);

        //  Socket to talk to clients
        Socket responder  = context.socket(ZMQ.REP);
        responder.bind("tcp://localhost:5560");

        System.out.println("launch and connect server.");

        while (!Thread.currentThread().isInterrupted()) {
            //  Wait for next request from client
            byte[] request = responder.recv(0);
            String string = new String(request);
            System.out.println("Received request: ["+string+"].");

            //  Do some 'work'
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //  Send reply back to client
            responder.send("World".getBytes(), 0);
        }

        //  We never get here but clean up anyhow
        responder.close();
        context.term();
    }
}

还有一部分,一个“客户端”:

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

public class rrclient{

    public static void main(String[] args) {
        Context context = ZMQ.context(1);

        //  Socket to talk to server
        Socket requester = context.socket(ZMQ.REQ);
        requester.connect("tcp://localhost:5560"); // REF ABOVE AND LET START THIS AFTER "server"

        System.out.println("launch and connect client.");

        for (int request_nbr = 0; request_nbr < 10; request_nbr++) {
            requester.send("Hello", 0);
            String reply = requester.recvStr(0);
            System.out.println("Received reply " + request_nbr + " [" + reply + "]");
        }

        //  We never get here but clean up anyhow
        requester.close();
        context.term();
    }
}

这应该会启动,运行 很快就会显示安装是否正确。代码是从 ZeroMQ 发布的简单示例中借用的,以获取灵感。

如果真的想进入分布式计算领域,请毫不犹豫地阅读 Pieter HINTJENS 的一本好书,"Code Connected, Volume 1"(也提供 pdf 格式)。值得花时间和精力。

在 OSX 我遇到了类似的问题。我安装了 ZMQ using these instructions.

最后一步说用-Djava.library.path=/usr/local/lib设置库路径。

我发现将路径简单地添加到

中要容易得多
~/.bash_profile

例如:

echo "export JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:/usr/local/lib" >> ~/.bash_profile

重启 Intellij 后可以正确找到 libjzmq.

此外,如果您打算进行任何 C/C++ 开发,导出 DYLD_LIBRARY_PATH 可能是个好主意。

只需添加

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib"

~/.bash_profile.