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?