@SuppressWarnings ( "all" ) // suppressing autocloseable error. inconsistent w/ other connectionfactory impls. @Override public JMSContext getContext( JmsDelegate delegate ) { String finalUrl = buildUrl( delegate ); ConnectionFactory factory = new ActiveMQConnectionFactory( finalUrl ); return factory.createContext( delegate.amqUsername, delegate.amqPassword ); }
ConnectionFactory createRemoteConnectionFactory(final String jmsURL, final String jmsUserName, final String jmsPassword) { return new ActiveMQConnectionFactory(jmsURL, jmsUserName, jmsPassword); }
ConnectionFactory createRemoteConnectionFactory(final String jmsURL, final String jmsUserName, final String jmsPassword) { return new ActiveMQConnectionFactory(jmsURL, jmsUserName, jmsPassword); }
void start() { connectionFactory = new ActiveMQConnectionFactory(getVmURL()); try { connection = connectionFactory.createConnection(); session = connection.createSession(); producer = session.createProducer(null); connection.start(); } catch (JMSException jmsEx) { throw new EmbeddedJMSResourceException("InternalClient creation failure", jmsEx); } }
void start() { connectionFactory = new ActiveMQConnectionFactory(getVmURL()); try { connection = connectionFactory.createConnection(); session = connection.createSession(); producer = session.createProducer(null); connection.start(); } catch (JMSException jmsEx) { throw new EmbeddedJMSResourceException("InternalClient creation failure", jmsEx); } }
private boolean tryConsume() throws JMSException { try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); Session session = connection.createSession(Session.AUTO_ACKNOWLEDGE)) { Queue queue = session.createQueue("NewQueue"); MessageConsumer consumer = session.createConsumer(queue); return true; } catch (JMSException e) { return false; } }
public FQQNOpenWireTest(String factoryType) { if ("OpenWire".equals(factoryType)) { factory = new ActiveMQConnectionFactory(urlString); } else if ("Artemis".equals(factoryType)) { factory = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory(urlString); } }
private static ConnectionFactory createCF(String uri) { ConnectionFactory factory; if (uri.startsWith("amqp")) { factory = new JmsConnectionFactory(uri); } else { factory = new ActiveMQConnectionFactory(uri); } return factory; }
private void sendObjectMessage(String qname, Serializable obj) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0"); Connection connection = factory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = session.createQueue(qname); MessageProducer producer = session.createProducer(q); ObjectMessage objMessage = session.createObjectMessage(); objMessage.setObject(obj); producer.send(objMessage); } finally { connection.close(); } }
private ConnectionFactory getJmsConnectionFactory(int node) { if (protocol.equals("AMQP")) { return new JmsConnectionFactory("amqp://localhost:" + (61616 + node)); } else if (protocol.equals("OPENWIRE")) { return new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:" + (61616 + node)); } else if (protocol.equals("CORE")) { return new ActiveMQConnectionFactory("tcp://localhost:" + (61616 + node)); } else { Assert.fail("Protocol " + protocol + " unkown"); return null; } }
/** * Login with valid user and password * Should allow */ @Test public void testLoginValidUserAndPasswordSystemProperty() throws Exception { System.setProperty(DefaultConnectionProperties.AMQ_USER, "guest"); System.setProperty(DefaultConnectionProperties.AMQ_PASSWORD, "guest"); DefaultConnectionProperties.initialize(); ConnectionFactory cf = new ActiveMQConnectionFactory(); Connection conn = addConnection(cf.createConnection()); }
private ConnectionFactory createCF() { if (isAMQP) { return new JmsConnectionFactory(getBrokerQpidJMSConnectionURI()); } else { return new ActiveMQConnectionFactory("tcp://localhost:5672"); } }
private ActiveMQConnectionFactory getActiveMQConnectionFactory(String user, String password) { ActiveMQConnectionFactory activeMQConnection = new ActiveMQConnectionFactory("tcp://localhost:61616"); activeMQConnection.setUser(user); activeMQConnection.setPassword(password); return activeMQConnection; }
public void createJMSConnection() throws Exception { cf = new ActiveMQConnectionFactory(false, new TransportConfiguration(ActiveMQTestBase.NETTY_CONNECTOR_FACTORY)); }
@Test public void testTwoConnectionsSameIDThroughCF() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid"); conn = connectionFactory.createConnection(); try { conn2 = connectionFactory.createConnection(); Assert.fail("Exception expected"); } catch (InvalidClientIDException expected) { // expected } Session session1 = conn.createSession(); Session session2 = conn.createSession(); session1.close(); session2.close(); }
/** * Login with valid user and password * Should allow */ @Test public void testLoginValidUserAndPasswordSystemPropertyWithAdditionalProperties() throws Exception { System.setProperty(DefaultConnectionProperties.AMQ_USER, "guest"); System.setProperty(DefaultConnectionProperties.AMQ_PASSWORD, "guest"); System.setProperty(DefaultConnectionProperties.BROKER_BIND_URL, "tcp://localhost:61616?compressLargeMessage=true"); DefaultConnectionProperties.initialize(); ConnectionFactory cf = new ActiveMQConnectionFactory(); Connection conn = addConnection(cf.createConnection()); Assert.assertTrue(((ActiveMQConnectionFactory) cf).isCompressLargeMessage()); }
private ConnectionFactory newCF() { if (protocol.equals("core")) { ConnectionFactory factory = new ActiveMQConnectionFactory(); ((ActiveMQConnectionFactory) factory).setBlockOnAcknowledge(true); return factory; } else if (protocol.equals("amqp")) { final JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616"); factory.setForceAsyncAcks(true); return factory; } else { org.apache.activemq.ActiveMQConnectionFactory cf = new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616?wireFormat.cacheEnabled=true"); cf.setSendAcksAsync(false); return cf; } }
private ConnectionFactory createFactory(int protocol) { switch (protocol) { case 1: ActiveMQConnectionFactory coreCF = new ActiveMQConnectionFactory();// core protocol coreCF.setCompressLargeMessage(true); coreCF.setMinLargeMessageSize(10 * 1024); return coreCF; case 2: return new JmsConnectionFactory("amqp://localhost:61616"); // amqp case 3: return new org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616"); // openwire default: return null; } }
@Test public void testAddressQueryOnAutoCreatedAddressWithFQQN() throws Exception { SimpleString addressName = SimpleString.toSimpleString(UUID.randomUUID().toString()); SimpleString fqqn = addressName.concat("::").concat(SimpleString.toSimpleString(UUID.randomUUID().toString())); ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0"); JMSContext c = cf.createContext(); c.createProducer().send(c.createTopic(fqqn.toString()), c.createMessage()); assertEquals(addressName, server.addressQuery(addressName).getName()); assertEquals(addressName, server.addressQuery(fqqn).getName()); }
@Test public void testParseURIs() throws Throwable { ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name"); Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length); ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length); ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length); ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length); }