Search in sources :

Example 31 with MessageId

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

the class QueueDuplicatesFromStoreTest method getMessage.

private Message getMessage(int i) throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setMessageId(new MessageId(mesageIdRoot + i));
    message.setDestination(destination);
    message.setPersistent(true);
    message.setResponseRequired(true);
    message.setText("Msg:" + i + " " + text);
    assertEquals(message.getMessageId().getProducerSequenceId(), i);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Example 32 with MessageId

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

the class QueueOptimizedDispatchExceptionTest method getMessage.

private Message getMessage(int i) throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setMessageId(new MessageId(mesageIdRoot + i));
    message.setDestination(destination);
    message.setPersistent(false);
    message.setResponseRequired(true);
    message.setText("Msg:" + i + " " + text);
    assertEquals(message.getMessageId().getProducerSequenceId(), i);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Example 33 with MessageId

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

the class SubscriptionAddRemoveQueueTest method testNoDispatchToRemovedConsumers.

public void testNoDispatchToRemovedConsumers() throws Exception {
    final AtomicInteger producerId = new AtomicInteger();
    Runnable sender = new Runnable() {

        @Override
        public void run() {
            AtomicInteger id = new AtomicInteger();
            int producerIdAndIncrement = producerId.getAndIncrement();
            while (working) {
                try {
                    Message msg = new ActiveMQMessage();
                    msg.setDestination(destination);
                    msg.setMessageId(new MessageId(producerIdAndIncrement + ":0:" + id.getAndIncrement()));
                    queue.send(producerBrokerExchange, msg);
                } catch (Exception e) {
                    e.printStackTrace();
                    fail("unexpected exception in sendMessage, ex:" + e);
                }
            }
        }
    };
    Runnable subRemover = new Runnable() {

        @Override
        public void run() {
            for (Subscription sub : subs) {
                try {
                    queue.removeSubscription(context, sub, 0);
                } catch (Exception e) {
                    e.printStackTrace();
                    fail("unexpected exception in removeSubscription, ex:" + e);
                }
            }
        }
    };
    for (int i = 0; i < numSubscriptions; i++) {
        SimpleImmediateDispatchSubscription sub = new SimpleImmediateDispatchSubscription();
        subs.add(sub);
        queue.addSubscription(context, sub);
    }
    assertEquals("there are X subscriptions", numSubscriptions, queue.getDestinationStatistics().getConsumers().getCount());
    ExecutorService executor = Executors.newCachedThreadPool();
    for (int i = 0; i < senders; i++) {
        executor.submit(sender);
    }
    Thread.sleep(1000);
    for (SimpleImmediateDispatchSubscription sub : subs) {
        assertTrue("There are some locked messages in the subscription", hasSomeLocks(sub.dispatched));
    }
    Future<?> result = executor.submit(subRemover);
    result.get();
    working = false;
    assertEquals("there are no subscriptions", 0, queue.getDestinationStatistics().getConsumers().getCount());
    for (SimpleImmediateDispatchSubscription sub : subs) {
        assertTrue("There are no locked messages in any removed subscriptions", !hasSomeLocks(sub.dispatched));
    }
}
Also used : ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) Message(org.apache.activemq.command.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) InvalidSelectorException(javax.jms.InvalidSelectorException) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) MessageId(org.apache.activemq.command.MessageId)

Example 34 with MessageId

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

the class StoreQueueCursorNoDuplicateTest method getMessage.

private ActiveMQTextMessage getMessage(int i) throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    MessageId id = new MessageId(mesageIdRoot + i);
    id.setBrokerSequenceId(i);
    id.setProducerSequenceId(i);
    message.setMessageId(id);
    message.setDestination(destination);
    message.setPersistent(true);
    message.setResponseRequired(true);
    message.setText("Msg:" + i + " " + text);
    assertEquals(message.getMessageId().getProducerSequenceId(), i);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

Example 35 with MessageId

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

the class StoreQueueCursorOrderTest method getMessage.

private ActiveMQTextMessage getMessage(int i) throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    MessageId id = new MessageId(mesageIdRoot + i);
    id.setBrokerSequenceId(i);
    id.setProducerSequenceId(i);
    message.setMessageId(id);
    message.setDestination(destination);
    message.setPersistent(true);
    message.setResponseRequired(true);
    message.setText("Msg:" + i + " " + text);
    assertEquals(message.getMessageId().getProducerSequenceId(), i);
    return message;
}
Also used : ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) MessageId(org.apache.activemq.command.MessageId)

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