Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration. Send message to HornetQ in JBoss 7.1.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration. Send message to HornetQ in JBoss 7.1.1

    I want to send message to HornetQ queue in Jboss 7.1.1. by using Spring Integration.

    My current spring integration configuration is:
    Code:
    <int:gateway id="gatewayService" service-interface="pl.firstdata.maqc.integration.GatewayService"
    default-request-channel="requestChannel"/>
    
    <int:channel id="requestChannel" >
    <int:interceptors>
    <int:wire-tap channel="logger"/>
    </int:interceptors>
    </int:channel>
    <int:logging-channel-adapter id="logger" level="DEBUG" />
    
    <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue" connection-factory="connFactory" />
    
    
    <jee:jndi-lookup id="connFactory" expected-type="javax.jms.ConnectionFactory" jndi-name="jms/RemoteConnectionFactory"/>
    
    <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
    
    <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
    But I get Exception:

    org.springframework.integration.MessageHandlingExc eption: javax.jms.JMSSecurityException: Unable to validate user: null
    at org.springframework.integration.jms.JmsOutboundGat eway.handleRequestMessage(JmsOutboundGateway.java: 410)
    at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:97)
    at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
    at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
    at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
    at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
    at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
    at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
    at org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
    at org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
    at org.springframework.integration.core.MessagingTemp late.convertAndSend(MessagingTemplate.java:189)
    at org.springframework.integration.gateway.MessagingG atewaySupport.send(MessagingGatewaySupport.java:18 3)
    at org.springframework.integration.gateway.GatewayPro xyFactoryBean.invokeGatewayMethod(GatewayProxyFact oryBean.java:308)
    at org.springframework.integration.gateway.GatewayPro xyFactoryBean.doInvoke(GatewayProxyFactoryBean.jav a:268)
    at org.springframework.integration.gateway.GatewayPro xyFactoryBean.invoke(GatewayProxyFactoryBean.java: 259)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy10.process(Unknown Source)
    at pl.firstdata.maqc.integration.IntegrationTest.inte grTest(IntegrationTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements .RunBeforeTestMethodCallbacks.evaluate(RunBeforeTe stMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements .RunAfterTestMethodCallbacks.evaluate(RunAfterTest MethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements .SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunn erWithArgs(JUnit4IdeaTestRunner.java:76)
    at com.intellij.rt.execution.junit.JUnitStarter.prepa reStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main (AppMain.java:120)
    Caused by: javax.jms.JMSSecurityException: Unable to validate user: null
    at org.hornetq.core.protocol.core.impl.ChannelImpl.se ndBlocking(ChannelImpl.java:312)
    at org.hornetq.core.client.impl.ClientSessionFactoryI mpl.createSessionInternal(ClientSessionFactoryImpl .java:780)
    at org.hornetq.core.client.impl.ClientSessionFactoryI mpl.createSession(ClientSessionFactoryImpl.java:27 9)
    at org.hornetq.jms.client.HornetQConnection.authorize (HornetQConnection.java:601)
    at org.hornetq.jms.client.HornetQConnectionFactory.cr eateConnectionInternal(HornetQConnectionFactory.ja va:684)
    at org.hornetq.jms.client.HornetQConnectionFactory.cr eateConnection(HornetQConnectionFactory.java:119)
    at org.hornetq.jms.client.HornetQConnectionFactory.cr eateConnection(HornetQConnectionFactory.java:114)
    at org.springframework.integration.jms.JmsOutboundGat eway.createConnection(JmsOutboundGateway.java:573)
    at org.springframework.integration.jms.JmsOutboundGat eway.sendAndReceive(JmsOutboundGateway.java:415)
    at org.springframework.integration.jms.JmsOutboundGat eway.handleRequestMessage(JmsOutboundGateway.java: 387)
    ... 49 more
    Caused by: HornetQException[errorCode=105 message=Unable to validate user: null]
    ... 59 more


    Please help
    Last edited by Gary Russell; Feb 15th, 2013, 08:14 AM.

  • #2
    Please use [ code ] ... [ /code ] tags when posting code and config (no spaces in brackets) - I edited your post to add them.

    I take it you got past your earlier schema problem... http://forum.springsource.org/showth...te-JBoss-queue

    This looks to be a problem with the JNDI configuration of the connection factory...

    ...
    Caused by: javax.jms.JMSSecurityException: Unable to validate user: null
    at org.hornetq.core.protocol.core.impl.ChannelImpl.se ndBlocking(ChannelImpl.java:312)
    ...

    Comment


    • #3
      Thank you Gary for reply!

      I have solved it I had to wrap my factoryconnection into UserCredentialsConnectionFactoryAdapter:

      Code:
       
      <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
              <property name="jndiName" value="jms/RemoteConnectionFactory"/>
          </bean>
      
          <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
              <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
              <property name="username" value="robert"/>
              <property name="password" value="sys"/>
          </bean>
      but now I have another problem: I wanty to send message to Jboss 7.1.1 HornetQ to requestQueue. On JBoss my MDB receivs message from requestQueue and writes message to replyMessage. And it happens and works 'cos messages are in replyQueue (I see it in JBoss console) but my remote client that uses Spring Integration can't receive messages from replyQueue. I want it to be ansynchron of course.

      My current spring configuration is:

      Code:
      <int:gateway id="gatewayService" service-interface="pl.firstdata.maqc.integration.GatewayService"
                       default-request-channel="requestChannel"/>
      
          <int:channel id="requestChannel" >
              <int:interceptors>
                  <int:wire-tap channel="logger"/>
              </int:interceptors>
          </int:channel>
          <int:logging-channel-adapter id="logger" level="DEBUG" />
      
          <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue"
                                    reply-channel="replyChannel" reply-destination="replyQueue" connection-factory="connFactory" />
      
          <int:outbound-channel-adapter id="replyChannel" ref="integrationService" method="logMessage"  />
      
          <bean id="integrationService" class="pl.firstdata.maqc.integration.IntegrationService"/>
      
      
          <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
      
          <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/reply"/>
      
      
          <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
              <property name="jndiName" value="jms/RemoteConnectionFactory"/>
          </bean>
      
          <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
              <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
              <property name="username" value="robert"/>
              <property name="password" value="sys"/>
          </bean>
      I get Exception in client:
      Code:
      org.springframework.integration.MessageTimeoutException: failed to receive JMS response within timeout of: 5000ms
      	at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:389)
      	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
      	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
      	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
      	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
      	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
      	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
      	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
      	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
      	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
      	at org.springframework.integration.core.MessagingTemplate.convertAndSend(MessagingTemplate.java:189)
      	at org.springframework.integration.gateway.MessagingGatewaySupport.send(MessagingGatewaySupport.java:183)
      	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:308)
      	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:268)
      	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:259)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy10.process(Unknown Source)
      	at pl.firstdata.maqc.integration.IntegrationTest.integrTest(IntegrationTest.java:18)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      What do I do wrong. I have no ideas...

      Comment


      • #4
        Sorry for confuson.

        I have solved this problem by adding inbound gateway.

        My Spring configuration

        Code:
         <int:gateway id="gatewayService" service-interface="pl.firstdata.maqc.integration.GatewayService"
                         default-request-channel="requestChannel"/>
        
            <int:channel id="requestChannel" >
                <int:interceptors>
                    <int:wire-tap channel="logger"/>
                </int:interceptors>
            </int:channel>
            <int:logging-channel-adapter id="logger" level="DEBUG" />
        
            <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue"
                                      connection-factory="connFactory" />
        
            <int-jms:inbound-gateway request-channel="replyChannel" request-destination="replyQueue" connection-factory="connFactory" />
        
            <int:outbound-channel-adapter id="replyChannel" ref="integrationService" method="logMessage"  />
        
            <bean id="integrationService" class="pl.firstdata.maqc.integration.IntegrationService"/>
        
        
            <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
        
            <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/reply"/>
        
        
            <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
                <property name="jndiName" value="jms/RemoteConnectionFactory"/>
            </bean>
        
            <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
                <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
                <property name="username" value="robert"/>
                <property name="password" value="sys"/>
            </bean>
        I get still the exception:

        Code:
        org.springframework.integration.MessageTimeoutException: failed to receive JMS response within timeout of: 5000ms
        	at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:389)
        	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
        	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
        	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
        	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
        	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
        	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
        	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
        	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
        	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
        	at org.springframework.integration.core.MessagingTemplate.convertAndSend(MessagingTemplate.java:189)
        	at org.springframework.integration.gateway.MessagingGatewaySupport.send(MessagingGatewaySupport.java:183)
        	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:308)
        	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:268)
        	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:259)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        	at $Proxy10.process(Unknown Source)
        	at pl.firstdata.maqc.integration.IntegrationTest.integrTest(IntegrationTest.java:18)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
        	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
        	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
        	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
        	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
        	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
        	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
        	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
        	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
        As I understand:
        - int-jms:inbound-gateway - reads messages from queue
        - int-jms:outbound-gateway - writes messages to queue

        Is it true. IF yes than what for is request and replay attributes both in inbound-gateway and outbound-gateway?

        Is something wrong in my configuration other could be better done and please help why I still get the Exception.

        Comment


        • #5
          No; the gateway is a request/response element - adding an inbound gateway is incorrect here. outbound/inbound (message-driven) channel adapters are for one-way integration.

          However, since your entry point is an <int:gateway/> your initial solution is correct - you just need an outbound gateway. Using channel adapters won't work (without complexity) because the framework will have no way to know where to send the reply.

          The outbound gateway is correct - we just need to figure out why that's not working for you.

          Does the remote MDB copy the JMSMessageID as the JMSCorrelationID on the reply? (That is what the gateway is expecting in its selector).

          You can control message correlation with the correlation-key attribute.

          By the way, I noticed in your other post you are using Spring Integration 2,0.x; the current release is 2.2.1.

          Plus; if your remote end takes more than the default 5 seconds, you can increase the timeout on the outbound gateway.

          Comment


          • #6
            I understand.

            I have change Spring configuration:
            Code:
            <int:gateway id="gatewayService" service-interface="pl.firstdata.maqc.integration.GatewayService"
                             default-request-channel="requestChannel"/>
            
                <int:channel id="requestChannel" />
            
            
            
                <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue"
                                          reply-channel="replyChannel" reply-destination="replyQueue"
                                          connection-factory="connFactory" />
            
                <int:outbound-channel-adapter id="replyChannel" ref="integrationService" method="logMessage"  />
            
                <bean id="integrationService" class="pl.firstdata.maqc.integration.IntegrationService"/>
            
            
            
                <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
            
                <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/reply"/>
            
            
                <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
                    <property name="jndiName" value="jms/RemoteConnectionFactory"/>
                </bean>
            
                <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
                    <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
                    <property name="username" value="robert"/>
                    <property name="password" value="sys"/>
                </bean>
            And my junit test:

            Code:
            @ContextConfiguration({ "/integration.xml"})
            @RunWith(SpringJUnit4ClassRunner.class)
            public class IntegrationTest {
            
                @Autowired
                private GatewayService gatewayService;
            
                @Autowired
                private IntegrationService integrationService;
            
            
                @Test
                public void integrTest() throws InterruptedException {
                    gatewayService.process("test message");
                    Thread.sleep(5000);
                    List<String> messages = integrationService.getMessages();
            
                    Assert.isTrue(!messages.isEmpty());
                }
            }

            And

            Code:
            public class IntegrationService {
            
                private List<String> messages = new ArrayList<String>();
            
            
                public void logMessage(String message) {
                    messages.add(message);
                }
            
                public List<String> getMessages() {
                    return Collections.unmodifiableList(messages);
                }
            }
            While performing junit test, program stops on "gatewayService.process("test message");" and doesn't go on so it looks like not asynchron and after 5 sec I get still
            org.springframework.integration.MessageTimeoutExce ption: failed to receive JMS response within timeout of: 5000ms

            Message driven bean looks like:

            Code:
            @MessageDriven(name = "ReqMBEJB", activationConfig = {
                    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                    @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/queue/req"),
                    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
            
            public class RequestMBBean implements javax.jms.MessageListener {
            
                @Resource(mappedName = "java:/ConnectionFactory")
                private ConnectionFactory connectionFactory;
            
                @Resource(mappedName = "java:jboss/exported/jms/queue/reply")
                private Queue replyQueue;
            
                @Override
                public void onMessage(Message message) {
                    System.out.println("-------------------" + message + "---------------------");
                    QueueConnection con = null;
                    QueueSession ses = null;
                    QueueSender sender = null;
                    try {
                        QueueConnectionFactory qcf = (QueueConnectionFactory) connectionFactory;
                        con = qcf.createQueueConnection();
                        ses = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                        sender = ses.createSender(replyQueue);
                        TextMessage msg = ses.createTextMessage("Test message from MDB");
                        sender.send(msg);
                    } catch (JMSException e) {
                        throw new RuntimeException(e);
                    } finally {
                        JmsHelper.close(sender, ses, con);
                    }
                }
            }
            When I set more than 5 sec than nothing changes.

            I want to add message to queue and my program processes other task (asynchron) and when remote replyqueu gets message than asynchron my IntegrationService gets message from replyQueue. I don't want to wait till I get reply but all asynchron. So send message to requestQueue and later something like listener gets message from replyQueue.
            Do I do it wrong?
            Last edited by RobertVox1977; Feb 15th, 2013, 12:51 PM.

            Comment


            • #7
              You need

              Code:
              public void onMessage(final Message message) {
              
              ...
              
                          sender = ses.createSender(replyQueue);
                          TextMessage msg = ses.createTextMessage("Test message from MDB");
                          msg.setJMSCorrelationID(message.getJMSMessageID);
                          sender.send(msg);
              The gateway is using a messageSelector that requires the receiving side to populate the JMSCorrelationID.

              Comment


              • #8
                Thank you Gary !

                That works!

                Now I understand why

                I would have one more question. That could be said that in this case the call of gatewayService.process("test message"); method (that comunicate through int-jms:outbound-gateway) is synchron in this sense that program waits for reply from the jms gateway.

                How can I send message to requestQueue, then program does other things and when replyQueue gets message from for instance MDB on the server, than something like listener on my client listens to replyQueue and gets that message from replyQueue.

                So, in general I mean functionality the same but total asynchron? How could I configure it in Spring Integration.
                Any hint I would appreciate.

                Comment


                • #9
                  I assume your GatewayService.process() method returns void.

                  You need to hand the request off to another thread, e.g. by adding a <dispatcher/> with a task-executor to, say, requestChannel.

                  http://static.springsource.org/sprin...ecutor-channel

                  http://static.springsource.org/sprin...xecutorchannel

                  Another option is to usean Asynchronous Gateway http://static.springsource.org/sprin...#async-gateway

                  The GatewayService method returns a Future<?> which is a holder for the result. The calling thread can go off and do other things and then check the future from time-to-time with a get(0).

                  In that case, you don't need the <service-activator/> just remove the reply-channel from the outbound gateway.

                  Comment


                  • #10
                    Thanks Gary once more!,

                    That's what I need. It's very helpful.

                    There is only one thing I need.

                    How to configure spring integration in the case, that, I don't send anything to server (to queue) but want to be informed when any message appears in replyQueue on the server. Of course both queues are on the server. How to configure client. I suppose I must sequentially ask the queue, use polling or something else? Would be here maybe <jms:listener-container> helpful. Or maybe I think something wrong and then other solution should be used. I'd like to use Spring Integration.

                    Comment


                    • #11
                      That's a tricky one - are you saying that sometimes replyQueue contains replies, and sometimes just unsolicited messages?

                      Given that the gateway uses a selector looking for the JMSMessageID in the JMSCorrelationID, you could, for unsolicited messages, have the other side set JMSCorrelationID to, say "foo" and have a <int-jms:message-driven-channel-adapter ... selector="JMSCorrelationID='foo'" .../>.

                      Comment


                      • #12
                        Thanks a lot Gary!

                        That works.

                        My spring configuration file:

                        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"
                               xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
                               xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms"
                               xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans.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-2.0.xsd
                               http://www.springframework.org/schema/jee
                               http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd">
                        
                            <int:gateway id="gatewayAsynchService" service-interface="pl.firstdata.maqc.integration.GatewayAsynchService"
                                         default-request-channel="requestChannel"/>
                        
                            <int:poller default="true" fixed-delay="250"/>
                        
                            <int:channel id="requestChannel">
                                <int:queue capacity="10"/>
                            </int:channel>
                        
                            <int-jms:outbound-gateway request-channel="requestChannel" request-destination="requestQueue"
                                                      connection-factory="connFactory"/>
                        
                            <int-jms:message-driven-channel-adapter id="mdChannel" connection-factory="connFactory" destination="replyQueue"
                                                                    selector="JMSCorrelationID='foo'" channel="replyChannel" />
                        
                            <int:outbound-channel-adapter id="replyChannel" ref="integrationAsynchService" method="logMessage"  />
                        
                            <bean id="integrationAsynchService" class="pl.firstdata.maqc.integration.IntegrationAsynchService"/>
                        
                            <jee:jndi-lookup id="requestQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/req"/>
                        
                            <jee:jndi-lookup id="replyQueue" expected-type="javax.jms.Destination" jndi-name="jms/queue/reply"/>
                        
                            <bean id="myTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
                                <property name="jndiName" value="jms/RemoteConnectionFactory"/>
                            </bean>
                        
                            <bean id="connFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
                                <property name="targetConnectionFactory" ref="myTargetConnectionFactory"/>
                                <property name="username" value="robert"/>
                                <property name="password" value="sys"/>
                            </bean>
                        
                        </beans>
                        and Test file:

                        Code:
                        @ContextConfiguration({ "/integration_asynch.xml"})
                        @RunWith(SpringJUnit4ClassRunner.class)
                        public class IntegrationAsynchTest {
                        
                            @Autowired
                            private GatewayAsynchService gatewayAsynchService;
                        
                            @Autowired
                            private IntegrationAsynchService integrationAsynchService;
                        
                        
                            @Test
                            public void integrAsynchTest() throws InterruptedException {
                                gatewayAsynchService.process("test message");
                                Thread.sleep(10000);
                                List<String> messages = integrationAsynchService.getMessages();
                                Assert.isTrue(messages.get(0).equals("Test message from MDB"));
                                Assert.isTrue(!messages.isEmpty());
                            }
                        }
                        A send message asynch, sleep main thread and reach to answers from queue.

                        MDB code:

                        Code:
                        @MessageDriven(name = "ReqMBEJB", activationConfig = {
                                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                                @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/queue/req"),
                                @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
                        
                        public class RequestMBBean implements javax.jms.MessageListener {
                        
                            @Resource(mappedName = "java:/ConnectionFactory")
                            private ConnectionFactory connectionFactory;
                        
                            @Resource(mappedName = "java:jboss/exported/jms/queue/reply")
                            private Queue replyQueue;
                        
                            @Override
                            public void onMessage(Message message) {
                                System.out.println("-------------------" + message + "---------------------");
                                QueueConnection con = null;
                                QueueSession ses = null;
                                QueueSender sender = null;
                                try {
                                    QueueConnectionFactory qcf = (QueueConnectionFactory) connectionFactory;
                                    con = qcf.createQueueConnection();
                                    ses = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                                    sender = ses.createSender(replyQueue);
                                    TextMessage msg = ses.createTextMessage("Test message from MDB");
                                    //msg.setJMSCorrelationID(message.getJMSMessageID());
                                    msg.setJMSCorrelationID("foo");
                                    sender.send(msg);
                                } catch (JMSException e) {
                                    throw new RuntimeException(e);
                                } finally {
                                    JmsHelper.close(sender, ses, con);
                                }
                            }
                        }
                        and
                        Code:
                        public class IntegrationAsynchService {
                        
                            private List<String> messages = new ArrayList<String>();
                        
                        
                            public void logMessage(String message) {
                                messages.add(message);
                            }
                        
                            public List<String> getMessages() {
                                return Collections.unmodifiableList(messages);
                            }
                        }
                        Last edited by RobertVox1977; Feb 15th, 2013, 04:57 PM.

                        Comment


                        • #13
                          The example of my spring configuration file I've attached doesn't work.

                          When I send in a test a message twice:
                          Code:
                          gatewayAsynchService.process(claimDto1);
                          gatewayAsynchService.process(claimDto2);
                          then is sent only the first.

                          I must simply add dispatcher to my requestChannel to hand the request off to another thread - exactly as wrote Gary.

                          So, instead of:
                          Code:
                           <int:channel id="requestChannel">
                                  <int:queue capacity="10"/>
                              </int:channel>

                          I should have:
                          Code:
                          <int:channel id="requestChannel">
                                  <int:dispatcher task-executor="myTaskExecutor"/>
                              </int:channel>
                          where myTaskExecutor could be class that extends, for instance: SimpleAsyncTaskExecutor.

                          I should have read more carefully, Gary, thanks

                          Comment

                          Working...
                          X