List of usage examples for org.springframework.jms.connection SingleConnectionFactory SingleConnectionFactory
public SingleConnectionFactory(ConnectionFactory targetConnectionFactory)
From source file:ch.algotrader.event.TopicEventDumper.java
public static void main(String... args) throws Exception { SingleConnectionFactory jmsActiveMQFactory = new SingleConnectionFactory( new ActiveMQConnectionFactory("tcp://localhost:61616")); jmsActiveMQFactory.afterPropertiesSet(); jmsActiveMQFactory.resetConnection(); ActiveMQTopic topic = new ActiveMQTopic(">"); DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer(); messageListenerContainer.setDestination(topic); messageListenerContainer.setConnectionFactory(jmsActiveMQFactory); messageListenerContainer.setSubscriptionShared(false); messageListenerContainer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); messageListenerContainer.setMessageListener((MessageListener) message -> { try {/* w w w .j a va 2 s . c o m*/ Destination destination = message.getJMSDestination(); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; System.out.println(destination + " -> " + textMessage.getText()); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); System.out.println(destination + " -> " + new String(bytes, Charsets.UTF_8)); } } catch (JMSException ex) { throw new UnrecoverableCoreException(ex); } }); messageListenerContainer.initialize(); messageListenerContainer.start(); System.out.println("Dumping messages from all topics"); Runtime.getRuntime().addShutdownHook(new Thread(messageListenerContainer::stop)); Thread.sleep(Long.MAX_VALUE); }
From source file:com.consol.citrus.demo.javaland.EmployeeJmsResourceTest.java
@Before public void setUp() { employeeJmsEndpoint = CitrusEndpoints.jms().synchronous().destination(employeeQueue) .connectionFactory(new SingleConnectionFactory(connectionFactory)).build(); }
From source file:net.lr.jmsbridge.ConnectionPool.java
public ConnectionFactory getConnectionFactory(UserNameAndPassword auth) { ConnectionFactory connectionFactory = connectionFactoryMap.get(auth); if (connectionFactory != null) { return connectionFactory; }//from ww w . j a v a2 s .c o m try { Context context = new InitialContext(); Context envContext = (Context) context.lookup("java:comp/env"); ConnectionFactory innerConnectionFactory = (ConnectionFactory) envContext .lookup("jms/ConnectionFactory"); UserCredentialsConnectionFactoryAdapter credConnectionFactory = new UserCredentialsConnectionFactoryAdapter(); credConnectionFactory.setTargetConnectionFactory(innerConnectionFactory); credConnectionFactory.setUsername(auth.getUserName()); credConnectionFactory.setPassword(auth.getPassword()); connectionFactory = new SingleConnectionFactory(innerConnectionFactory); connectionFactoryMap.put(auth, connectionFactory); return connectionFactory; } catch (NamingException e) { throw new RuntimeException("Could not find Connectionfactory in JNDI", e); } }
From source file:org.openmrs.event.EventEngine.java
private synchronized void initializeIfNeeded() { if (jmsTemplate == null) { log.info("creating connection factory"); String dataDirectory = new File(OpenmrsUtil.getApplicationDataDirectory(), "activemq-data") .getAbsolutePath();/*w w w .ja va2 s .c om*/ try { dataDirectory = URLEncoder.encode(dataDirectory, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Failed to encode URI", e); } String brokerURL = "vm://localhost?broker.persistent=true&broker.dataDirectory=" + dataDirectory; ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL); connectionFactory = new SingleConnectionFactory(cf); // or CachingConnectionFactory ? jmsTemplate = new JmsTemplate(connectionFactory); } else { log.trace("messageListener already defined"); } }