Skip to content

timer functions should be bound-fns to allow eventbus replies to work #126

@cocodrino

Description

@cocodrino

hi...when I run this code I get an error

server

(ns httpServerSlow
  (:require [vertx.http :as http]
            [vertx.eventbus :as ev]))



(ev/set-default-reply-timeout! 10000)

(defn req-handler [req]
  (println "got request")
  (ev/send "slowVerticle:hi" "hello"
           (fn [msg]
             (-> (http/server-response req)
                 (http/end msg)))))


(-> (http/server) (http/on-request req-handler) (http/listen 8080 "localhost"))

verticle

(ns yourvertxproject.slowVerticles
  (:require [vertx.core :as vertx]
            [vertx.eventbus :as bus]
            [vertx.eventbus :as eb]))

(bus/on-message
  "slowVerticle:hi"
  (fn [m]
    (println "recibido mensaje " m)
    (vertx/timer 5000 (eb/reply "hello back"))))
Unexpected exception in Clojure verticle 
java.lang.NullPointerException
    at vertx.eventbus$reply_STAR_.invoke(eventbus.clj:225)
    at vertx.eventbus$reply.invoke(eventbus.clj:249)
    at yourvertxproject.slowVerticles$eval359$fn__360$fn__361.invoke(slowVerticles.clj:10)
    at vertx.core$as_handler$fn__234.invoke(core.clj:97)
    at vertx.core$as_handler$reify__238.handle(core.clj:101)
    at org.vertx.java.core.impl.DefaultVertx$InternalTimerHandler.run(DefaultVertx.java:432)
    at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
    at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:123)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

Unexpected exception in Clojure verticle 
java.lang.NullPointerException
    at vertx.eventbus$reply_STAR_.invoke(eventbus.clj:225)
    at vertx.eventbus$reply.invoke(eventbus.clj:249)
    at yourvertxproject.slowVerticles$eval359$fn__360$fn__361.invoke(slowVerticles.clj:10)
    at vertx.core$as_handler$fn__234.invoke(core.clj:97)
    at vertx.core$as_handler$reify__238.handle(core.clj:101)
    at org.vertx.java.core.impl.DefaultVertx$InternalTimerHandler.run(DefaultVertx.java:432)
    at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
    at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:123)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:745)

the problem fixes when I use directly timer*

(vertx/timer* 5000 (bound-fn [_] (eb/reply "hello back")))

the bound-fn is also required

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions