Search in sources :

Example 1 with SessionReceiveContinuationMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage in project activemq-artemis by apache.

the class CoreSessionCallback method sendLargeMessageContinuation.

@Override
public int sendLargeMessageContinuation(ServerConsumer consumer, byte[] body, boolean continues, boolean requiresResponse) {
    Packet packet = new SessionReceiveContinuationMessage(consumer.getID(), body, continues, requiresResponse);
    channel.send(packet);
    return packet.getPacketSize();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionReceiveContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage)

Example 2 with SessionReceiveContinuationMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage in project activemq-artemis by apache.

the class JMSFailoverTest method testSendReceiveLargeMessages.

@Test
public void testSendReceiveLargeMessages() throws Exception {
    SimpleString QUEUE = new SimpleString("somequeue");
    ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc, backuptc);
    jbcf.setReconnectAttempts(-1);
    jbcf.setBlockOnDurableSend(true);
    jbcf.setBlockOnNonDurableSend(true);
    jbcf.setMinLargeMessageSize(1024);
    // jbcf.setConsumerWindowSize(0);
    // jbcf.setMinLargeMessageSize(1024);
    final CountDownLatch flagAlign = new CountDownLatch(1);
    final CountDownLatch waitToKill = new CountDownLatch(1);
    final AtomicBoolean killed = new AtomicBoolean(false);
    jbcf.getServerLocator().addIncomingInterceptor(new Interceptor() {

        int count = 0;

        @Override
        public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
            if (packet instanceof SessionReceiveContinuationMessage) {
                if (count++ == 300 && !killed.get()) {
                    System.out.println("sending countDown on latch waitToKill");
                    killed.set(true);
                    waitToKill.countDown();
                }
            }
            return true;
        }
    });
    Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    final ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
    // The thread that will fail the server
    Thread spoilerThread = new Thread() {

        @Override
        public void run() {
            flagAlign.countDown();
            // a large timeout just to help in case of debugging
            try {
                waitToKill.await(120, TimeUnit.SECONDS);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                System.out.println("Killing server...");
                JMSUtil.crash(liveServer, coreSession);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    coreSession.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, true);
    Queue queue = sess.createQueue("somequeue");
    MessageProducer producer = sess.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    for (int i = 0; i < 100; i++) {
        TextMessage message = sess.createTextMessage(new String(new byte[10 * 1024]));
        producer.send(message);
        if (i % 10 == 0) {
            sess.commit();
        }
    }
    sess.commit();
    conn.start();
    spoilerThread.start();
    assertTrue(flagAlign.await(10, TimeUnit.SECONDS));
    MessageConsumer consumer = sess.createConsumer(queue);
    // this test is not meant to validate transactionality during Failover as that would require XA and recovery
    for (int i = 0; i < 90; i++) {
        TextMessage message = null;
        int retryNrs = 0;
        do {
            retryNrs++;
            try {
                message = (TextMessage) consumer.receive(5000);
                assertNotNull(message);
                break;
            } catch (JMSException e) {
                new Exception("Exception on receive message", e).printStackTrace();
            }
        } while (retryNrs < 10);
        assertNotNull(message);
        try {
            sess.commit();
        } catch (Exception e) {
            new Exception("Exception during commit", e);
            sess.rollback();
        }
    }
    conn.close();
    spoilerThread.join();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionReceiveContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage) MessageConsumer(javax.jms.MessageConsumer) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JMSException(javax.jms.JMSException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MessageProducer(javax.jms.MessageProducer) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

Packet (org.apache.activemq.artemis.core.protocol.core.Packet)2 SessionReceiveContinuationMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Connection (javax.jms.Connection)1 JMSException (javax.jms.JMSException)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 Queue (javax.jms.Queue)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)1 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)1 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)1 Test (org.junit.Test)1