Announcement Announcement Module
Collapse
No announcement yet.
synchronous messages ala observer pattern Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment

        Working...
        X