Class Publisher

  • All Implemented Interfaces:
    io.zenoh.session.SessionDeclaration , java.lang.AutoCloseable

    
    public final class Publisher
     implements SessionDeclaration, AutoCloseable
                        

    A Zenoh Publisher.

    A publisher is automatically dropped when using it with the 'try-with-resources' statement (i.e. 'use' in Kotlin). The session from which it was declared will also keep a reference to it and undeclare it once the session is closed.

    In order to declare a publisher, Session.declarePublisher must be called.

    Example:

    try (Session session = Session.open()) {
        try (KeyExpr keyExpr = KeyExpr.tryFrom("demo/java/greeting")) {
            System.out.println("Declaring publisher on '" + keyExpr + "'...");
            try (Publisher publisher = session.declarePublisher(keyExpr)) {
                int i = 0;
                while (true) {
                    publisher.put("Hello for the " + i + "th time!");
                    Thread.sleep(1000);
                    i++;
                }
            }
        }
    } catch (ZError | InterruptedException e) {
        System.out.println("Error: " + e);
    }

    The publisher configuration parameters can be later changed using the setter functions.