/** * constructs an activemq transport factory that connects to a specific host * and port. * * @param host * JMS server host * @param port * JMS server port. * @throws Exception */ public ActiveMQTransportFactory(String host, int port) throws Exception { // failover: means that it will automatically reconnect. String conUrl = "failover:tcp://" + host + ":" + port + "??wireFormat.maxInactivityDuration=0"; log.info("Constructing ActiveMQTransportFactory for " + conUrl); connectionFactory = new ActiveMQConnectionFactory(conUrl); connectionFactory.setProducerWindowSize(1024000); connectionFactory.setUseAsyncSend(true); connectionFactory.setOptimizeAcknowledge(true); connection = connectionFactory.createTopicConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
public AMQConnection(final AMQPublisherConfig baseConfig) { useBytesMessage = new AtomicBoolean(baseConfig.getUseBytesMessage()); final String uri = baseConfig.getUri(); if (uri != null) { this.connectionFactory = new ActiveMQConnectionFactory(uri); this.connectionFactory.setUseAsyncSend(baseConfig.getUseAsyncSend()); } }
public void run(){ logger.debug("JMS Sender get started to send responses to activeMq..."); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); connectionFactory.setUseAsyncSend(true);//faster than sync connectionFactory.setOptimizeAcknowledge(true); Connection connection; try{ connection = connectionFactory.createConnection(); connection.start(); /** create an activeMq for responses **/ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = session.createQueue(jmsResponseQueueName); MessageProducer responseProducer = session.createProducer(destination); responseProducer.setDeliveryMode(DeliveryMode.PERSISTENT); //persistent mode while (keepRunning){ // do time-consuming work here } } catch (JMSException e){ logger.error("Exception occur when sender fails to connect to activeMQ:{}", e.getMessage()); } catch (InterruptedException ie){ logger.error("Exception occur when take response from queue...{}", ie.getMessage()); } }
/** * constructs an activemq transport factory that connects to a specific host * and port. * * @param host * JMS server host * @param port * JMS server port. * @throws Exception */ public ActiveMQTransportFactory(String host, int port, String username, String password) throws Exception { // failover: means that it will automatically reconnect. String conUrl = "failover:tcp://" + host + ":" + port + "??wireFormat.maxInactivityDuration=0"; log.info("Constructing ActiveMQTransportFactory for " + conUrl); // connectionFactory = new ActiveMQConnectionFactory(conUrl); connectionFactory.setUserName(username); connectionFactory.setPassword(password); connectionFactory.setProducerWindowSize(1024000); connectionFactory.setUseAsyncSend(true); connectionFactory.setOptimizeAcknowledge(true); connection = connectionFactory.createTopicConnection(username, password); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
@Override public ConnectionFactory getConnectionFactory(final JmsConfig jmsConfig, final boolean poolable) { final String brokerUrl = jmsConfig.getBrokerUrl(); final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); final RedeliveryPolicy redeliveryPolicy = connectionFactory.getRedeliveryPolicy(); connectionFactory.setUseAsyncSend(true); setupRedeliveryPolicy(redeliveryPolicy, jmsConfig); if (poolable) { return new PooledConnectionFactory(connectionFactory); } else { return connectionFactory; } }
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) getConnectionFactory(); factory.setExceptionListener(null); factory.setUseAsyncSend(false); this.flowControlConnection = (ActiveMQConnection) factory.createConnection(); this.flowControlConnection.start();
@Test public void testAsyncPublisherRecoverAfterBlock() throws Exception { factory.setProducerWindowSize(1024 * 5); factory.setUseAsyncSend(true); flowControlConnection = (ActiveMQConnection) factory.createConnection(); flowControlConnection.start();
factory.setUseAsyncSend(true); this.flowControlConnection = (ActiveMQConnection) factory.createConnection(); this.flowControlConnection.start();