Announcement Announcement Module
Collapse
No announcement yet.
Lifecycle Support of MessageBus Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lifecycle Support of MessageBus

    Hello,

    I switched from M3 to M5 and found some differences concerning the lifecycle support of the MessageBus. After starting the MessageBus in M3, all registered MessageHandler and MessageEndpoints which have implemented the Lifecycle interface were also started. In M5 this behavior is missing:

    Code:
        public void testLifecycleMessageTarget() throws Exception {
            MessageBus bus = new DefaultMessageBus();
            MessageChannel channel = new QueueChannel();
            bus.registerChannel("myChannel", channel);
            LifecycleMessageTarget target = new LifecycleMessageTarget();
            bus.registerTarget("myTarget", target, "myChannel", null);
            bus.start();
            Assert.assertTrue("message target was not started", target.isRunning());
            bus.stop();
            Assert.assertFalse("message target was not stopped", target.isRunning());
        }
        
        public void testLifecycleMessageHandler() throws Exception {
            MessageBus bus = new DefaultMessageBus();
            MessageChannel channel = new QueueChannel();
            bus.registerChannel("myChannel", channel);
            LifecycleMessageHandler handler = new LifecycleMessageHandler();
            bus.registerHandler("myHandler", handler, "myChannel", null);
            bus.start();
            Assert.assertTrue("message handler was not started", handler.isRunning());
            bus.stop();
            Assert.assertFalse("message handler was not stopped", handler.isRunning());
        }
    
        public void testLifecycleTargetEndpoint() throws Exception {
            MessageBus bus = new DefaultMessageBus();
            MessageChannel channel = new QueueChannel();
            bus.registerChannel("myChannel", channel);
            TargetEndpoint endpoint = new TargetEndpoint();
            endpoint.setAutoStartup(false);
            endpoint.setName("testEndpoint");
            endpoint.setInputChannel(channel);
            bus.registerEndpoint(endpoint);
            bus.start();
            Assert.assertTrue("target endpoint was not started", endpoint.isRunning());
            bus.stop();
            Assert.assertFalse("target endpoint was not stopped", endpoint.isRunning());
        }
    Thank's,
    Thomas

  • #2
    This behavior was removed after many internal components had been simplified so that they no longer required the cascading lifecycle management. In general, it seemed a bit excessive and potentially confusing that this would happen automatically. Since Spring provides the cascading itself for all Spring-managed objects within an Application Context, global lifecycle management is already a feature of the context. The MessageBus should probably not interfere by adding an extra layer. Also, it is common to manage components' Lifecycles individually (e.g. exporting the component's Lifecycle interface as a JMX MBean).

    Can you describe the way you were using this? We can reconsider this feature and/or possibly another way to support it. For example, a cleaner solution might include an optional callback interface so that an endpoint can receive an "event" when the bus activates/deactivates it, such as:
    Code:
    public interface ActivationAware {
    
        void onActivation();
    
        void onDeactivation();
    
    }
    In fact, another idea that has been floating around for a while is to support the EIP notion of a Control Bus. With that approach, we can reuse the Spring Integration messaging framework to provide "control" Messages.

    Please describe the use-case(s) you have in mind, and if the discussion here leads to some good ideas, we can then open a JIRA issue.

    Regards,
    Mark

    Comment


    • #3
      Hi Mark,

      many thanks for your fast reply.
      I'm currently using my own messaging layer within my application. This looks very similar to the implementation of SI. At the moment I'm thinking about to replace my implementation with yours.
      Some words to my application:
      I have several components that can send and receive messages among each other. All components are managed by a message bus. The message bus itself are placed in a session pool. When a new session starts, an available message bus will be obtained from the pool and starts working. Some of the managed components will send messages at startup. Thus I need a way to trigger a "start event" for that. Currently I want to use the Lifecycle interface for that but your suggestion with the callback interface sounds better.
      It would be very nice if you can implement this in one of the next releases.

      Regards,
      Thomas

      Comment


      • #4
        Thomas,

        Please raise an issue for this in JIRA. I'm personally interested in pursuing the idea of sending a start/stop (among others) "control" Message. Does that seem appropriate?

        -Mark

        Comment


        • #5
          Do we have a jira created for this or a solution already in place ?

          Comment


          • #6
            ... long time ago.
            Yes, I raised an issue: https://jira.springframework.org/browse/INT-350
            But in the meantime there is no MessageBus anymore.

            ~Thomas

            Comment


            • #7
              I just posted a comment on that JIRA issue. I think we should resolve it actually. Please let me know what you think.

              Another interesting one is the new "Control Bus". That supports the sending of messages with command payloads, such as "@someEndpoint.stop()".

              Comment

              Working...
              X