use of org.springframework.jms.connection.CachingConnectionFactory in project webofneeds by researchstudio-sat.
the class BrokerComponentFactory method configureCachingConnectionFactory.
public synchronized ConnectionFactory configureCachingConnectionFactory(ActiveMQConnectionFactory connectionFactory) {
// for non-persistent messages setting "AlwaysSyncSend" to true makes it slow, but ensures that a producer is immediately informed
// about the memory issues on broker (is blocked or gets exception depending on <systemUsage> config)
// see more info http://activemq.apache.org/producer-flow-control.html
connectionFactory.setAlwaysSyncSend(false);
// disable timestamps by default so that ttl of messages is not checked
connectionFactory.setDisableTimeStampsByDefault(true);
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
cachingConnectionFactory.setCacheConsumers(true);
cachingConnectionFactory.setCacheProducers(true);
return cachingConnectionFactory;
}
use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestCorrelationIdOptimized.
@Test
public void messageCorrelationBasedOnRequestCorrelationIdOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("correlationPropagatingConsumerWithOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueOptimizedC", Destination.class);
final Destination replyDestination = context.getBean("siInQueueOptimizedC", Destination.class);
new Thread(() -> {
final Message requestMessage = jmsTemplate.receive(requestDestination);
jmsTemplate.send(replyDestination, (MessageCreator) session -> {
TextMessage message = session.createTextMessage();
message.setText("bar");
message.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
return message;
});
}).start();
org.springframework.messaging.Message<?> siReplyMessage = gateway.exchange(new GenericMessage<String>("foo"));
assertEquals("bar", siReplyMessage.getPayload());
} finally {
context.close();
}
}
use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestCorrelationIdNonOptimized.
@Test(expected = MessageTimeoutException.class)
public void messageCorrelationBasedOnRequestCorrelationIdNonOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("correlationPropagatingConsumerWithoutOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueNonOptimizedD", Destination.class);
final Destination replyDestination = context.getBean("siInQueueNonOptimizedD", Destination.class);
new Thread(() -> {
final Message requestMessage = jmsTemplate.receive(requestDestination);
jmsTemplate.send(replyDestination, (MessageCreator) session -> {
TextMessage message = session.createTextMessage();
message.setText("bar");
message.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
return message;
});
}).start();
gateway.exchange(new GenericMessage<String>("foo"));
} finally {
context.close();
}
}
use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method getConnectionFactory.
private ConnectionFactory getConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(activeMQConnectionFactory);
cachingConnectionFactory.setCacheConsumers(false);
return cachingConnectionFactory;
}
use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.
the class JmsOutboundGatewayTests method testConnectionBreakOnReplyCustomCorrelation.
@Test
public void testConnectionBreakOnReplyCustomCorrelation() throws Exception {
CachingConnectionFactory connectionFactory1 = new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
connectionFactory1.setCacheConsumers(false);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setConnectionFactory(connectionFactory1);
String requestQ = "requests2";
gateway.setRequestDestinationName(requestQ);
String replyQ = "replies2";
gateway.setReplyDestinationName(replyQ);
QueueChannel queueChannel = new QueueChannel();
gateway.setOutputChannel(queueChannel);
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.setReceiveTimeout(60000);
gateway.setCorrelationKey("JMSCorrelationID");
gateway.afterPropertiesSet();
gateway.start();
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> gateway.handleMessage(new GenericMessage<String>("foo")));
CachingConnectionFactory connectionFactory2 = new CachingConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"));
connectionFactory2.setCacheConsumers(false);
JmsTemplate template = new JmsTemplate(connectionFactory2);
template.setReceiveTimeout(10000);
template.afterPropertiesSet();
final Message request = template.receive(requestQ);
assertNotNull(request);
connectionFactory1.resetConnection();
MessageCreator reply = session -> {
TextMessage reply1 = session.createTextMessage("bar");
reply1.setJMSCorrelationID(request.getJMSCorrelationID());
return reply1;
};
logger.debug("Sending reply to: " + replyQ);
template.send(replyQ, reply);
logger.debug("Sent reply to: " + replyQ);
org.springframework.messaging.Message<?> received = queueChannel.receive(20000);
assertNotNull(received);
assertEquals("bar", received.getPayload());
gateway.stop();
connectionFactory1.destroy();
connectionFactory2.destroy();
exec.shutdownNow();
}
Aggregations