0

I am trying to pass string messages from one class to another (from Class1 to Class2) within the same application so I am trying to solve it using Spring Integration.

My context.xml file looks like below:

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

      xmlns:int="http://www.springframework.org/schema/integration"
      xmlns:int-jms="http://www.springframework.org/schema/integration/jms">

    <int:channel id="processEmpChannel">
        <int:queue/>
    </int:channel>

    <int-jms:inbound-channel-adapter
        channel="processEmpChannel" connection-factory="connectionFactory"
        destination-name="empQueue">
        <int:poller fixed-delay="500" />
    </int-jms:inbound-channel-adapter>

    <bean id="connectionFactory"
        class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="vm://localhost?broker.persistent=false" />
            </bean>
        </property>
        <property name="sessionCacheSize" value="10" />
        <property name="cacheProducers" value="false" />
    </bean>
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>

    <bean id="springIntExample"
        class="com.distributed.analyzer.Manager">
        <property name="jmsTemplate" ref="jmsTemplate" />
    </bean>

    <int:service-activator input-channel="processEmpChannel" ref="springIntExample" method="processMessage">
        <int:poller fixed-delay="500"/>
    </int:service-activator>
</beans>

Class Class1:

package com.my.package;

public class Class1 implements Runnable {


        @Autowired
        private ApplicationContext appContext;
        private JmsTemplate jmsTemplate;

        ...

        public void someMethod() {
             Class1 c = (Class1) appContext.getBean("springIntExample");
             c.send();
        }

        public void send() {
            getJmsTemplate().convertAndSend("empQueue", "one message to test");
        }

        public JmsTemplate getJmsTemplate() {
            return jmsTemplate;
        }

        public void setJmsTemplate(JmsTemplate jmsTemplate) {
            this.jmsTemplate = jmsTemplate;
        }

        ...
    }

Class Class2:

package com.my.package;

public class Class2 implements Runnable {

    ...

    public void processMessage(String msg) {
         System.out.println("message recived: " + msg);
    }

    ...
}

Problem I have:

If I open my context.xml file, the below lines in context.xml are marked with a cross (error):

<int:poller fixed-delay="500" />

Anyway I can build and execute application but in run time an exception message saying fixe-delay not allowed in int:poller appears.

Also, is my implementation correct? I am not sure if after solving the problem commented it will work. I am new in spring sorry.

Willy
  • 9,848
  • 22
  • 141
  • 284
  • What version of Spring Integration are you using? It sounds like you have a very old version (1.0.x). The current version is 4.2.4 which requires Spring Framework at least 4.0.x. The latest Spring Framework is also 4.2.4. – Gary Russell Feb 08 '16 at 22:09
  • @GaryRussell I have imported the last one, that is, 4.2.4.In my libraries I have all the jar spring jars as 4.2.4. – Willy Feb 08 '16 at 22:28
  • `>If I open my context.xml file, the below lines in context.xml are marked with a cross (error):` - that implies your IDE is not Spring-Aware and it using an old schema from the internet instead of the current one from the jar; but you should not have any runtime problems since Spring knows how to find the right schema in the jar. If you can post your project on GitHub or somewhere, we can take a look. You should use maven or gradle to manage your dependencies. – Gary Russell Feb 08 '16 at 22:32

0 Answers0