List of usage examples for org.springframework.jms.core JmsTemplate JmsTemplate
public JmsTemplate(ConnectionFactory connectionFactory)
From source file:org.springframework.cloud.stream.binder.test.integration.EndToEndIntegrationTests.java
protected EndToEndIntegrationTests(QueueProvisioner queueProvisioner, ConnectionFactory connectionFactory) { this.queueProvisioner = queueProvisioner; this.connectionFactory = connectionFactory; this.jmsTemplate = new JmsTemplate(connectionFactory); }
From source file:org.springframework.integration.jms.request_reply.RequestReplyScenariosWithTempReplyQueuesTests.java
@SuppressWarnings("resource") @Test//from w w w. j a va 2s .c o m 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) { // ignore } return null; }); }).start(); gateway.exchange(new GenericMessage<String>("foo")); context.close(); }
From source file:org.springframework.jms.core.support.JmsGatewaySupport.java
/** * Create a JmsTemplate for the given ConnectionFactory. * Only invoked if populating the gateway with a ConnectionFactory reference. * <p>Can be overridden in subclasses to provide a JmsTemplate instance with * a different configuration.//w w w. ja v a2s .co m * @param connectionFactory the JMS ConnectionFactory to create a JmsTemplate for * @return the new JmsTemplate instance * @see #setConnectionFactory */ protected JmsTemplate createJmsTemplate(ConnectionFactory connectionFactory) { return new JmsTemplate(connectionFactory); }
From source file:org.springframework.util.jms.JmsIntegrationTestUtils.java
public static void startAndConnectToJmsBroker(Class<?> clzzForPayload, Marshaller m, JmsBrokerExecutionCallback callback) throws Throwable { Assert.assertNotNull("the " + JmsBrokerExecutionCallback.class.getName() + "can not be null", callback); String destinationUrl = "tcp://localhost:61617"; BrokerService broker = new BrokerService(); TransportConnector connector = broker.addConnector(destinationUrl); broker.start();//from ww w . j a v a 2s .c om while (!broker.isStarted()) { Thread.sleep(500); } ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(destinationUrl); MarshallingMessageConverter converter = new MarshallingMessageConverter(clzzForPayload, m); JmsTemplate jmsTemplate = new JmsTemplate(activeMQConnectionFactory); converter.setPayloadClass(clzzForPayload); jmsTemplate.setMessageConverter(converter); jmsTemplate.afterPropertiesSet(); try { callback.doWithActiveMq(broker, jmsTemplate); } catch (AssertionError ae) { throw ae; } catch (Throwable th) { if (log.isErrorEnabled()) { log.error("execution of jms session failed.", th); } } finally { connector.stop(); broker.stop(); } }
From source file:test.SecureSampleApp.java
private static void init() throws JMSException { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(URL); template = new JmsTemplate(cf); }