Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cocodrino opened this issue Feb 11, 2015 · 3 comments
Closed
Milestone

Comments

@cocodrino
Copy link

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

@stream-iori
Copy link
Member

Excellent. i have make more simple example, for test this issue

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

(eb/set-default-reply-timeout! 5000)

(eb/on-message "eb.address"
           (fn [m]
             (println "recibido mensaje " m)
             (vertx/timer 1000 (eb/reply "hello back")))
           (fn [_]
             (println "send message")
             (eb/send "eb.address" "hello" (fn [msg] (println msg)))))

Master branch have fixed this tiny bug, waiting Toby make release.

@tobias
Copy link
Contributor

tobias commented Feb 12, 2015

@cocodrino thanks for the report, and @stream1984 thanks for the fix. I'll merge the fix in, but don't think it's worth making a release right now, especially since an easy workaround (using bound-fn) exists. I'll leave this issue open until we do release, in case anyone else stumbles over the issue.

@tobias
Copy link
Contributor

tobias commented Feb 12, 2015

Ah, right, there's nothing to merge in, since @stream1984 has push rights. So this is already fixed on master.

@tobias tobias modified the milestone: 1.0.5 Feb 27, 2015
@tobias tobias changed the title timer macro seems not works timer functions should be bound-fns to allow eventbus replies to work Mar 31, 2015
@tobias tobias closed this as completed Apr 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants