Announcement Announcement Module
Collapse
No announcement yet.
How do i get Number of subscribers in a channel ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do i get Number of subscribers in a channel ?

    How do i get the number of subscribers registered to a channel ?

    When i look at the code i see a list maintaining the subscribers but i am not not able to use this info to get the count on these .Why are these made private ?

    Why isn't the number of subscribers info hidden in a pub -sub channel ?

    I have use cases where based on the number of subscribers, i start my listeners. which need to listen to queue dynamically.

  • #2
    Originally posted by sudheerk84 View Post
    I have use cases where based on the number of subscribers, i start my listeners. which need to listen to queue dynamically.
    Can you describe this use-case in more detail? I am wondering if it's relevant to the "Control Bus" idea that we are considering for 2.0. I would like to first know exactly what functionality you need - for which you are planning to use the subscriber count.

    Thanks,
    Mark

    Comment


    • #3
      Hi Mark,

      My Usecase:

      I do not want to attach my jms:message-driven-channel-adapter to the channel during initialization , Instead I would like to do it at runtime ,if any subscriber subscribes to this channel. (This makes my code generic)

      Also I would want to stop this jms:message-driven-channel-adapter listening to the JMS queue when there are no subscribers to the channel.

      I am looking at registering this jms-message-driven adapter at runtime using
      StaticApplicationContext.html#registerSingleton(ja va.lang.String, java.lang.Class)

      Is there any easier way to achieve this ?

      Currently since I have no options. I will have to use AOP and maintain the count for each channel which would be much easier provided by Channel.

      Comment


      • #4
        Also can you give some idea about this "Control Bus"

        Thanks & Regards

        Comment


        • #5
          I would not recommend calling registerSingleton() directly. It would require that you manage the full lifecycle of that component as well as dealing with potential synchronization issues. You should be able to accomplish what you need by simply calling start() and stop() on the JMS endpoint and setting 'auto-startup' to false on the XML element. If I understand correctly, you don't really need the actual number of subscribers, you just need to know when it changes from/to 0, correct?

          The idea behind the "control bus" is that it allows us to reuse the same messaging system to send control event messages between components. That is one of the topics from the EIP book (see: http://enterpriseintegrationpatterns...ontrolBus.html), and we have several potential uses for that in 2.0. The events on subscribe/unsubscribe are certainly good candidates.

          Regards,
          Mark

          Comment


          • #6
            Thanks a lot Mark.


            Just trying to understand what you said

            <jms:message-driven-channel-adapter
            id="jmsout" destination="sendDestination" channel="jmsOutChannel"
            auto-startup="false"
            />

            So I need to inject this bean to required class and call start stop on it based on my requirement.

            And for the second question you asked

            Yes , i want notifications only when the subscriber count reaches

            1. 0 from 1
            2. 1 from 0

            Any chances of supporting this in the future release ?

            Comment

            Working...
            X