Search in sources :

Example 11 with BrokerInfo

use of org.apache.activemq.command.BrokerInfo in project activemq-artemis by apache.

the class FailoverTransportBrokerTest method testNoBrokersInBrokerInfo.

public void testNoBrokersInBrokerInfo() throws Exception {
    final BrokerInfo[] info = new BrokerInfo[1];
    TransportListener listener = new TransportListener() {

        @Override
        public void onCommand(Object command) {
            LOG.info("Got command: " + command);
            if (command instanceof BrokerInfo) {
                info[0] = (BrokerInfo) command;
            }
        }

        @Override
        public void onException(IOException error) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void transportInterupted() {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void transportResumed() {
        // To change body of implemented methods use File | Settings | File Templates.
        }
    };
    @SuppressWarnings("unused") StubConnection c = createFailoverConnection(listener);
    int count = 0;
    while (count++ < 20 && info[0] == null) {
        TimeUnit.SECONDS.sleep(1);
    }
    Assert.assertNotNull("got a valid brokerInfo after 20 secs", info[0]);
    Assert.assertNull("no peer brokers present", info[0].getPeerBrokerInfos());
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) StubConnection(org.apache.activemq.broker.StubConnection) IOException(java.io.IOException) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Example 12 with BrokerInfo

use of org.apache.activemq.command.BrokerInfo in project activemq-artemis by apache.

the class AdvisoryNetworkBridgeTest method testAddConsumerLater.

public void testAddConsumerLater() throws Exception {
    createBroker1();
    createBroker2();
    Thread.sleep(1000);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://broker1");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    MessageConsumer consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    ActiveMQMessage advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertTrue(advisory.getBooleanProperty("started"));
    assertCreatedByDuplex(advisory.getBooleanProperty("createdByDuplex"));
    broker2.stop();
    broker2.waitUntilStopped();
    advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertFalse(advisory.getBooleanProperty("started"));
    consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    advisory = (ActiveMQMessage) consumer.receive(1000);
    assertNull(advisory);
    conn.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) Session(javax.jms.Session) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Example 13 with BrokerInfo

use of org.apache.activemq.command.BrokerInfo in project activemq-artemis by apache.

the class AdvisoryNetworkBridgeTest method testAdvisory.

public void testAdvisory() throws Exception {
    createBroker1();
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://broker1");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    conn.start();
    MessageConsumer consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
    Thread.sleep(1000);
    createBroker2();
    ActiveMQMessage advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertTrue(advisory.getBooleanProperty("started"));
    assertCreatedByDuplex(advisory.getBooleanProperty("createdByDuplex"));
    broker2.stop();
    broker2.waitUntilStopped();
    advisory = (ActiveMQMessage) consumer.receive(2000);
    assertNotNull(advisory);
    assertTrue(advisory.getDataStructure() instanceof BrokerInfo);
    assertFalse(advisory.getBooleanProperty("started"));
    conn.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) Session(javax.jms.Session) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Example 14 with BrokerInfo

use of org.apache.activemq.command.BrokerInfo in project activemq-artemis by apache.

the class NetworkRouteTest method before.

@Before
public void before() throws Exception {
    control = EasyMock.createControl();
    localBroker = control.createMock(Transport.class);
    remoteBroker = control.createMock(Transport.class);
    NetworkBridgeConfiguration configuration = new NetworkBridgeConfiguration();
    brokerService = new BrokerService();
    BrokerInfo remoteBrokerInfo = new BrokerInfo();
    configuration.setDuplex(true);
    configuration.setNetworkTTL(5);
    brokerService.setBrokerId("broker-1");
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.start();
    brokerService.waitUntilStarted();
    remoteBrokerInfo.setBrokerId(new BrokerId("remote-broker-id"));
    remoteBrokerInfo.setBrokerName("remote-broker-name");
    localBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder localListenerRef = ArgHolder.holdArgsForLastVoidCall();
    remoteBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder remoteListenerRef = ArgHolder.holdArgsForLastVoidCall();
    localBroker.start();
    remoteBroker.start();
    remoteBroker.oneway(EasyMock.isA(Object.class));
    EasyMock.expectLastCall().times(4);
    remoteBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter remoteInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    localBroker.oneway(remoteBrokerInfo);
    EasyMock.expect(localBroker.request(EasyMock.isA(Object.class))).andReturn(null);
    localBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter localInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    control.replay();
    DurableConduitBridge bridge = new DurableConduitBridge(configuration, localBroker, remoteBroker);
    bridge.setBrokerService(brokerService);
    bridge.start();
    localListener = (TransportListener) localListenerRef.getArguments()[0];
    Assert.assertNotNull(localListener);
    remoteListener = (TransportListener) remoteListenerRef.getArguments()[0];
    Assert.assertNotNull(remoteListener);
    remoteListener.onCommand(remoteBrokerInfo);
    remoteInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    localInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    control.verify();
    control.reset();
    ActiveMQMessage msg = new ActiveMQMessage();
    msg.setDestination(new ActiveMQTopic("test"));
    msgDispatch = new MessageDispatch();
    msgDispatch.setMessage(msg);
    ConsumerInfo path1 = new ConsumerInfo();
    path1.setDestination(msg.getDestination());
    path1.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-1"), 1), 3));
    path1.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(1)-broker-id") });
    path1Msg = new ActiveMQMessage();
    path1Msg.setDestination(AdvisorySupport.getConsumerAdvisoryTopic(path1.getDestination()));
    path1Msg.setDataStructure(path1);
    ConsumerInfo path2 = new ConsumerInfo();
    path2.setDestination(path1.getDestination());
    path2.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-2"), 2), 4));
    path2.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(2)-broker-id"), new BrokerId("server(1)-broker-id") });
    path2Msg = new ActiveMQMessage();
    path2Msg.setDestination(path1Msg.getDestination());
    path2Msg.setDataStructure(path2);
    RemoveInfo removePath1 = new RemoveInfo(path1.getConsumerId());
    RemoveInfo removePath2 = new RemoveInfo(path2.getConsumerId());
    removePath1Msg = new ActiveMQMessage();
    removePath1Msg.setDestination(path1Msg.getDestination());
    removePath1Msg.setDataStructure(removePath1);
    removePath2Msg = new ActiveMQMessage();
    removePath2Msg.setDestination(path1Msg.getDestination());
    removePath2Msg.setDataStructure(removePath2);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) BrokerId(org.apache.activemq.command.BrokerId) BrokerInfo(org.apache.activemq.command.BrokerInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) TransportListener(org.apache.activemq.transport.TransportListener) MessageDispatch(org.apache.activemq.command.MessageDispatch) ConnectionId(org.apache.activemq.command.ConnectionId) RemoveInfo(org.apache.activemq.command.RemoveInfo) ConsumerId(org.apache.activemq.command.ConsumerId) Transport(org.apache.activemq.transport.Transport) BrokerService(org.apache.activemq.broker.BrokerService) SessionId(org.apache.activemq.command.SessionId) Before(org.junit.Before)

Example 15 with BrokerInfo

use of org.apache.activemq.command.BrokerInfo in project activemq-artemis by apache.

the class OpenWireProtocolManager method sendBrokerInfo.

public void sendBrokerInfo(OpenWireConnection connection) throws Exception {
    BrokerInfo brokerInfo = new BrokerInfo();
    brokerInfo.setBrokerName(getBrokerName());
    brokerInfo.setBrokerId(new BrokerId("" + server.getNodeID()));
    brokerInfo.setPeerBrokerInfos(null);
    brokerInfo.setFaultTolerantConfiguration(false);
    brokerInfo.setBrokerURL(connection.getLocalAddress());
    // cluster support yet to support
    brokerInfo.setPeerBrokerInfos(null);
    connection.dispatch(brokerInfo);
}
Also used : BrokerId(org.apache.activemq.command.BrokerId) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Aggregations

BrokerInfo (org.apache.activemq.command.BrokerInfo)27 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)3 BrokerId (org.apache.activemq.command.BrokerId)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Connection (javax.jms.Connection)2 MessageConsumer (javax.jms.MessageConsumer)2 Session (javax.jms.Session)2 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)2 BrokerService (org.apache.activemq.broker.BrokerService)2 TransportListener (org.apache.activemq.transport.TransportListener)2 IOException (java.io.IOException)1 StubConnection (org.apache.activemq.broker.StubConnection)1 RegionBroker (org.apache.activemq.broker.region.RegionBroker)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1 ConnectionId (org.apache.activemq.command.ConnectionId)1 ConsumerId (org.apache.activemq.command.ConsumerId)1 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)1 MessageDispatch (org.apache.activemq.command.MessageDispatch)1 RemoveInfo (org.apache.activemq.command.RemoveInfo)1 SessionId (org.apache.activemq.command.SessionId)1