Announcement Announcement Module
No announcement yet.
polling service Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • polling service

    Hi All,

    I have a database table on which I have a trigger which gets fired when the table is inserted or updated, and populate a record in another table, say a notifications table.

    I want a polling service which will lookup the notifications table, on a specified interval, continuously.

    Please let me know how can I implement a polling service using Spring?

    I am posting this on Spring Integration because I guess this kind of things I guess is a part of integration.

  • #2
    What are you planning to do after polling for that data? If you want to create a Message and send it to a channel, then Spring Integration is a good choice.

    If you want to use Spring Integration, you can create an <inbound-channel-adapter/> with "ref" and "method" attributes pointing to the object/method that performs the query (in 2.0 we will be adding a JDBC inbound-channel-adapter so you only need to configure the query itself).

    If you don't need to create and send a Message from the result of your query, then in Spring 3.0, you can provide a scheduled task by using the new 'task' namespace. See the reference manual for details:


    • #3
      I would be forming a object of xmlbeans using the fetched data, I am using xmlbeans marshaller.

      And then I need to wrap this object (xmlbeans) into soap envelope tags ? any idea how to do this ? and send it to a ActiveMQ queue.

      I guess I need to go with Spring Integration, right ?

      I have downloaded Spring Integration 2.0.0.M1, does it have JDBC inbound-channel-adapter ? if yes, could you point me to an example ?



      • #4
        The JDBC inbound-channel-adapter is not yet available in M1, but it will be available in a later milestone (hopefully M2).

        If you are going to be using this in production prior to the final 2.0 release, I would suggest sticking with 1.0.x and simply referring to your own method from an <inbound-channel-adapter/> element for now.

        Otherwise, this does indeed sound like a good case for Spring Integration. You can check out the WS <outbound-gateway/> examples here (specifically the one that uses a "marshaller"):

        Do you need to add anything custom within SOAP headers, or is it just to prepare a valid message for a SOAP Web Service invocation?


        • #5
          No I don't need to add anything in the SOAP Header, its just to prepare a valid soap message for a SOAP Web Service invocation


          • #6

            And after sending your message you could simply use Spring-WS WebServiceTemplate. This class has methods similar to marshallSendAndReceive() which uses your marshaller to create valid XML message with Soap envelope wrapper.

            Grzegorz Grzybek


            • #7
              Thanks Grzegorz for the reply.

              Any idea on <inbound-channel-adapter/> configuration, I couldn't configure it for polling. any idea on this ?

              Below is the configuration that I did :
              <bean id="pollingTest" class=""/>

              <si:inbound-channel-adapter id="testAdapt" ref="pollingTest" method="getMessage1">
              <si:interval-trigger interval="5" time-unit="SECONDS"/>

              PollingTest is a simple POJO with getMessage1 method.


              • #8
                Sorry forgot to mention, this is the error I am getting.

                27 Oct, 2009 11:40:45 AM org.springframework.integration.handler.LoggingHan dler handleMessageInternal
                SEVERE: org.springframework.integration.message.MessageDel iveryException: Dispatcher has no subscribers.
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch( :97)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch( 0)
                at bscribableChannel.doSend(AbstractSubscribableChann
                at ssageChannel.send(
                at ssageChannel.send(
                at nnelTemplate.doSend( 3)
                at nnelTemplate.send(
                at org.springframework.integration.endpoint.SourcePol lingChannelAdapter.doPoll(SourcePollingChannelAdap
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$Poller.innerPoll(AbstractPollingEnd
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$Poller.poll(AbstractPollingEndpoint .java:216)
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$ java:209)
                at org.springframework.integration.scheduling.SimpleT askScheduler$
                at java.util.concurrent.Executors$ l(
                at java.util.concurrent.FutureTask$Sync.innerRunAndRe set(
                at java.util.concurrent.FutureTask.runAndReset(Future
                at org.springframework.integration.scheduling.SimpleT askScheduler$ .java:256)
                at java.util.concurrent.ThreadPoolExecutor$ Task(
                at java.util.concurrent.ThreadPoolExecutor$ (


                • #9

                  You should configure output channel to your inbound-channel-adapter. Poller has to have some channel to send the message to.

                  • <channel id="c1" />
                  • <service-activator input-channel="c1" ref="service1" />
                  • <bean id="service1" class="xxx" /> with class which have method with @ServiceActivator annotation and argument matching the message you are going to pass to remote webservice
                  • "channel" attribute to your inbound-channel-adapter

                  Implement your service activator to use Spring-WS WebServiceTemplate

                  and that's all!

                  Grzegorz Grzybek
                  Last edited by Grzegorz Grzybek; Oct 27th, 2009, 01:59 AM.


                  • #10
                    Thanks Grzegorz, I got it working .. but it throws me the below exception

                    SEVERE: olutionException: unable to resolve reply channel for message: [Payload=Abdullah][Headers={springintegration_timestamp=1256626115993 , springintegration_id=9c530ab7-3a1b-4826-bed5-3d1a503c6f21}]
                    at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.resolveReplyChannel(Abs
                    at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A

                    What I just want is the polling service, which will poll the database, process the data that I will get from the database, and send to an ActiveMQTopic wrapped with Soap Envelope tags.

                    Am I heading in right direction ? or missing something ?


                    • #11
                      It seams that your ServiceActivator method returns something.

                      The method in class referenced in <service-activator /> should have @ServiceActivator annotation, parameter matching your message. If it returns something, Spring-Integration thinks that your ServiceActivator is a component that does something with the message and tells that the procesing is not finished. If your method returns void it means that the processing is finished.

                      So use WebServiceTemplate configured with der as WebServiceMessageSender.

                      tell then if it helps!

                      Grzegorz Grzybek


                      • #12
                        Yes you are right, the ServiceActivator method was returning a string, I have changed it to return void.

                        But now inbound-channel-adapter doesn't seem to comply with the interval set in poller, it just runs continuously, I have set the interval="30" & time-unit="SECONDS".

                        Any idea what can be wrong here ?


                        • #13
                          There's one tricky attribute in <poller /> - max-messages-per-poll.

                          Set it to "1". Otherwise poller will try (every 30 seconds) to acquire "max-messages-per-poll" messages which is ... unlimited.

                          This is good for sources which produce messages that disappear after their retrieval, but not in case of databases

                          Grzegorz Grzybek


                          • #14
                            I set the max-messages-per-poll, its working fine .. thanks a lot Grzegorz


                            • #15
                              Glad to see that you got this working. It would be nice if you could rely on the WS <outbound-gateway/> instead of a custom Service Activator. You should be able to provide a JMS Message Sender reference in the "message-sender" attribute. Then, if you need no response, you could set the reply-channel on the gateway to "nullChannel".

                              However, we ideally need a uni-directional "outbound-channel-adapter" for Web Services as well as the outbound-gateway. If that's useful to you, feel free to raise an issue. It would be very similar to the following: