use of org.springframework.jms.connection.CachingConnectionFactory in project nifi by apache.
the class JMSPublisherConsumerIT method validateFailOnUnsupportedMessageType.
/**
* At the moment the only two supported message types are TextMessage and
* BytesMessage which is sufficient for the type if JMS use cases NiFi is
* used. The may change to the point where all message types are supported
* at which point this test will no be longer required.
*/
@Test
public void validateFailOnUnsupportedMessageType() throws Exception {
final String destinationName = "validateFailOnUnsupportedMessageType";
JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
try {
jmsTemplate.send(destinationName, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage();
}
});
JMSConsumer consumer = new JMSConsumer((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class));
consumer.consume(destinationName, false, false, null, "UTF-8", new ConsumerCallback() {
@Override
public void accept(JMSResponse response) {
// noop
}
});
} finally {
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
}
use of org.springframework.jms.connection.CachingConnectionFactory in project opennms by OpenNMS.
the class AppConfig method connectionFactory.
// private static final Logger logger = LoggerFactory.getLogger(AppConfig.class);
@Bean(name = "connectionFactory")
public CachingConnectionFactory connectionFactory() {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(amqConnectionFactory());
cachingConnectionFactory.setSessionCacheSize(8);
cachingConnectionFactory.setExceptionListener(jmsExceptionListener());
return cachingConnectionFactory;
}
use of org.springframework.jms.connection.CachingConnectionFactory in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestMessageIdNonOptimized.
@Test
public void messageCorrelationBasedOnRequestMessageIdNonOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("standardMessageIdCopyingConsumerWithoutOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueNonOptimizedB", Destination.class);
final Destination replyDestination = context.getBean("siInQueueNonOptimizedB", 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.getJMSMessageID());
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 messageCorrelationBasedOnRequestMessageIdOptimized.
@Test(expected = MessageTimeoutException.class)
public void messageCorrelationBasedOnRequestMessageIdOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("standardMessageIdCopyingConsumerWithOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueOptimizedA", Destination.class);
final Destination replyDestination = context.getBean("siInQueueOptimizedA", 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.getJMSMessageID());
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 RequestReplyScenariosWithTempReplyQueuesTests method messageCorrelationBasedOnRequestMessageId.
@SuppressWarnings("resource")
@Test
public void messageCorrelationBasedOnRequestMessageId() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-temp-reply-consumers.xml", this.getClass());
RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueue", Destination.class);
new Thread(() -> {
final Message requestMessage = jmsTemplate.receive(requestDestination);
Destination replyTo = null;
try {
replyTo = requestMessage.getJMSReplyTo();
} catch (Exception e) {
fail();
}
jmsTemplate.send(replyTo, (MessageCreator) session -> {
try {
TextMessage message = session.createTextMessage();
message.setText("bar");
message.setJMSCorrelationID(requestMessage.getJMSMessageID());
return message;
} catch (Exception e) {
}
return null;
});
}).start();
gateway.exchange(new GenericMessage<String>("foo"));
context.close();
}
Aggregations