Results 1 to 4 of 4

Thread: synchronous messages ala observer pattern

  1. #1

    Default synchronous messages ala observer pattern

    I looked over some of the issues open and closed around synchronous messages. I would like to have observer pattern messages dumped into a channel and have observers register for events from that observed source. This part is relatively easy. However, I do not see an easy way to configure synchronous handling in spring integration using the semantics described below:

    a) Subject begins to issue a change event e.g. a property change.
    b) The Subject sends the change event to the well-known observer channel.
    c) The subject send method blocks until the event is completely handled from all handlers whether or note the handlers are executed in the same thread or not.
    d) The Observer may modify the event but no burden should be placed on it for creating a reply message of any sort.

    Both the Subject and Observer would be relatively plain POJOs with the Subject knowing about the well-known observer channel but the Observer is subscribed to the desired event using a non-spring API (its easy to write a small adapter for the Observer).

    The use case scenario is similar to observing property change events using the property change listener pattern in plain Java. Sometimes, but now always, and for some event types, the Subject needs to inspect the event object for changes only after all handlers (if any) have completely fired.

    Any easy ways to do this?

  2. #2
    Join Date
    Oct 2007
    Location
    Toronto, ON
    Posts
    90

    Default

    You can try using a <direct-channel/> or a chain of <direct-channel/> objects. In this case, the message send() and the handler (or handlers) will execute synchronously (i.e. in the same thread).

    -- Marius
    Marius Bogoevici,
    Spring Integration Committer

  3. #3

    Default

    Does the direct channel also force the endpoint wrapper to run synchronously as well? My understanding is that if I add a handler to the channel, the bus wraps the handler in a DefaultMessageEndpoint which runs the handling in its own thread as near as I can tell from the code.

  4. #4
    Join Date
    Oct 2007
    Location
    Toronto, ON
    Posts
    90

    Default

    The SynchronousChannel in M3 should work just fine and dispatch the message directly to the handler (in the same thread). That being said, there were significant changes in that area in preparation for M4, so one way to go is to get the latest snapshot or just wait for M4 which is due in the coming days.

    -- Marius
    Marius Bogoevici,
    Spring Integration Committer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •