Search in sources :

Example 56 with ConnectionInfo

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

the class AdvisoryBrokerTest method testProducerAdvisories.

public void testProducerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // We should get an advisory of the new producer.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 57 with ConnectionInfo

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

the class RecoverExpiredMessagesTest method consumeExpected.

private void consumeExpected() throws Exception {
    // Setup the consumer and receive the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull("Should have received message " + expected.get(0) + " by now!", m);
    assertEquals(expected.get(0), m.getMessageId().toString());
    MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
    connection.send(ack);
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 58 with ConnectionInfo

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

the class BrokerQueueNetworkWithDisconnectTest method testNoStuckConnectionsWithTransportDisconnect.

public void testNoStuckConnectionsWithTransportDisconnect() throws Exception {
    inactiveDuration = 60000L;
    useDuplexNetworkBridge = true;
    bridgeBrokers(SPOKE, HUB);
    final BrokerItem hub = brokers.get(HUB);
    hub.broker.setPlugins(new BrokerPlugin[] { new BrokerPluginSupport() {

        int sleepCount = 2;

        @Override
        public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
            try {
                while (--sleepCount >= 0) {
                    LOG.info("sleeping for a bit in close impl to simulate load where reconnect fails due to a pending close");
                    TimeUnit.SECONDS.sleep(2);
                }
            } catch (Exception ignored) {
            }
            super.removeConnection(context, info, error);
        }
    } });
    startAllBrokers();
    waitForBridgeFormation();
    // remote side will need to spot duplicate network and stop/kill the original
    for (int i = 0; i < 3; i++) {
        socketProxy.halfClose();
        sleep(10000);
    }
    // wait for full reformation of bridge
    // verify no extra connections
    boolean allGood = Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            long numConnections = hub.broker.getTransportConnectors().get(0).getConnections().size();
            LOG.info("Num connetions:" + numConnections);
            return numConnections == 1;
        }
    });
    if (!allGood) {
        dumpAllThreads("ExtraHubConnection");
    }
    assertTrue("should be only one transport connection for the single duplex network connector", allGood);
    allGood = Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            long numVmConnections = VMTransportFactory.SERVERS.get(HUB).getConnectionCount();
            LOG.info("Num VM connetions:" + numVmConnections);
            return numVmConnections == 2;
        }
    });
    if (!allGood) {
        dumpAllThreads("ExtraHubVMConnection");
    }
    assertTrue("should be only 2 vm connections for the single network duplex network connector", allGood);
}
Also used : BrokerPluginSupport(org.apache.activemq.broker.BrokerPluginSupport) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Wait(org.apache.activemq.util.Wait)

Example 59 with ConnectionInfo

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

the class ClientTestSupport method createConnectionInfo.

// Helper Classes
protected ConnectionInfo createConnectionInfo() throws Exception {
    ConnectionInfo info = new ConnectionInfo();
    info.setConnectionId(new ConnectionId("connection:" + (++idGenerator)));
    info.setClientId(info.getConnectionId().getValue());
    return info;
}
Also used : ConnectionId(org.apache.activemq.command.ConnectionId) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 60 with ConnectionInfo

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

the class BrokerNetworkWithStuckMessagesTest method createConnectionInfo.

protected ConnectionInfo createConnectionInfo() throws Exception {
    ConnectionInfo info = new ConnectionInfo();
    info.setConnectionId(new ConnectionId("connection:" + (++idGenerator)));
    info.setClientId(info.getConnectionId().getValue());
    return info;
}
Also used : ConnectionId(org.apache.activemq.command.ConnectionId) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Aggregations

ConnectionInfo (org.apache.activemq.command.ConnectionInfo)110 SessionInfo (org.apache.activemq.command.SessionInfo)77 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 Message (org.apache.activemq.command.Message)71 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 StubConnection (org.apache.activemq.broker.StubConnection)18 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)10 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 ConnectionId (org.apache.activemq.command.ConnectionId)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)6 IOException (java.io.IOException)5 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4