FAQ
Hi All!
Can I configure a bolt (and spout too) to be created lazily (on workers,
not on nimbus) to avoid serialization problems?
My bolt use a class from external library which is not serializable. I know
I can use "prepare" method to do an instantiation of service are used by
the bolt, but it means I have to put all dependency creation logic to the
bolt and violate the Single Responsibility Principle. I want the bolt to be
focused on business logic, not on dependencies creation one. Additional consequence
of such "prepare" method usage is that bold will be hard to test because of
dependency is a concrete classes, I will have no opportunity to replace
them with mocks.

One of solution is not to instantiate bolt and spout classes during
topology creation. TopologyBuilder should use factories or to be integrated
with IoC framework (like Spring or Guice).
Anyway it is hard to understand why I have to instantiate bolds and spouts
on topology creation phase instead of just creating some kind topology
description (xml, json, etc) which does not need serialization at all! Just
move plain vanilla text description to workers ;)

Search Discussions

  • Nathan Marz at Jan 13, 2013 at 5:39 am
    You can easily create a bolt which implements exactly that and delegates to
    another bolt created from some BoltFactory.
    On Fri, Jan 11, 2013 at 1:36 AM, Stanislav Tyurikov wrote:

    Hi All!
    Can I configure a bolt (and spout too) to be created lazily (on workers,
    not on nimbus) to avoid serialization problems?
    My bolt use a class from external library which is not serializable. I
    know I can use "prepare" method to do an instantiation of service are used
    by the bolt, but it means I have to put all dependency creation logic to
    the bolt and violate the Single Responsibility Principle. I want the bolt
    to be focused on business logic, not on dependencies creation one.
    Additional consequence of such "prepare" method usage is that bold will
    be hard to test because of dependency is a concrete classes, I will have no
    opportunity to replace them with mocks.

    One of solution is not to instantiate bolt and spout classes during
    topology creation. TopologyBuilder should use factories or to be integrated
    with IoC framework (like Spring or Guice).
    Anyway it is hard to understand why I have to instantiate bolds and spouts
    on topology creation phase instead of just creating some kind topology
    description (xml, json, etc) which does not need serialization at all! Just
    move plain vanilla text description to workers ;)


    --
    Twitter: @nathanmarz
    http://nathanmarz.com
  • Aaron Zimmerman at Jun 28, 2013 at 12:14 am
    Can you explain this a bit more? Is there a way to create a bolt without
    creating non-serializable dependencies in the Prepare (or Spout.open()) ?

    I am using Guice for dependency injection - so I have an Injector that is
    built with different modules (which are bindings of interfaces to
    implementations thereof). Is there a way I can pass this injector to the
    prepare method? That way the bolt can use that injector to get instances
    of the classes it needs, without having to know the specific
    implementations. Rather than Database db = new Database("Connection
    String"), i need to say Database db = injector.getInstance(Db.class).

    https://github.com/nathanmarz/storm/issues/155 is perhaps what I'm after.
      Being over a year old, I was thinking it might have been discarded in
    favor of a different mechanism though.


    On Saturday, January 12, 2013 11:39:34 PM UTC-6, nathanmarz wrote:

    You can easily create a bolt which implements exactly that and delegates
    to another bolt created from some BoltFactory.

    On Fri, Jan 11, 2013 at 1:36 AM, Stanislav Tyurikov <
    stanislav...@gmail.com <javascript:>> wrote:
    Hi All!
    Can I configure a bolt (and spout too) to be created lazily (on workers,
    not on nimbus) to avoid serialization problems?
    My bolt use a class from external library which is not serializable. I
    know I can use "prepare" method to do an instantiation of service are used
    by the bolt, but it means I have to put all dependency creation logic to
    the bolt and violate the Single Responsibility Principle. I want the bolt
    to be focused on business logic, not on dependencies creation one.
    Additional consequence of such "prepare" method usage is that bold will
    be hard to test because of dependency is a concrete classes, I will have no
    opportunity to replace them with mocks.

    One of solution is not to instantiate bolt and spout classes during
    topology creation. TopologyBuilder should use factories or to be integrated
    with IoC framework (like Spring or Guice).
    Anyway it is hard to understand why I have to instantiate bolds and
    spouts on topology creation phase instead of just creating some kind
    topology description (xml, json, etc) which does not need serialization at
    all! Just move plain vanilla text description to workers ;)


    --
    Twitter: @nathanmarz
    http://nathanmarz.com
    --
    You received this message because you are subscribed to the Google Groups "storm-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to storm-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupstorm-user @
postedJan 13, '13 at 5:32a
activeJun 28, '13 at 12:14a
posts3
users3
websitestorm-project.net
irc#storm-user

People

Translate

site design / logo © 2022 Grokbase