Search in sources :

Example 1 with ActiveMQTextMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.

the class GroupingTest method testGroupingRollbackOnClose.

@Test
public void testGroupingRollbackOnClose() throws Exception {
    ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
    fact.setConsumerWindowSize(1000);
    fact.setTransactionBatchSize(0);
    Connection connection = fact.createConnection();
    RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
    Connection connection2 = fact.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(queue);
    MessageConsumer consumer1 = session.createConsumer(queue);
    MessageConsumer consumer2 = session2.createConsumer(queue);
    connection.start();
    connection2.start();
    String jmsxgroupID = null;
    for (int j = 0; j < 100; j++) {
        TextMessage message = session.createTextMessage();
        message.setText("Message" + j);
        setProperty(message);
        producer.send(message);
        String prop = message.getStringProperty("JMSXGroupID");
        assertNotNull(prop);
        if (jmsxgroupID != null) {
            assertEquals(jmsxgroupID, prop);
        } else {
            jmsxgroupID = prop;
        }
    }
    session.commit();
    // consume 5 msgs from 1st first consumer
    for (int j = 0; j < 1; j++) {
        TextMessage tm = (TextMessage) consumer1.receive(10000);
        assertNotNull(tm);
        assertEquals("Message" + j, tm.getText());
        assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
    }
    Thread.sleep(2000);
    // session.rollback();
    // session.close();
    // consume all msgs from 2nd first consumer
    // ClientSession amqs = ((ActiveMQSession) session).getCoreSession();
    // ((DelegatingSession) amqs).getChannel().close();
    rc.fail(new ActiveMQNotConnectedException());
    for (int j = 0; j < 10; j++) {
        TextMessage tm = (TextMessage) consumer2.receive(10000);
        assertNotNull(tm);
        long text = ((ActiveMQTextMessage) tm).getCoreMessage().getMessageID();
        System.out.println(tm.getJMSMessageID() + " text = " + text);
        // assertEquals("Message" + j, text);
        assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
    }
    connection.close();
    connection2.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) MessageProducer(javax.jms.MessageProducer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with ActiveMQTextMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.

the class MessageHeaderTest method testCopyOnForeignTextMessage.

@Test
public void testCopyOnForeignTextMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    TextMessage foreignTextMessage = new SimpleJMSTextMessage();
    ActiveMQTextMessage copy = new ActiveMQTextMessage(foreignTextMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignTextMessage, copy);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) Test(org.junit.Test)

Example 3 with ActiveMQTextMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.

the class MessageConsumerRollbackTest method sendMessages.

/**
 * @param numberOfMessages
 * @param session
 * @throws Exception
 */
private void sendMessages(int numberOfMessages, ClientSession session) throws Exception {
    ClientProducer producer = session.createProducer(inQueue);
    for (int i = 0; i < numberOfMessages; i++) {
        ActiveMQTextMessage txt = new ActiveMQTextMessage(session);
        txt.setIntProperty("msg", i);
        txt.setText("Message Number (" + i + ")");
        txt.doBeforeSend();
        producer.send(txt.getCoreMessage());
    }
    session.commit();
}
Also used : ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage)

Example 4 with ActiveMQTextMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.

the class JournalPendingMessageTest method testQueueLargeMessageSize.

@Test
public void testQueueLargeMessageSize() throws Exception {
    ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
    acf.setMinLargeMessageSize(1000);
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String testText = StringUtils.repeat("t", 5000);
    ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
    session.createProducer(session.createQueue(defaultQueueName)).send(message);
    verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
    connection.close();
    this.killServer();
    this.restartServer();
    verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) Test(org.junit.Test)

Example 5 with ActiveMQTextMessage

use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.

the class JournalPendingMessageTest method testQueueLargeMessageSizeTX.

@Test
public void testQueueLargeMessageSizeTX() throws Exception {
    ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
    acf.setMinLargeMessageSize(1000);
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    String testText = StringUtils.repeat("t", 2000);
    MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName));
    ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
    for (int i = 0; i < 10; i++) {
        producer.send(message);
    }
    // not commited so should be 0
    verifyPendingStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);
    verifyPendingDurableStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);
    session.commit();
    verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);
    verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);
    connection.close();
    this.killServer();
    this.restartServer();
    verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
    verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) Test(org.junit.Test)

Aggregations

ActiveMQTextMessage (org.apache.activemq.artemis.jms.client.ActiveMQTextMessage)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 Test (org.junit.Test)6 TextMessage (javax.jms.TextMessage)4 EventMessage (eu.europa.ec.fisheries.uvms.activity.message.event.carrier.EventMessage)3 Connection (javax.jms.Connection)3 Session (javax.jms.Session)3 SneakyThrows (lombok.SneakyThrows)3 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)3 MessageProducer (javax.jms.MessageProducer)2 TopicSession (javax.jms.TopicSession)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ReceiveSalesReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.ReceiveSalesReportRequest)1 ActivityModuleMethod (eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod)1 GetFishingActivitiesForTripResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.GetFishingActivitiesForTripResponse)1 GetNonUniqueIdsRequest (eu.europa.ec.fisheries.uvms.activity.model.schemas.GetNonUniqueIdsRequest)1 GetNonUniqueIdsResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.GetNonUniqueIdsResponse)1 MessageConsumer (javax.jms.MessageConsumer)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1