Search in sources :

Example 36 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class DynamicallyIncludedDestinationsDuplexNetworkTest method getDuplexBridgeConnectionFromRemote.

public TransportConnection getDuplexBridgeConnectionFromRemote() {
    TransportConnector transportConnector = remoteBroker.getTransportConnectorByScheme("tcp");
    CopyOnWriteArrayList<TransportConnection> transportConnections = transportConnector.getConnections();
    TransportConnection duplexBridgeConnectionFromRemote = transportConnections.get(0);
    return duplexBridgeConnectionFromRemote;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) TransportConnection(org.apache.activemq.broker.TransportConnection)

Example 37 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class NetworkLoopBackTest method testLoopbackOnDifferentUrlScheme.

@Test
public void testLoopbackOnDifferentUrlScheme() throws Exception {
    final BrokerService brokerServce = new BrokerService();
    brokerServce.setPersistent(false);
    TransportConnector transportConnector = brokerServce.addConnector("nio://0.0.0.0:0");
    // connection filter is bypassed when scheme is different
    final NetworkConnector networkConnector = brokerServce.addNetworkConnector("static:(tcp://" + transportConnector.getConnectUri().getHost() + ":" + transportConnector.getConnectUri().getPort() + ")");
    brokerServce.start();
    brokerServce.waitUntilStarted();
    try {
        Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 1 == networkConnector.bridges.size();
            }
        });
        final DemandForwardingBridgeSupport loopbackBridge = (DemandForwardingBridgeSupport) networkConnector.bridges.values().iterator().next();
        assertTrue("nc started", networkConnector.isStarted());
        assertTrue("It should get disposed", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return loopbackBridge.getRemoteBroker().isDisposed();
            }
        }));
        assertEquals("No peer brokers", 0, brokerServce.getBroker().getPeerBrokerInfos().length);
    } finally {
        brokerServce.stop();
    }
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) Wait(org.apache.activemq.util.Wait) BrokerService(org.apache.activemq.broker.BrokerService) Test(org.junit.Test)

Example 38 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class TimeStampTest method test.

public void test() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(true);
    broker.setPlugins(new BrokerPlugin[] { new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() });
    TransportConnector tcpConnector = broker.addConnector("tcp://localhost:0");
    broker.addConnector("stomp://localhost:0");
    broker.start();
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri());
    // Create a Connection
    Connection connection = connectionFactory.createConnection();
    connection.start();
    // Create a Session
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the destination Queue
    Destination destination = session.createQueue("TEST.FOO");
    // Create a MessageProducer from the Session to the Topic or Queue
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    // Create a messages
    Message sentMessage = session.createMessage();
    // Tell the producer to send the message
    long beforeSend = System.currentTimeMillis();
    producer.send(sentMessage);
    long afterSend = System.currentTimeMillis();
    // assert message timestamp is in window
    assertTrue(beforeSend <= sentMessage.getJMSTimestamp() && sentMessage.getJMSTimestamp() <= afterSend);
    // Create a MessageConsumer from the Session to the Topic or Queue
    MessageConsumer consumer = session.createConsumer(destination);
    // Wait for a message
    Message receivedMessage = consumer.receive(1000);
    // assert we got the same message ID we sent
    assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID());
    // assert message timestamp is in window
    assertTrue("JMS Message Timestamp should be set during the send method: \n" + "        beforeSend = " + beforeSend + "\n" + "   getJMSTimestamp = " + receivedMessage.getJMSTimestamp() + "\n" + "         afterSend = " + afterSend + "\n", beforeSend <= receivedMessage.getJMSTimestamp() && receivedMessage.getJMSTimestamp() <= afterSend);
    // assert message timestamp is unchanged
    assertEquals("JMS Message Timestamp of received message should be the same as the sent message\n        ", sentMessage.getJMSTimestamp(), receivedMessage.getJMSTimestamp());
    // Clean up
    producer.close();
    consumer.close();
    session.close();
    connection.close();
}
Also used : UDPTraceBrokerPlugin(org.apache.activemq.broker.util.UDPTraceBrokerPlugin) TransportConnector(org.apache.activemq.broker.TransportConnector) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionDotFilePlugin(org.apache.activemq.broker.view.ConnectionDotFilePlugin) BrokerService(org.apache.activemq.broker.BrokerService) Session(javax.jms.Session)

Example 39 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class JDBCQueueMasterSlaveTest method createSlave.

@Override
protected void createSlave() throws Exception {
    // use a separate thread as the slave will block waiting for
    // the exclusive db lock
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("slave");
                TransportConnector connector = new TransportConnector();
                connector.setUri(new URI(SLAVE_URL));
                broker.addConnector(connector);
                // no need for broker.setMasterConnectorURI(masterConnectorURI)
                // as the db lock provides the slave/master initialisation
                broker.setUseJmx(false);
                broker.setPersistent(true);
                JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
                persistenceAdapter.setDataSource(getExistingDataSource());
                persistenceAdapter.setCreateTablesOnStartup(false);
                broker.setPersistenceAdapter(persistenceAdapter);
                configureJdbcPersistenceAdapter(persistenceAdapter);
                configureBroker(broker);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (IllegalStateException expectedOnShutdown) {
            } catch (Exception e) {
                fail("failed to start slave broker, reason:" + e);
            }
        }
    };
    t.start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) IOException(java.io.IOException)

Example 40 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class QueueMasterSlaveSingleUrlTest method createSlave.

@Override
protected void createSlave() throws Exception {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("shared-slave");
                configureSharedPersistenceAdapter(broker);
                // add transport as a service so that it is bound on start, after store started
                final TransportConnector tConnector = new TransportConnector();
                tConnector.setUri(new URI(brokerUrl));
                broker.addConnector(tConnector);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Aggregations

TransportConnector (org.apache.activemq.broker.TransportConnector)59 URI (java.net.URI)31 BrokerService (org.apache.activemq.broker.BrokerService)31 NetworkConnector (org.apache.activemq.network.NetworkConnector)10 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 DiscoveryNetworkConnector (org.apache.activemq.network.DiscoveryNetworkConnector)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)4 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)4 JMSException (javax.jms.JMSException)3 Session (javax.jms.Session)3 File (java.io.File)2 Principal (java.security.Principal)2 MessageProducer (javax.jms.MessageProducer)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)2 Connector (org.apache.activemq.broker.Connector)2 StubConnection (org.apache.activemq.broker.StubConnection)2