Search in sources :

Example 16 with MessageId

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

the class MessageIdTest method createObject.

@Override
public Object createObject() throws Exception {
    MessageId info = new MessageId();
    populateObject(info);
    return info;
}
Also used : MessageId(org.apache.activemq.command.MessageId)

Example 17 with MessageId

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

the class MessageIdTest method createObject.

@Override
public Object createObject() throws Exception {
    MessageId info = new MessageId();
    populateObject(info);
    return info;
}
Also used : MessageId(org.apache.activemq.command.MessageId)

Example 18 with MessageId

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

the class FailoverTransportBrokerTest method createMessage.

protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
    message.setDestination(destination);
    message.setPersistent(false);
    try {
        message.setText("Test Message Payload.");
    } catch (MessageNotWriteableException e) {
    }
    return message;
}
Also used : MessageNotWriteableException(javax.jms.MessageNotWriteableException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Example 19 with MessageId

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

the class PriorityNetworkDispatchPolicyTest method init.

@Before
public void init() throws Exception {
    info.setDestination(ActiveMQDestination.createDestination("test", ActiveMQDestination.TOPIC_TYPE));
    info.setConsumerId(id);
    info.setNetworkSubscription(true);
    info.setNetworkConsumerPath(new ConsumerId[] { id });
    node.setMessageId(new MessageId("test:1:1:1:1"));
}
Also used : MessageId(org.apache.activemq.command.MessageId) Before(org.junit.Before)

Example 20 with MessageId

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

the class DurableSubscriptionOfflineTest method testNoDuplicateOnConcurrentSendTranCommitAndActivate.

@Test(timeout = 60 * 1000)
public void testNoDuplicateOnConcurrentSendTranCommitAndActivate() throws Exception {
    final int messageCount = 1000;
    Connection con = null;
    Session session = null;
    final int numConsumers = 10;
    for (int i = 0; i <= numConsumers; i++) {
        con = createConnection("cli" + i);
        session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
        session.createDurableSubscriber(topic, "SubsId", null, true);
        session.close();
        con.close();
    }
    class CheckForDupsClient implements Runnable {

        HashSet<Long> ids = new HashSet<>();

        final int id;

        public CheckForDupsClient(int id) {
            this.id = id;
        }

        @Override
        public void run() {
            try {
                Connection con = createConnection("cli" + id);
                Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
                for (int j = 0; j < 2; j++) {
                    MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
                    for (int i = 0; i < messageCount / 2; i++) {
                        Message message = consumer.receive(4000);
                        assertNotNull(message);
                        long producerSequenceId = new MessageId(message.getJMSMessageID()).getProducerSequenceId();
                        assertTrue("ID=" + id + " not a duplicate: " + producerSequenceId, ids.add(producerSequenceId));
                    }
                    consumer.close();
                }
                // verify no duplicates left
                MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
                Message message = consumer.receive(4000);
                if (message != null) {
                    long producerSequenceId = new MessageId(message.getJMSMessageID()).getProducerSequenceId();
                    assertTrue("ID=" + id + " not a duplicate: " + producerSequenceId, ids.add(producerSequenceId));
                }
                assertNull(message);
                session.close();
                con.close();
            } catch (Throwable e) {
                e.printStackTrace();
                exceptions.add(e);
            }
        }
    }
    final String payLoad = new String(new byte[1000]);
    con = createConnection();
    final Session sendSession = con.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = sendSession.createProducer(topic);
    for (int i = 0; i < messageCount; i++) {
        producer.send(sendSession.createTextMessage(payLoad));
    }
    ExecutorService executorService = Executors.newCachedThreadPool();
    // concurrent commit and activate
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                sendSession.commit();
            } catch (JMSException e) {
                e.printStackTrace();
                exceptions.add(e);
            }
        }
    });
    for (int i = 0; i < numConsumers; i++) {
        executorService.execute(new CheckForDupsClient(i));
    }
    executorService.shutdown();
    executorService.awaitTermination(5, TimeUnit.MINUTES);
    con.close();
    assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) ExecutorService(java.util.concurrent.ExecutorService) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) HashSet(java.util.HashSet) MessageId(org.apache.activemq.command.MessageId) Test(org.junit.Test)

Aggregations

MessageId (org.apache.activemq.command.MessageId)38 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)10 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)5 MessageNotWriteableException (javax.jms.MessageNotWriteableException)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ProducerId (org.apache.activemq.command.ProducerId)4 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3 Message (org.apache.activemq.command.Message)3 ProducerInfo (org.apache.activemq.command.ProducerInfo)3 Connection (javax.jms.Connection)2 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Session (javax.jms.Session)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 MessageReference (org.apache.activemq.broker.region.MessageReference)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2