Vertx best practices?

531 views
Skip to first unread message

gal.ch...@web-pick.com

unread,
Oct 13, 2016, 3:49:27 AM10/13/16
to vert.x
Hello,

I have a Vertx java application consisting of 7 Verticles.

I need to access the event bus from all of the Verticles, a lot of the times from a static function.

to do so, today, when a Verticle starts, we call a static function which stores the Vertx object in a static field,
because of the class loader isolation, we do this in all 7 verticles.

It works, but it looks awful, every time we want to access the event bus, we use VertxStatic.getVertx().eventBus().

I wanted to ask if there is a more elegant solution you guys are using.

Thanks,
Gal.

Clement Escoffier

unread,
Oct 13, 2016, 4:19:14 AM10/13/16
to ve...@googlegroups.com
Hi,

It’s probably a stupid idea but what about passing the vertx object or the eventbus object as parameter of your static function ?

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/73f83994-8537-4571-9e1f-40a3feb2ff41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jochen Mader

unread,
Oct 13, 2016, 4:30:35 AM10/13/16
to ve...@googlegroups.com
I don't really get the problem.
Why do you have to access the eventbus in that way?
Do you have a code sample for us so we can see what you are doing?

2016-10-13 10:19 GMT+02:00 Clement Escoffier <clement....@gmail.com>:
Hi,

It’s probably a stupid idea but what about passing the vertx object or the eventbus object as parameter of your static function ?

Clement
On 13 Oct 2016, at 09:49, gal.ch...@web-pick.com wrote:

Hello,

I have a Vertx java application consisting of 7 Verticles.

I need to access the event bus from all of the Verticles, a lot of the times from a static function.

to do so, today, when a Verticle starts, we call a static function which stores the Vertx object in a static field,
because of the class loader isolation, we do this in all 7 verticles.

It works, but it looks awful, every time we want to access the event bus, we use VertxStatic.getVertx().eventBus().

I wanted to ask if there is a more elegant solution you guys are using.

Thanks,
Gal.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jochen Mader | Lead IT Consultant

codecentric AG | Elsenheimerstr. 55a | 80687 München | Deutschland
tel: +49 89 215486633 | fax: +49 89 215486699 | mobil: +49 152 51862390
www.codecentric.de | blog.codecentric.de | www.meettheexperts.de | www.more4fi.de

Sitz der Gesellschaft: Düsseldorf | HRB 63043 | Amtsgericht Düsseldorf
Vorstand: Michael Hochgürtel . Mirko Novakovic . Rainer Vehns
Aufsichtsrat: Patric Fedlmeier (Vorsitzender) . Klaus Jäger . Jürgen Schütz

Jez P

unread,
Oct 13, 2016, 5:37:42 AM10/13/16
to vert.x
Every verticle has a reference to the vertx object anyway, so why not just use that?

Jez P

unread,
Oct 13, 2016, 5:39:05 AM10/13/16
to vert.x
Ah wait, you're using a static function? In which case I would either make the vertx or the eventbus a parameter of that function. The point of making a function static is surely to avoid using state. 
Reply all
Reply to author
Forward
0 new messages