Announcement Announcement Module
Collapse
No announcement yet.
spring integration spring-integration-2.1.0.RC1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring integration spring-integration-2.1.0.RC1

    Hello,

    1. Kindly let me know about a good link explains about channels, service activators, inbound - outbound with sample configurations.

    2. While trying sample code for spring integration gives an error of "no such method" - looks like some jar is missing - not suire which one. Added all jars which comes with download of spring integration spring-integration-2.1.0.RC1.

    code is below

    public class HelloWorldApp {

    private static Logger logger = Logger.getLogger(HelloWorldApp.class);

    public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
    "dd/helloworlddemo.xml");
    MessageChannel inputChannel = (MessageChannel) context.getBean(
    "inputChannel", MessageChannel.class);
    PollableChannel outputChannel = (PollableChannel) context.getBean(
    "outputChannel", PollableChannel.class);
    inputChannel.send(new GenericMessage<String>("World"));
    logger.info("==> HelloWorldDemo: "
    + outputChannel.receive(0).getPayload());
    }

    }

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/integration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd">


    <channel id="inputChannel"/>

    <channel id="outputChannel">
    <queue capacity="10"/>
    </channel>

    <service-activator input-channel="inputChannel"
    output-channel="outputChannel"
    ref="helloService"
    method="sayHello"/>

    <beans:bean id="helloService" class="com.hcl.sprngintg.HelloService"/>

    </beans:beans>


    3. Any example which has inbound as file with polling and outbound as JMS message or webservice message will be great.


    Thanks

  • #2
    error (no such method) with spring integration 2.1.0.rc1

    Kindly help we are facing same issue - while running spring integration sample - ver 2.1.0.rc1

    (1)
    Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.beans.factory.support.RootBean Definition.<init>(Ljava/lang/StringV
    at org.springframework.integration.config.xml.Default ConfiguringBeanFactoryPostProcessor.registerIdGene ratorConfigurer(DefaultConfiguringBeanFactoryPostP rocessor.java:86)
    at org.springframework.integration.config.xml.Default ConfiguringBeanFactoryPostProcessor.postProcessBea nFactory


    (2)
    import org.springframework.context.support.AbstractApplic ationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.integration.MessageChannel;
    import org.springframework.integration.message.GenericMes sage;


    public class Simple {
    public static void main(String[] args) {
    AbstractApplicationContext context = null;

    context = new ClassPathXmlApplicationContext("dd/simple.xml");


    MessageChannel inChannel = (MessageChannel) context.getBean("numberChannel");
    inChannel.send(new GenericMessage<String>("5"));


    }
    }




    (3)

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xsi:schemaLocation="http://www.springframework.org/schema/integration
    http://www.springframework.org/schem...ntegration.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">


    <int:channel id="stringOrNumberChannel" datatype="java.lang.String,java.lang.Number" />

    </beans>



    (4) how does service activator work?? What is the difference between gateway and adapter???


    thanks

    Comment


    • #3
      1. The reference manual is an excellent source of information you'll need

      2. The github link for the samples has numerous samples which can help you understand things better.

      3. Regarding the exception, what version of spring are you using?

      4. While posting, post all you code between the [ CODE ] [/ CODE ] (without the spaces) tags

      Comment


      • #4
        Amol,

        Answer to your point (3)
        3. Regarding the exception, what version of spring are you using?
        Jars used ->
        spring-integration-core-2.1.0.RC1.jar
        spring-integration-file-2.1.0.RC1.jar
        commons-logging-1.0.4.jar
        spring.jar - ver 3.x

        Kindly let me know correct combination/versions of jars to be used.


        Query -> How does integration between inbound and outbound channel happen? Is it using service activator? Apologies if my question is basic. My doubt we specify different channels for inbound / outbound but still message flow.

        Thanks

        Comment


        • #5
          Amol please find stubs giving exception (nosuchmethod) with above jars
          Please try from your side and let us know.

          --------------------------------------------------
          <code>
          import org.springframework.context.support.AbstractApplic ationContext;
          import org.springframework.context.support.ClassPathXmlAp plicationContext;
          import org.springframework.integration.MessageChannel;
          import org.springframework.integration.message.GenericMes sage;
          public class Simple {
          public static void main(String[] args) {
          AbstractApplicationContext context = null;
          context = new ClassPathXmlApplicationContext("dd/simple.xml");
          MessageChannel inChannel = (MessageChannel) context.getBean("stringOrNumberChannel");
          inChannel.send(new GenericMessage<String>("5"));

          }
          }
          </code>
          --------------------------------------------------


          --------------------------------------------------

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:int="http://www.springframework.org/schema/integration"
          xsi:schemaLocation="http://www.springframework.org/schema/integration
          http://www.springframework.org/schem...ntegration.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd">
          <int:channel id="stringOrNumberChannel" datatype="java.lang.String,java.lang.Number" />
          </beans>
          --------------------------------------------------

          Thanks

          Comment


          • #6
            Looking at your exception I am not sure that your are using Spring 3.x. In fact the exception tells me that you are using Spring 2.5.x since version 3.0 of RootBeanDefinition definitely has a constructor that takes String. So you might be using the wrong version of Spring or you may have two versions on the classpath

            Comment


            • #7
              Also to add to what oleg said, since spring 3.x we no longer have the bit fat jar containing all the classes (unless you have built one yourself). So which spring.jar are you using?
              You will find this class in spring-beans-{VERSION}.RELEASE.jar

              Comment


              • #8
                Thanks Oleg / Amol. As Oleg suggested earlier problem was with wrong version of jar. Examples are running fine. Great framework like openadapter.

                My query serviceactivator - is to couple inbound and outbound channel???

                Myself tried inbound adapter as file adapter and outbound adapter as jms. Basically want to to test read from file and send to queue. But is not happening as expected. Handler class is not getting invoked. If I hook a listener to listen to the queue it is not getting messages.


                configuration-->

                common.xml
                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:integration="http://www.springframework.org/schema/integration"
                xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schem...ring-beans.xsd
                http://www.springframework.org/schema/integration
                http://www.springframework.org/schema/integration/spring-integration.xsd">

                <bean id="connectionFactory"
                class="org.springframework.jms.connection.CachingC onnectionFactory">
                <property name="targetConnectionFactory">
                <bean class="org.apache.activemq.ActiveMQConnectionFacto ry">
                <property name="brokerURL" value="tcp://localhost:61616" />
                </bean>
                </property>
                <property name="sessionCacheSize" value="10" />
                <property name="cacheProducers" value="false" />
                </bean>

                <bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
                <constructor-arg value="queue.request" />
                </bean>

                <bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
                <constructor-arg value="queue.response" />
                </bean>

                <integrationoller id="poller" default="true"
                fixed-delay="1000" />
                </beans>

                ------------------------------------------------------
                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:integration="http://www.springframework.org/schema/integration"
                xmlns:file="http://www.springframework.org/schema/integration/file"
                xmlns:jms="http://www.springframework.org/schema/integration/jms"
                xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schem...ring-beans.xsd
                http://www.springframework.org/schema/integration
                http://www.springframework.org/schem...ntegration.xsd
                http://www.springframework.org/schema/integration/file
                http://www.springframework.org/schem...ation-file.xsd
                http://www.springframework.org/schema/integration/jms
                http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
                <bean
                class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer" />

                <file:inbound-channel-adapter id="filesIn"
                directory="e:\\software\\complete\\"
                filename-pattern="[a-z]+.txt">
                <integrationoller id="poller" fixed-delay="500" />
                </file:inbound-channel-adapter>
                <file:file-to-string-transformer
                input-channel="filesIn" output-channel="strings" />

                <integration:channel id="strings" />
                <integration:channel id="strgToJmsoutChannel" />
                <integration:service-activator input-channel="strings" output-channel="strgToJmsoutChannel" ref="handler" method="handleString" />
                <jms:outbound-channel-adapter id="jmsout" channel="strgToJmsoutChannel" destination="requestQueue" />

                <bean id="handler"
                class="Handler" />
                </beans>


                ----------------------------------------------

                import org.springframework.context.ApplicationContext;
                import org.springframework.context.support.ClassPathXmlAp plicationContext;

                public class TextFileCopyTest {

                private final static String[] configFiles = { "dd/common.xml",
                "dd/fileCopyDemo-text.xml" };

                public void testTextBasedCopy() throws Exception {
                ApplicationContext context = new ClassPathXmlApplicationContext(
                configFiles, TextFileCopyTest.class);
                //FileCopyDemoCommon.displayDirectories(context);
                Thread.sleep(5000);
                }

                public static void main(String[] args) throws Exception {
                TextFileCopyTest test = new TextFileCopyTest();
                test.testTextBasedCopy();
                }

                }
                -------------------------------------------------------------------
                import java.io.File;

                public class Handler {

                public String handleString(String input) {
                System.out.println("***************** Copying text: ************" + input);
                return input.toUpperCase();
                }

                public File handleFile(File input) {
                System.out.println("Copying file: " + input.getAbsolutePath());
                return input;
                }

                public byte[] handleBytes(byte[] input) {
                System.out.println("Copying " + input.length + " bytes ...");
                return new String(input).toUpperCase().getBytes();
                }

                }
                ----------------------------------------------------

                Comment


                • #9
                  Use filename-regex instead of filename-pattern. If you want to use filename-pattern, use the value as *.txt

                  Also, please format you code well to improve the readability of the post.
                  Last edited by Amol Nayak; Dec 23rd, 2011, 11:55 AM. Reason: suggested the formatting of the post before posting

                  Comment


                  • #10
                    Thanks Amol -will try with -> "*.txt" but existing exp should also work?
                    Requirement is channel inbound adapter should read text file -> convert content into string -> send to jms outbound adapter (activemq)

                    Listener on a different machine should be able to receive this message.

                    Comment


                    • #11
                      [a-z]+.txt is a regular expression and not a pattern. *.txt on other hand is a pattern.
                      Now as i said earlier, in order to use [a-z]+.txt, you need to use the filename-regex attribute and not filename-pattern.
                      If you use filename-pattern, one of the the valid values would be *.txt.

                      Comment


                      • #12
                        Thanks Amol - works fine with "*.txt"

                        Requirement was channel inbound adapter should read text file -> convert content into string -> send to jms outbound adapter (activemq)

                        Listener on a different machine should be able to receive this message - listener works fine if I use jms:listener container as shown below

                        <?xml version="1.0" encoding="UTF-8"?>
                        <beans xmlns="http://www.springframework.org/schema/beans"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:jms="http://www.springframework.org/schema/jms"
                        xmlns="http://www.springframework.org/schema/p"
                        xsi:schemaLocation="
                        http://www.springframework.org/schema/beans
                        http://www.springframework.org/schem...ring-beans.xsd
                        http://www.springframework.org/schema/jms
                        http://www.springframework.org/schema/jms/spring-jms.xsd">

                        <bean id="connectionFactory"
                        class="org.apache.activemq.ActiveMQConnectionFacto ry"
                        p:brokerURL="tcp://localhost:61616" />

                        <bean id="simpleMessageListener"
                        class="SimpleMessageListener"/>

                        <jms:listener-container
                        container-type="default"
                        connection-factory="connectionFactory"
                        acknowledge="auto">
                        <jms:listener destination="queue.request"
                        ref="simpleMessageListener" method="onMessage"/>
                        </jms:listener-container>
                        </beans>



                        import javax.jms.Message;
                        import javax.jms.MessageListener;
                        import javax.jms.TextMessage;

                        import org.springframework.context.ApplicationContext;
                        import org.springframework.context.support.ClassPathXmlAp plicationContext;


                        public class SimpleMessageListener implements MessageListener {


                        public void onMessage(Message message)
                        {
                        TextMessage msg= (TextMessage)message;
                        System.out.println("received message is *********" + msg.toString());
                        }

                        public static void main(String[] args) throws Exception {
                        SimpleMessageListener test = new SimpleMessageListener();
                        test.process();
                        }

                        private void process()throws Exception
                        {
                        ApplicationContext context = new ClassPathXmlApplicationContext(
                        "dd/jmscommon.xml", SimpleMessageListener.class);
                        //FileCopyDemoCommon.displayDirectories(context);
                        Thread.sleep(5000);
                        }


                        }
                        -------------------------------------------------------------

                        But does not work if I use jndi context lookup like below - why is it so?? Actual requirement have remote listener as weblogic - mdb via foreign jms.

                        package com.hcl.util.jms.impl.activemq;

                        import java.util.Map;
                        import java.util.Properties;

                        import javax.jms.JMSException;
                        import javax.jms.MessageConsumer;
                        import javax.jms.MessageListener;
                        import javax.jms.QueueConnection;
                        import javax.jms.QueueConnectionFactory;
                        import javax.jms.QueueSession;
                        import javax.naming.Context;
                        import javax.naming.NamingException;

                        import com.hcl.util.jms.JMSQueueRecieveUtil;

                        public class JMSActiveMQQueueRecieve implements JMSQueueRecieveUtil{
                        private Map properties;

                        private QueueConnectionFactory factory;

                        private boolean isConcurrent;

                        private String selectorExpression;

                        private MessageListener messageListener;

                        public JMSActiveMQQueueRecieve(Map properties){
                        this.properties=properties;
                        try {
                        javax.naming.Context ctx = new javax.naming.InitialContext(getInitialContextPrope rties());
                        factory = (javax.jms.QueueConnectionFactory)ctx.lookup((Stri ng)properties.get("QUEUE_CONNECTION_FACTORY_JNDI_N AME"));
                        isConcurrent=new Boolean((String)properties.get("CONCURRET_USERS")) ;
                        } catch (NamingException e) {

                        e.printStackTrace();
                        }

                        }
                        public Map getProperties() {
                        return properties;
                        }
                        public void reciveMessage(){
                        if(isConcurrent){
                        synchronized (this) {
                        recieveMessageFromActiveMQ();
                        }
                        }else{
                        recieveMessageFromActiveMQ();
                        }

                        }
                        public void recieveMessageFromActiveMQ(){
                        QueueConnection conn =null;
                        javax.jms.QueueSession session =null;
                        javax.jms.Queue myqueue = null;
                        MessageConsumer consumer =null;
                        try{

                        conn = factory.createQueueConnection();
                        conn.start();
                        session = conn.createQueueSession(false,QueueSession.AUTO_AC KNOWLEDGE);
                        myqueue = session.createQueue((String)properties.get("QUEUE_ NAME"));
                        //consumer =session.createConsumer(myqueue,selectorExpression );
                        consumer =session.createConsumer(myqueue);
                        consumer.setMessageListener(messageListener);

                        }catch(JMSException jmsException){
                        jmsException.printStackTrace();
                        }finally{

                        }

                        }


                        public String getSelectorExpression() {
                        return selectorExpression;
                        }
                        public void setSelectorExpression(String selectorExpression) {
                        this.selectorExpression = selectorExpression;
                        }
                        public MessageListener getMessageListener() {
                        return messageListener;
                        }
                        public void setMessageListener(MessageListener messageListener) {
                        this.messageListener = messageListener;
                        }
                        public void setProperties(Map properties) {
                        this.properties = properties;
                        }
                        private Properties getInitialContextProperties(){
                        Properties props = new Properties();
                        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, (String)properties.get("INITIAL_CONTEXT_FACTORY")) ;
                        props.setProperty(Context.PROVIDER_URL,(String)pro perties.get("PROVIDER_URL"));
                        return props;
                        }
                        }

                        Comment


                        • #13
                          Please edit and format your post properly. It becomes difficult to read.
                          If you want to see how your post loos like, click "Go advanced" and wrap relevant portions of your code with the right quotes, preview before posting.

                          Whats not working as expected? Anything in the logs?

                          Comment


                          • #14
                            Amol - sending attachment file - jms.txt
                            Good framework like lightweight esb - keep it up!! -myself still need to understand various things.Attachment

                            Requirement was channel inbound adapter should read text file -> convert content into string -> send to jms outbound adapter (activemq) --> Listener on remote machine should be able to subscribe messages

                            Remote Listener on a different/remote machine should be able to receive this message - listener works fine if I use jms:listener container as shown in attached code, no logs as such, I suspect jms properties(code1) using template and jndi(code2) do not match?
                            Attached Files

                            Comment


                            • #15
                              amol - sorry my mistake - things are working - myself was giving wrong queue name at remote listener side.

                              Quick question file polling adaper - file:inbound-channel-adapter with poller -> poller works only if filename is changed or new file is created in the directory but if an existing file once picked up by file:inbound-channel-adapter with poller is not again selected why is it so? Even if existing file is changed, it does not pickup - needs a new filename.

                              Comment

                              Working...
                              X