Announcement Announcement Module
Collapse
No announcement yet.
polling service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    http://static.springsource.org/sprin...cheduled-tasks

    Comment


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

      Thanks

      Comment


      • #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"): http://static.springsource.org/sprin...ices-namespace

        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?

        Comment


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

          Comment


          • #6
            Hi

            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.

            regards
            Grzegorz Grzybek

            Comment


            • #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="com.soamods.jsec.services.PollingTest"/>

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

              PollingTest is a simple POJO with getMessage1 method.

              Comment


              • #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(UnicastingDispatcher.java :97)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:9 0)
                at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:43)
                at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:116)
                at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:94)
                at org.springframework.integration.channel.MessageCha nnelTemplate.doSend(MessageChannelTemplate.java:22 3)
                at org.springframework.integration.channel.MessageCha nnelTemplate.send(MessageChannelTemplate.java:180)
                at org.springframework.integration.endpoint.SourcePol lingChannelAdapter.doPoll(SourcePollingChannelAdap ter.java:78)
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$Poller.innerPoll(AbstractPollingEnd point.java:232)
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$Poller.poll(AbstractPollingEndpoint .java:216)
                at org.springframework.integration.endpoint.AbstractP ollingEndpoint$Poller.run(AbstractPollingEndpoint. java:209)
                at org.springframework.integration.scheduling.SimpleT askScheduler$ErrorHandlingRunnableWrapper.run(Simp leTaskScheduler.java:307)
                at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:441)
                at java.util.concurrent.FutureTask$Sync.innerRunAndRe set(FutureTask.java:317)
                at java.util.concurrent.FutureTask.runAndReset(Future Task.java:150)
                at org.springframework.integration.scheduling.SimpleT askScheduler$TriggeredTask.run(SimpleTaskScheduler .java:256)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
                at java.lang.Thread.run(Thread.java:619)

                Comment


                • #9
                  Hi

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

                  add:
                  • <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!

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

                  Comment


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

                    SEVERE: org.springframework.integration.channel.ChannelRes 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 tractReplyProducingMessageHandler.java:142)
                    at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:102)


                    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 ?

                    Comment


                    • #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 org.springframework.ws.transport.jms.JmsMessageSen der as WebServiceMessageSender.

                      tell then if it helps!

                      regards
                      Grzegorz Grzybek

                      Comment


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

                        Comment


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

                          regards
                          Grzegorz Grzybek

                          Comment


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

                            Comment


                            • #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:
                              http://jira.springframework.org/browse/INT-861

                              Comment

                              Working...
                              X