newConnection = embeddedConnectionFactory.createTopicConnection();
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); TopicConnection connection = factory.createTopicConnection(); Session session = connection.createSession(false,Session.DUPS_OK_ACKNOWLEDGE);
/** * constructs and in-memory active mq transport factory. * * @throws Exception */ public ActiveMQTransportFactory() throws Exception { String conUrl = "vm://localhost"; log.info("Constructing embedded ActiveMQTransportFactory for " + conUrl); connectionFactory = new ActiveMQConnectionFactory(conUrl); connectionFactory.setProducerWindowSize(1024000); connection = connectionFactory.createTopicConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
numTries++; try { connection = connectionFactory.createTopicConnection(); connection.start(); connected = true;
/** * 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); }
/** * 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); }
localTopicConnection = embeddedConnectionFactory.createTopicConnection();
newConnection = embeddedConnectionFactory.createTopicConnection();
newConnection = embeddedConnectionFactory.createTopicConnection();
newConnection = embeddedConnectionFactory.createTopicConnection();
@Test public void testNotificationProperties() throws Exception { try (TopicConnection topicConnection = factory.createTopicConnection()) { TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic notificationsTopic = topicSession.createTopic("activemq.notifications"); TopicSubscriber subscriber = topicSession.createSubscriber(notificationsTopic); List<Message> receivedMessages = new CopyOnWriteArrayList<>(); subscriber.setMessageListener(receivedMessages::add); topicConnection.start(); Wait.waitFor(() -> receivedMessages.size() > 0); Assert.assertTrue(receivedMessages.size() > 0); for (Message message : receivedMessages) { assertNotNull(message); assertNotNull(message.getStringProperty("_AMQ_NotifType")); } } }