Search in sources :

Example 36 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class ManagementServiceImpl method sendNotification.

@Override
public void sendNotification(final Notification notification) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Sending Notification = " + notification + ", notificationEnabled=" + notificationsEnabled + " messagingServerControl=" + messagingServerControl);
    }
    // This needs to be synchronized since we need to ensure notifications are processed in strict sequence
    synchronized (this) {
        if (messagingServerControl != null && notificationsEnabled) {
            // if a notification occurs at same time as sendQueueInfoToQueue is processed
            synchronized (postOffice.getNotificationLock()) {
                // First send to any local listeners
                for (NotificationListener listener : listeners) {
                    try {
                        listener.onNotification(notification);
                    } catch (Exception e) {
                        // Exception thrown from one listener should not stop execution of others
                        ActiveMQServerLogger.LOGGER.errorCallingNotifListener(e);
                    }
                }
                // https://jira.jboss.org/jira/browse/HORNETQ-317
                if (messagingServer == null || !messagingServer.isActive()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("ignoring message " + notification + " as the server is not initialized");
                    }
                    return;
                }
                long messageID = storageManager.generateID();
                Message notificationMessage = new CoreMessage(messageID, 512);
                // Notification messages are always durable so the user can choose whether to add a durable queue to
                // consume them in
                notificationMessage.setDurable(true);
                notificationMessage.setAddress(managementNotificationAddress);
                if (notification.getProperties() != null) {
                    TypedProperties props = notification.getProperties();
                    for (SimpleString name : notification.getProperties().getPropertyNames()) {
                        notificationMessage.putObjectProperty(name, props.getProperty(name));
                    }
                }
                notificationMessage.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(notification.getType().toString()));
                notificationMessage.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
                if (notification.getUID() != null) {
                    notificationMessage.putStringProperty(new SimpleString("foobar"), new SimpleString(notification.getUID()));
                }
                postOffice.route(notificationMessage, false);
            }
        }
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener)

Example 37 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class FilterTest method testAMQDurable.

@Test
public void testAMQDurable() throws Exception {
    filter = FilterImpl.createFilter(new SimpleString("AMQDurable='DURABLE'"));
    message.setDurable(true);
    Assert.assertTrue(filter.match(message));
    message.setDurable(false);
    Assert.assertFalse(filter.match(message));
    filter = FilterImpl.createFilter(new SimpleString("AMQDurable='NON_DURABLE'"));
    message = new CoreMessage();
    message.setDurable(true);
    Assert.assertFalse(filter.match(message));
    message.setDurable(false);
    Assert.assertTrue(filter.match(message));
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Example 38 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class FilterTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    message = new CoreMessage().initBuffer(1024).setMessageID(1);
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Before(org.junit.Before)

Example 39 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class EmbedMessageUtil method embedAsCoreMessage.

public static ICoreMessage embedAsCoreMessage(Message source) {
    if (source instanceof ICoreMessage) {
        return (ICoreMessage) source;
    } else {
        Persister persister = source.getPersister();
        CoreMessage message = new CoreMessage(source.getMessageID(), persister.getEncodeSize(source) + signature.length + CoreMessage.BODY_OFFSET).setType(Message.EMBEDDED_TYPE);
        ActiveMQBuffer buffer = message.getBodyBuffer();
        buffer.writeBytes(signature);
        persister.encode(buffer, source);
        return message;
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Persister(org.apache.activemq.artemis.core.persistence.Persister) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 40 with CoreMessage

use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.

the class PageCursorStressTest method pgMessages.

/**
 * @param storage
 * @param pageStore
 * @param pgParameter
 * @param start
 * @param NUM_MESSAGES
 * @param messageSize
 * @throws Exception
 */
private Transaction pgMessages(StorageManager storage, PagingStoreImpl pageStore, long pgParameter, int start, final int NUM_MESSAGES, final int messageSize) throws Exception {
    TransactionImpl txImpl = new TransactionImpl(pgParameter, null, storage);
    RoutingContext ctx = generateCTX(txImpl);
    for (int i = start; i < start + NUM_MESSAGES; i++) {
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        Message msg = new CoreMessage(storage.generateID(), buffer.writerIndex());
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        msg.putIntProperty("key", i);
        pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock);
    }
    return txImpl;
}
Also used : RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)48 Test (org.junit.Test)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)16 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 Message (org.apache.activemq.artemis.api.core.Message)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ByteBuf (io.netty.buffer.ByteBuf)5 LinkedList (java.util.LinkedList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2