Justin Lange
Justin Lange

Reputation: 907

The import org.zeromq cannot be resolved, what can I do?

The import org.zeromq cannot be resolved, what can I do?

Im trying to Subscribe ZMQ for my web app. First time working with ZMQ and im getting a little frusty. Can anybody help?

It has been a while since I used Java the last time.

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

/**
* Pubsub envelope subscriber
*/

public class psenvsub {

    public static void main (String[] args) {

        // Prepare our context and subscriber
        Context context = ZMQ.context(1);
        Socket subscriber = context.socket(ZMQ.SUB);

        subscriber.connect("tcp://localhost:5563");
        subscriber.subscribe("B".getBytes());
        while (!Thread.currentThread ().isInterrupted ()) {
            // Read envelope with address
            String address = subscriber.recvStr ();
            // Read message contents
            String contents = subscriber.recvStr ();
            System.out.println(address + " : " + contents);
        }
        subscriber.close ();
        context.term ();
    }
}

Upvotes: 1

Views: 1810

Answers (1)

Nikolai
Nikolai

Reputation: 61

You need to have zeromq implementation. Looks like there are multiple implementations in maven central: https://mvnrepository.com/artifact/org.zeromq

This POM should resolve imports:

<?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>zmq</groupId>
    <artifactId>zmq-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.zeromq/jeromq -->
        <dependency>
            <groupId>org.zeromq</groupId>
            <artifactId>jeromq</artifactId>
            <version>0.4.0</version>
        </dependency>
    </dependencies>

</project>

If you aren't familiar with Maven, read here

Upvotes: 1

Related Questions