Search in sources :

Example 11 with CoreMessage

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

the class OpenWireMessageConverter method inbound.

public static org.apache.activemq.artemis.api.core.Message inbound(final Message messageSend, final WireFormat marshaller, final CoreMessageObjectPools coreMessageObjectPools) throws Exception {
    final CoreMessage coreMessage = new CoreMessage(-1, messageSend.getSize(), coreMessageObjectPools);
    final String type = messageSend.getType();
    if (type != null) {
        coreMessage.putStringProperty(JMS_TYPE_PROPERTY, new SimpleString(type));
    }
    coreMessage.setDurable(messageSend.isPersistent());
    coreMessage.setExpiration(messageSend.getExpiration());
    coreMessage.setPriority(messageSend.getPriority());
    coreMessage.setTimestamp(messageSend.getTimestamp());
    final byte coreType = toCoreType(messageSend.getDataStructureType());
    coreMessage.setType(coreType);
    final ActiveMQBuffer body = coreMessage.getBodyBuffer();
    final ByteSequence contents = messageSend.getContent();
    if (contents == null && coreType == org.apache.activemq.artemis.api.core.Message.TEXT_TYPE) {
        body.writeNullableString(null);
    } else if (contents != null) {
        final boolean messageCompressed = messageSend.isCompressed();
        if (messageCompressed) {
            coreMessage.putBooleanProperty(AMQ_MSG_COMPRESSED, messageCompressed);
        }
        switch(coreType) {
            case org.apache.activemq.artemis.api.core.Message.TEXT_TYPE:
                writeTextType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.MAP_TYPE:
                writeMapType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE:
                writeObjectType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.STREAM_TYPE:
                writeStreamType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
                writeBytesType(contents, messageCompressed, body);
                break;
            default:
                writeDefaultType(contents, messageCompressed, body);
                break;
        }
    }
    // amq specific
    coreMessage.putLongProperty(AMQ_MSG_ARRIVAL, messageSend.getArrival());
    coreMessage.putLongProperty(AMQ_MSG_BROKER_IN_TIME, messageSend.getBrokerInTime());
    final BrokerId[] brokers = messageSend.getBrokerPath();
    if (brokers != null) {
        putMsgBrokerPath(brokers, coreMessage);
    }
    final BrokerId[] cluster = messageSend.getCluster();
    if (cluster != null) {
        putMsgCluster(cluster, coreMessage);
    }
    coreMessage.putIntProperty(AMQ_MSG_COMMAND_ID, messageSend.getCommandId());
    final String corrId = messageSend.getCorrelationId();
    if (corrId != null) {
        coreMessage.putStringProperty(JMS_CORRELATION_ID_PROPERTY, new SimpleString(corrId));
    }
    final DataStructure ds = messageSend.getDataStructure();
    if (ds != null) {
        putMsgDataStructure(ds, marshaller, coreMessage);
    }
    final String groupId = messageSend.getGroupID();
    if (groupId != null) {
        coreMessage.putStringProperty(AMQ_MSG_GROUP_ID, coreMessageObjectPools.getGroupIdStringSimpleStringPool().getOrCreate(groupId));
    }
    coreMessage.putIntProperty(AMQ_MSG_GROUP_SEQUENCE, messageSend.getGroupSequence());
    final MessageId messageId = messageSend.getMessageId();
    final ByteSequence midBytes = marshaller.marshal(messageId);
    midBytes.compact();
    coreMessage.putBytesProperty(AMQ_MSG_MESSAGE_ID, midBytes.data);
    final ProducerId producerId = messageSend.getProducerId();
    if (producerId != null) {
        final ByteSequence producerIdBytes = marshaller.marshal(producerId);
        producerIdBytes.compact();
        coreMessage.putBytesProperty(AMQ_MSG_PRODUCER_ID, producerIdBytes.data);
    }
    final ByteSequence propBytes = messageSend.getMarshalledProperties();
    if (propBytes != null) {
        putMsgMarshalledProperties(propBytes, messageSend, coreMessage);
    }
    final ActiveMQDestination replyTo = messageSend.getReplyTo();
    if (replyTo != null) {
        putMsgReplyTo(replyTo, marshaller, coreMessage);
    }
    final String userId = messageSend.getUserID();
    if (userId != null) {
        coreMessage.putStringProperty(AMQ_MSG_USER_ID, new SimpleString(userId));
    }
    coreMessage.putBooleanProperty(AMQ_MSG_DROPPABLE, messageSend.isDroppable());
    final ActiveMQDestination origDest = messageSend.getOriginalDestination();
    if (origDest != null) {
        putMsgOriginalDestination(origDest, marshaller, coreMessage);
    }
    return coreMessage;
}
Also used : BrokerId(org.apache.activemq.command.BrokerId) ProducerId(org.apache.activemq.command.ProducerId) DataStructure(org.apache.activemq.command.DataStructure) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ByteSequence(org.apache.activemq.util.ByteSequence) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) MessageId(org.apache.activemq.command.MessageId) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 12 with CoreMessage

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

the class JMSMappingOutboundTransformerTest method newMessage.

private CoreMessage newMessage(byte messageType) {
    CoreMessage message = new CoreMessage(0, 512);
    message.setType(messageType);
    ((ResetLimitWrappedActiveMQBuffer) message.getBodyBuffer()).setMessage(null);
    return message;
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ResetLimitWrappedActiveMQBuffer(org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer)

Example 13 with CoreMessage

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

the class ServerConsumerImpl method forceDelivery.

/**
 * Prompt delivery and send a "forced delivery" message to the consumer.
 * <p>
 * When the consumer receives such a "forced delivery" message, it discards it and knows that
 * there are no other messages to be delivered.
 */
@Override
public void forceDelivery(final long sequence) {
    forceDelivery(sequence, () -> {
        Message forcedDeliveryMessage = new CoreMessage(storageManager.generateID(), 50);
        forcedDeliveryMessage.putLongProperty(ClientConsumerImpl.FORCED_DELIVERY_MESSAGE, sequence);
        forcedDeliveryMessage.setAddress(messageQueue.getName());
        applyPrefixForLegacyConsumer(forcedDeliveryMessage);
        callback.sendMessage(null, forcedDeliveryMessage, ServerConsumerImpl.this, 0);
    });
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 14 with CoreMessage

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

the class PagingStoreImplTest method createMessage.

private CoreMessage createMessage(final long id, final PagingStore store, final SimpleString destination, final ActiveMQBuffer buffer) {
    CoreMessage msg = new CoreMessage(id, 50 + buffer.capacity());
    msg.setAddress(destination);
    msg.setContext(store);
    msg.getBodyBuffer().resetReaderIndex();
    msg.getBodyBuffer().resetWriterIndex();
    msg.getBodyBuffer().writeBytes(buffer, buffer.capacity());
    return msg;
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 15 with CoreMessage

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

the class BindingsImplTest method internalTest.

private void internalTest(final boolean route) throws Exception {
    final FakeBinding fake = new FakeBinding(new SimpleString("a"));
    final Bindings bind = new BindingsImpl(null, null, null);
    bind.addBinding(fake);
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                bind.removeBinding(fake);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    Queue queue = new FakeQueue(new SimpleString("a"));
    t.start();
    for (int i = 0; i < 100; i++) {
        if (route) {
            bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
        } else {
            bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
        }
    }
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

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